+ # keep resolutions in sync when in mirror mode
+ def syncIfMirror(source, target):
+ def _slot(idx):
+ if self.isMirror:
+ target.setCurrentIndex(idx)
+ source.currentIndexChanged.connect(_slot)
+ syncIfMirror(self.intRes, self.extRes)
+ syncIfMirror(self.extRes, self.intRes)
+
+ # connect the update function, and make sure we are in a correct state
+ self.intEnabled.toggled.connect(self.updateEnabledControls)
+ self.extEnabled.toggled.connect(self.updateEnabledControls)
+ self.relPos.currentIndexChanged.connect(self.updateEnabledControls)
+ self.updateEnabledControls()
+
+ def getRelativeScreenPosition(self):
+ idx = self.relPos.currentIndex()
+ return self.relPos.itemData(idx)
+
+ def fillResolutionBox(self, box, resolutions):
+ # if the count did not change, update in-place (this avoids flicker)
+ if box.count() == len(resolutions):
+ for idx, res in enumerate(resolutions):
+ box.setItemText(idx, str(res))
+ box.setItemData(idx, res)
+ else:
+ # first clear it
+ while box.count() > 0:
+ box.removeItem(0)
+ # then fill it
+ for res in resolutions:
+ box.addItem(str(res), res)
+
+ def updateEnabledControls(self):
+ intEnabled = self.intEnabled.isChecked()
+ extEnabled = self.extEnabled.isChecked()
+ bothEnabled = intEnabled and extEnabled
+ self.isMirror = bothEnabled and self.getRelativeScreenPosition() == RelativeScreenPosition.MIRROR # only if both are enabled, we can really mirror
+ # configure screen controls
+ self.intRes.setEnabled(intEnabled)
+ self.intPrimary.setEnabled(intEnabled and not self.isMirror)
+ self.extRes.setEnabled(extEnabled)
+ self.extPrimary.setEnabled(extEnabled and not self.isMirror)
+ if not intEnabled and extEnabled:
+ self.extPrimary.setChecked(True)
+ elif not extEnabled and intEnabled:
+ self.intPrimary.setChecked(True)
+ # which resolutions do we offer?
+ if self.isMirror:
+ commonRes = self._situation.commonResolutions()
+ self.fillResolutionBox(self.intRes, commonRes)
+ self.fillResolutionBox(self.extRes, commonRes)
+ self.intRes.setCurrentIndex(self.extRes.currentIndex())
+ else:
+ self.fillResolutionBox(self.intRes, self._situation.internalResolutions())
+ self.fillResolutionBox(self.extRes, self._situation.externalResolutions())
+ # configure position control
+ self.posGroup.setEnabled(bothEnabled)
+ self.posLabel1.setEnabled(bothEnabled)
+ self.posLabel2.setEnabled(bothEnabled)
+ self.relPos.setEnabled(bothEnabled)
+ # avoid having no screen
+ self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(intEnabled or extEnabled)