X-Git-Url: https://git.ralfj.de/lilass.git/blobdiff_plain/b8a3257b112e87352dfc719d4c4da4ab6ae69c30..93e1258e8c9afca0e3cba00d765d6de0afa1bc3e:/selector_window.py diff --git a/selector_window.py b/selector_window.py index 47fb831..adee7e4 100644 --- a/selector_window.py +++ b/selector_window.py @@ -1,60 +1,63 @@ #!/usr/bin/python -from PyQt4 import QtGui +from PyQt4 import QtCore, QtGui + +def makeLayout(layout, members): + for m in members: + if isinstance(m, QtGui.QLayout): + layout.addLayout(m) + else: + layout.addWidget(m) + return layout class PositionSelection(QtGui.QDialog): LEFT = 10 RIGHT = 20 EXTERNAL_ONLY = 30 - def __init__(self, resolutions): - super(PositionSelection, self).__init__() + def __init__(self, internalResolutions, externalResolutions): + # set up main window + super(PositionSelection, self).__init__() + self.setWindowTitle('External screen setup') - mainBox = QtGui.QVBoxLayout() - posBox = QtGui.QHBoxLayout() - resBox = QtGui.QHBoxLayout() + # 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])) - # First row: Resolution selection - mainBox.addLayout(resBox) - resBox.addWidget(QtGui.QLabel('Select the resolution of the external screen:')) - self.resolutions = QtGui.QComboBox(self) - for res in resolutions: - self.resolutions.addItem(res) - self.resolutions.setCurrentIndex(0) # select first resolution - resBox.addWidget(self.resolutions) + # 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) + self.primInt.setChecked(True) + primBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.primExt, self.primInt])) - # Next two rows: Position selection - mainBox.addWidget(QtGui.QLabel('Select the position of the external screen relative to the internal one:')) - mainBox.addLayout(posBox) - - btn = QtGui.QPushButton('Left', self) - btn.clicked.connect(self.left) - posBox.addWidget(btn) - - btn = QtGui.QPushButton('Right', self) - btn.clicked.connect(self.right) - btn.setFocus() - posBox.addWidget(btn) - - btn = QtGui.QPushButton('External only', self) - btn.clicked.connect(self.externalOnly) - posBox.addWidget(btn) - - # Finalization - self.setLayout(mainBox) - self.setWindowTitle('External screen setup') - - def accept(self): - self.resolution = str(self.resolutions.currentText()) - super(PositionSelection, self).accept() - - def left(self): - self.position = PositionSelection.LEFT - self.accept() - - def right(self): - self.position = PositionSelection.RIGHT - self.accept() - - def externalOnly(self): - self.position = PositionSelection.EXTERNAL_ONLY - self.accept() + # resolution selection + resBox = QtGui.QGroupBox('Screen resolutions', self) + extResLabel = QtGui.QLabel('Resolution of external screen:', resBox) + self.extResolutions = QtGui.QComboBox(resBox) + for res in externalResolutions: + self.extResolutions.addItem(res) + self.extResolutions.setCurrentIndex(0) # select first resolution + extRow = makeLayout(QtGui.QHBoxLayout(), [extResLabel, self.extResolutions]) + 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.intResolutions = QtGui.QComboBox(resBox) + for res in internalResolutions: + self.intResolutions.addItem(res) + self.intResolutions.setCurrentIndex(0) # select first resolution + self.extOnly.toggled.connect(self.intResolutions.setDisabled) # disable the box if there's just one screen in use + intRow = makeLayout(QtGui.QHBoxLayout(), [intResLabel, self.intResolutions]) + resBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [extRow, intRow])) + + # last row: buttons + buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self) + buttons.accepted.connect(self.accept) + buttons.rejected.connect(self.reject) + + # add them all to the window + self.setLayout(makeLayout(QtGui.QVBoxLayout(), [posBox, primBox, resBox, buttons]))