2 from PyQt4 import QtCore, QtGui
4 def makeLayout(layout, members):
6 if isinstance(m, QtGui.QLayout):
12 class PositionSelection(QtGui.QDialog):
17 def __init__(self, externalName, internalResolutions, externalResolutions):
19 super(PositionSelection, self).__init__()
20 self.setWindowTitle('External screen setup (connector: %s)' % externalName)
23 posBox = QtGui.QGroupBox('Position of external screen', self)
24 self.posLeft = QtGui.QRadioButton('Left of internal screen', posBox)
25 self.posRight = QtGui.QRadioButton('Right of internal screen', posBox)
26 self.posRight.setChecked(True)
27 self.posRight.setFocus()
28 self.extOnly = QtGui.QRadioButton('Use external screen exclusively', posBox)
29 posBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.posLeft, self.posRight, self.extOnly]))
32 primBox = QtGui.QGroupBox('Which should be the primary screen?', self)
33 self.extOnly.toggled.connect(primBox.setDisabled) # disable the box if there's just one screen in use
34 self.primExt = QtGui.QRadioButton('The external screen', primBox)
35 self.primInt = QtGui.QRadioButton('The internal screen', primBox)
36 self.primInt.setChecked(True)
37 primBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.primExt, self.primInt]))
39 # resolution selection
40 resBox = QtGui.QGroupBox('Screen resolutions', self)
41 extResLabel = QtGui.QLabel('Resolution of external screen:', resBox)
42 self.extResolutions = QtGui.QComboBox(resBox)
43 for res in externalResolutions:
44 self.extResolutions.addItem(res)
45 self.extResolutions.setCurrentIndex(0) # select first resolution
46 extRow = makeLayout(QtGui.QHBoxLayout(), [extResLabel, self.extResolutions])
47 intResLabel = QtGui.QLabel('Resolution of internal screen:', resBox)
48 self.extOnly.toggled.connect(intResLabel.setDisabled) # disable the label if there's just one screen in use
49 self.intResolutions = QtGui.QComboBox(resBox)
50 for res in internalResolutions:
51 self.intResolutions.addItem(res)
52 self.intResolutions.setCurrentIndex(0) # select first resolution
53 self.extOnly.toggled.connect(self.intResolutions.setDisabled) # disable the box if there's just one screen in use
54 intRow = makeLayout(QtGui.QHBoxLayout(), [intResLabel, self.intResolutions])
55 resBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [extRow, intRow]))
58 buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self)
59 buttons.accepted.connect(self.accept)
60 buttons.rejected.connect(self.reject)
62 # add them all to the window
63 self.setLayout(makeLayout(QtGui.QVBoxLayout(), [posBox, primBox, resBox, buttons]))