diff options
author | mkaay <mkaay@mkaay.de> | 2009-12-21 17:57:17 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2009-12-21 17:57:17 +0100 |
commit | 59eaacc4228707f715be147350adb0a670de6985 (patch) | |
tree | d9048d89724c123ad7500dc51e91c5673582b20a | |
parent | package creation works (diff) | |
download | pyload-59eaacc4228707f715be147350adb0a670de6985.tar.xz |
save window state
-rw-r--r-- | module/config/gui_default.xml | 4 | ||||
-rw-r--r-- | module/gui/LinkDock.py | 1 | ||||
-rw-r--r-- | module/gui/MainWindow.py | 27 | ||||
-rw-r--r-- | module/gui/PackageDock.py | 1 | ||||
-rwxr-xr-x | pyLoadGui.py | 29 |
5 files changed, 61 insertions, 1 deletions
diff --git a/module/config/gui_default.xml b/module/config/gui_default.xml index af38eda4c..9b6d75936 100644 --- a/module/config/gui_default.xml +++ b/module/config/gui_default.xml @@ -4,4 +4,8 @@ <name>Local</name> </connection> </connections> + <mainWindow> + <state></state> + <geometry></geometry> + </mainWindow> </root> diff --git a/module/gui/LinkDock.py b/module/gui/LinkDock.py index 01a0cc193..99429d04b 100644 --- a/module/gui/LinkDock.py +++ b/module/gui/LinkDock.py @@ -22,6 +22,7 @@ from PyQt4.QtGui import * class NewLinkDock(QDockWidget): def __init__(self): QDockWidget.__init__(self, "New Links") + self.setObjectName("New Links Dock") self.widget = NewLinkWindow(self) self.setWidget(self.widget) self.setAllowedAreas(Qt.RightDockWidgetArea|Qt.LeftDockWidgetArea) diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index 63ffb86a0..4f92f68a9 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -33,6 +33,9 @@ class MainWindow(QMainWindow): self.setWindowIcon(QIcon("icons/logo.png")) self.resize(750,500) + #layout version + self.version = 1 + #init docks self.newPackDock = NewPackageDock() self.addDockWidget(Qt.RightDockWidgetArea, self.newPackDock) @@ -89,7 +92,8 @@ class MainWindow(QMainWindow): self.connect(self.mactions["exit"], SIGNAL("triggered()"), self.close) def init_toolbar(self): - self.toolbar = self.addToolBar("main") + self.toolbar = self.addToolBar("Main Toolbar") + self.toolbar.setObjectName("Main Toolbar") self.toolbar.setIconSize(QSize(40,40)) self.actions["toggle_status"] = self.toolbar.addAction("Toggle Pause/Resume") pricon = QIcon() @@ -160,3 +164,24 @@ class MainWindow(QMainWindow): def slotAddPackage(self, name, ids): self.emit(SIGNAL("addPackage"), name, ids) + + def closeEvent(self, event): + state_raw = self.saveState(self.version) + geo_raw = self.saveGeometry() + + state = str(state_raw.toBase64()) + geo = str(geo_raw.toBase64()) + + self.emit(SIGNAL("saveMainWindow"), state, geo) + event.accept() + + def restoreWindow(self, state, geo): + state = QByteArray(state) + geo = QByteArray(geo) + + state_raw = QByteArray.fromBase64(state) + geo_raw = QByteArray.fromBase64(geo) + + self.restoreState(state_raw, self.version) + self.restoreGeometry(geo_raw) + diff --git a/module/gui/PackageDock.py b/module/gui/PackageDock.py index 7367efda4..b90e3533d 100644 --- a/module/gui/PackageDock.py +++ b/module/gui/PackageDock.py @@ -22,6 +22,7 @@ from PyQt4.QtGui import * class NewPackageDock(QDockWidget): def __init__(self): QDockWidget.__init__(self, "New Package") + self.setObjectName("New Package Dock") self.widget = NewPackageWindow(self) self.setWidget(self.widget) self.setAllowedAreas(Qt.RightDockWidgetArea|Qt.LeftDockWidgetArea) diff --git a/pyLoadGui.py b/pyLoadGui.py index ccab8ba64..a21c27cb9 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -61,6 +61,7 @@ class main(QObject): def startMain(self): self.connector.start() sleep(1) + self.restoreMainWindow() self.mainWindow.show() self.initQueue() self.initPackageCollector() @@ -90,6 +91,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("addLinks"), self.slotAddLinks) self.connect(self.mainWindow, SIGNAL("addPackage"), self.slotAddPackage) self.connect(self.mainWindow, SIGNAL("setDownloadStatus"), self.slotSetDownloadStatus) + self.connect(self.mainWindow, SIGNAL("saveMainWindow"), self.slotSaveMainWindow) def slotShowConnector(self): self.stopMain() @@ -293,6 +295,33 @@ class main(QObject): for fileid in ids: self.connector.addFileToPackage(fileid, packid) + def slotSaveMainWindow(self, state, geo): + mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) + if mainWindowNode.isNull(): + raise Exception("null") + stateNode = mainWindowNode.toElement().elementsByTagName("state").item(0) + geoNode = mainWindowNode.toElement().elementsByTagName("geometry").item(0) + newStateNode = self.parser.xml.createTextNode(state) + newGeoNode = self.parser.xml.createTextNode(geo) + + stateNode.removeChild(stateNode.firstChild()) + geoNode.removeChild(geoNode.firstChild()) + stateNode.appendChild(newStateNode) + geoNode.appendChild(newGeoNode) + + self.parser.saveData() + + def restoreMainWindow(self): + mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) + if mainWindowNode.isNull(): + raise Exception("null") + nodes = self.parser.parseNode(mainWindowNode, "dict") + + state = str(nodes["state"].text()) + geo = str(nodes["geometry"].text()) + + self.mainWindow.restoreWindow(state, geo) + class Loop(QThread): def __init__(self, parent): QThread.__init__(self) |