pre select last used setup in qt gui
[lilass.git] / qt_frontend.py
index 62e3b842054ce3760668ed8c263314e0d04835cd..05c33ae26ddf0f91241dfa73d2e67e8a931336ae 100644 (file)
@@ -19,9 +19,9 @@ from screen import RelativeScreenPosition, ScreenSetup
 
 try:
     # Be fine with PyQt4 not being installed
-    from PyQt4 import QtCore, QtGui, uic
+    from PyQt5 import QtCore, QtWidgets, uic
 
-    class PositionSelection(QtGui.QDialog):
+    class PositionSelection(QtWidgets.QDialog):
         def __init__(self, situation):
             # set up main window
             super(PositionSelection, self).__init__()
@@ -42,12 +42,23 @@ try:
             syncIfMirror(self.intRes, self.extRes)
             syncIfMirror(self.extRes, self.intRes)
 
-            # connect the update function, and make sure we are in a correct state
+            # connect the update function
             self.intEnabled.toggled.connect(self.updateEnabledControls)
             self.extEnabled.toggled.connect(self.updateEnabledControls)
             self.relPos.currentIndexChanged.connect(self.updateEnabledControls)
+
+            # if situation has a lastSetup, use its values as initial state
+            if situation.lastSetup:
+                last = situation.lastSetup
+                self.intEnabled.setChecked(last.intResolution is not None)
+                self.extEnabled.setChecked(last.extResolution is not None)
+                if last.relPosition:
+                    print("YO:",last.relPosition.value-1)
+                    self.relPos.setCurrentIndex(last.relPosition.value-1)
+
+            # make sure we are in a correct state
             self.updateEnabledControls()
-        
+
         def getRelativeScreenPosition(self):
             idx = self.relPos.currentIndex()
             return self.relPos.itemData(idx)
@@ -95,7 +106,7 @@ try:
             self.posLabel2.setEnabled(bothEnabled)
             self.relPos.setEnabled(bothEnabled)
             # avoid having no screen
-            self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(intEnabled or extEnabled)
+            self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(intEnabled or extEnabled)
         
         def run(self):
             self.exec_()
@@ -109,13 +120,13 @@ except ImportError:
 # Qt frontend
 class QtFrontend:
     def __init__(self):
-        from PyQt4 import QtGui
-        self.app = QtGui.QApplication(sys.argv)
+        from PyQt5 import QtWidgets
+        self.app = QtWidgets.QApplication(sys.argv)
         print("Qt loaded")
     
     def error(self, message):
-        from PyQt4 import QtGui
-        QtGui.QMessageBox.critical(None, 'Fatal error', message)
+        from PyQt5 import QtWidgets
+        QtWidgets.QMessageBox.critical(None, 'Fatal error', message)
     
     def setup(self, situation):
         return PositionSelection(situation).run()
@@ -123,7 +134,7 @@ class QtFrontend:
     @staticmethod
     def isAvailable():
         try:
-            import PyQt4
+            import PyQt5
             return True
         except ImportError:
             return False