Mercurial > hg > RemoteViewer
changeset 3:77fa82dcc956
add a settings object that is read when the main window is opened and persisted when the
main window closes
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 20 Sep 2014 03:12:26 +0200 |
parents | 71c9c315cfad |
children | 8905b45cf9fb |
files | RemoteViewer/RemoteViewer.py RemoteViewer/Settings.py |
diffstat | 2 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/RemoteViewer/RemoteViewer.py Sat Sep 20 02:50:37 2014 +0200 +++ b/RemoteViewer/RemoteViewer.py Sat Sep 20 03:12:26 2014 +0200 @@ -2,11 +2,13 @@ from PyQtLib.ExceptionSafeSlot import ExceptionSafeSlot from .ConnectionDialog import ConnectionDialog +from .Settings import Settings from .Ui_RemoteViewer import Ui_RemoteViewer class RemoteViewer(QMainWindow): def __init__(self): super(RemoteViewer, self).__init__() + self.settings = Settings() self.ui = Ui_RemoteViewer() self.ui.setupUi(self) @@ -15,3 +17,7 @@ dialog = ConnectionDialog() dialog.setWindowTitle('New Connection') dialog.exec_() + + def close(self): + self.settings.persist() + super(RemoteViewer, self).close()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RemoteViewer/Settings.py Sat Sep 20 03:12:26 2014 +0200 @@ -0,0 +1,15 @@ + +from os.path import expanduser +from configparser import ConfigParser + +class Settings(object): + def __init__(self): + self.parser = ConfigParser() + self.parser.read(self.__filename()) + + def __filename(self): + return expanduser('~/.remoteviewer') + + def persist(self): + with open(self.__filename(), 'w') as rcfile: + self.parser.write(rcfile)