Persist main window geometry

Added support for saving and restoring main window geometry.

Saving is done in a somewhat contrieved manner. In order to avoid
exposing App.defaults (or App) to the UI class, a geomUpdate
signal was added to to the FlatCAMGUI class. The signal is emitted
whenever FlatCAMGUI thinks its geometry should be saved (which, so
far, seems to be only in closeEvent()). FlatCAMApp has a slot for
this signal, which updates the defaults dictionary.

Restoring is done by explicitly applying the loaded geometry to
the UI. The UI is initialized (i.e. FlatCAMGUI's __init__ is
called) very early in the initialization sequence, before the
defaults are loaded, so at that time the persisted geometry is
not known to the program. As soon as it is known (i.e. after
load_defaults() is completed), we apply it.

Signed-off-by: Alexandru Lazar <alex@zencoding.org>
This commit is contained in:
Alexandru Lazar
2015-03-27 13:48:51 +02:00
parent 476f1e5858
commit ae2e227682
2 changed files with 28 additions and 0 deletions

View File

@@ -4,6 +4,9 @@ from GUIElements import *
class FlatCAMGUI(QtGui.QMainWindow):
# Emitted when persistent window geometry needs to be retained
geom_update = QtCore.pyqtSignal(int, int, int, int, name='geomUpdate')
def __init__(self, version):
super(FlatCAMGUI, self).__init__()
@@ -241,6 +244,8 @@ class FlatCAMGUI(QtGui.QMainWindow):
self.show()
def closeEvent(self, event):
grect = self.geometry()
self.geom_update.emit(grect.x(), grect.y(), grect.width(), grect.height())
QtGui.qApp.quit()