X-Git-Url: https://git.ralfj.de/lilass.git/blobdiff_plain/7129adf1f29ada89d37adf131dbab8d3c5483408..4dd0918b62956f292f8448c32d8c61fbbeacfeb4:/qt_dialogue.py?ds=inline diff --git a/qt_dialogue.py b/qt_dialogue.py index 879a09a..c82b8f9 100644 --- a/qt_dialogue.py +++ b/qt_dialogue.py @@ -26,47 +26,59 @@ def makeLayout(layout, members): return layout class PositionSelection(QtGui.QDialog): - def __init__(self, internalResolutions, externalResolutions): + def __init__(self, internalResolutions, externalResolutions, commonResolutions): # set up main window super(PositionSelection, self).__init__() self.setWindowTitle('DSL - easy Display Setup for Laptops') - # position selection + ## position selection posBox = QtGui.QGroupBox('Position of external screen', self) self.posLeft = QtGui.QRadioButton('Left of internal screen', posBox) self.posRight = QtGui.QRadioButton('Right of internal screen', posBox) self.posRight.setChecked(True) self.posRight.setFocus() self.extOnly = QtGui.QRadioButton('Use external screen exclusively', posBox) - posBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.posLeft, self.posRight, self.extOnly])) + self.mirror = QtGui.QRadioButton('Mirror internal screen', posBox) + positions = [self.posLeft, self.posRight, self.extOnly, self.mirror] + posBox.setLayout(makeLayout(QtGui.QVBoxLayout(), positions)) + for pos in positions: + pos.toggled.connect(self.updateForm) - # primary screen - primBox = QtGui.QGroupBox('Which should be the primary screen?', self) - self.extOnly.toggled.connect(primBox.setDisabled) # disable the box if there's just one screen in use - self.primExt = QtGui.QRadioButton('The external screen', primBox) - self.primInt = QtGui.QRadioButton('The internal screen', primBox) + ## primary screen + self.primBox = QtGui.QGroupBox('Which should be the primary screen?', self) + self.primExt = QtGui.QRadioButton('The external screen', self.primBox) + self.primInt = QtGui.QRadioButton('The internal screen', self.primBox) self.primInt.setChecked(True) - primBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.primExt, self.primInt])) + self.primBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.primExt, self.primInt])) - # resolution selection + ## resolution selection resBox = QtGui.QGroupBox('Screen resolutions', self) - extResLabel = QtGui.QLabel('Resolution of external screen:', resBox) + # external screen + self.extResLabel = QtGui.QLabel('Resolution of external screen:', resBox) self.extResolutions = externalResolutions self.extResolutionsBox = QtGui.QComboBox(resBox) for res in externalResolutions: self.extResolutionsBox.addItem(res2user(res)) self.extResolutionsBox.setCurrentIndex(0) # select first resolution - extRow = makeLayout(QtGui.QHBoxLayout(), [extResLabel, self.extResolutionsBox]) - intResLabel = QtGui.QLabel('Resolution of internal screen:', resBox) - self.extOnly.toggled.connect(intResLabel.setDisabled) # disable the label if there's just one screen in use + self.extRow = makeLayout(QtGui.QHBoxLayout(), [self.extResLabel, self.extResolutionsBox]) + # internal screen + self.intResLabel = QtGui.QLabel('Resolution of internal screen:', resBox) self.intResolutions = internalResolutions self.intResolutionsBox = QtGui.QComboBox(resBox) for res in internalResolutions: self.intResolutionsBox.addItem(res2user(res)) self.intResolutionsBox.setCurrentIndex(0) # select first resolution - self.extOnly.toggled.connect(self.intResolutionsBox.setDisabled) # disable the box if there's just one screen in use - intRow = makeLayout(QtGui.QHBoxLayout(), [intResLabel, self.intResolutionsBox]) - resBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [extRow, intRow])) + self.intRow = makeLayout(QtGui.QHBoxLayout(), [self.intResLabel, self.intResolutionsBox]) + # both screens + self.mirrorResLabel = QtGui.QLabel('Resolution of both screens:', resBox) + self.mirrorResolutions = commonResolutions + self.mirrorResolutionsBox = QtGui.QComboBox(resBox) + for res in commonResolutions: + self.mirrorResolutionsBox.addItem(res2user(res)) + self.mirrorResolutionsBox.setCurrentIndex(0) # select first resolution + self.mirrorRow = makeLayout(QtGui.QHBoxLayout(), [self.mirrorResLabel, self.mirrorResolutionsBox]) + # show them all + resBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.extRow, self.intRow, self.mirrorRow])) # last row: buttons buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self) @@ -74,20 +86,40 @@ class PositionSelection(QtGui.QDialog): buttons.rejected.connect(self.reject) # add them all to the window - self.setLayout(makeLayout(QtGui.QVBoxLayout(), [posBox, primBox, resBox, buttons])) + self.setLayout(makeLayout(QtGui.QVBoxLayout(), [posBox, self.primBox, resBox, buttons])) + + # make sure we are consistent + self.updateForm() + + def updateForm(self): + self.primBox.setEnabled(self.posLeft.isChecked() or self.posRight.isChecked()) + self.extResolutionsBox.setEnabled(not self.mirror.isChecked()) + self.extResLabel.setEnabled(not self.mirror.isChecked()) + self.intResolutionsBox.setEnabled(self.posLeft.isChecked() or self.posRight.isChecked()) + self.intResLabel.setEnabled(self.posLeft.isChecked() or self.posRight.isChecked()) + self.mirrorResolutionsBox.setEnabled(self.mirror.isChecked()) + self.mirrorResLabel.setEnabled(self.mirror.isChecked()) def run(self): self.exec_() if not self.result(): return None - return ScreenSetup(self.getRelativeScreenPosition(), - self.intResolutions[self.intResolutionsBox.currentIndex()], - self.extResolutions[self.extResolutionsBox.currentIndex()], - self.primExt.isChecked()) + if self.mirror.isChecked(): + return ScreenSetup(RelativeScreenPosition.MIRROR, + self.mirrorResolutions[self.mirrorResolutionsBox.currentIndex()], + self.mirrorResolutions[self.mirrorResolutionsBox.currentIndex()], + extIsPrimary = True) + else: + return ScreenSetup(self.getRelativeScreenPosition(), + self.intResolutions[self.intResolutionsBox.currentIndex()], + self.extResolutions[self.extResolutionsBox.currentIndex()], + self.primExt.isChecked()) def getRelativeScreenPosition(self): if self.posLeft.isChecked(): return RelativeScreenPosition.LEFT elif self.posRight.isChecked(): return RelativeScreenPosition.RIGHT - else: + elif self.extOnly.isChecked(): return RelativeScreenPosition.EXTERNAL_ONLY + else: + raise Exception("Nothing is checked?")