2 from PyQt4 import QtCore, QtGui
4 def makeLayout(parent, layout, widgets):
7 parent.setLayout(layout)
9 class PositionSelection(QtGui.QDialog):
14 def __init__(self, externalResolutions):
16 super(PositionSelection, self).__init__()
17 self.setWindowTitle('External screen setup')
19 # first box: position selection
20 posBox = QtGui.QGroupBox('Position of external screen', self)
21 self.posLeft = QtGui.QRadioButton('Left of internal screen', posBox)
22 self.posRight = QtGui.QRadioButton('Right of internal screen', posBox)
23 self.posRight.setChecked(True)
24 self.posRight.setFocus()
25 self.extOnly = QtGui.QRadioButton('Use external screen exclusively', posBox)
26 makeLayout(posBox, QtGui.QVBoxLayout(), [self.posLeft, self.posRight, self.extOnly])
28 # second box: resolution selection
29 resBox = QtGui.QGroupBox('Resolution of external screen', self)
30 resLabel = QtGui.QLabel('Select the resolution of the external screen:', resBox)
31 self.resolutions = QtGui.QComboBox(resBox)
32 for res in externalResolutions:
33 self.resolutions.addItem(res)
34 self.resolutions.setCurrentIndex(0) # select first resolution
35 makeLayout(resBox, QtGui.QHBoxLayout(), [resLabel, self.resolutions])
38 buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self)
39 buttons.accepted.connect(self.accept)
40 buttons.rejected.connect(self.reject)
42 # add them all to the window
43 makeLayout(self, QtGui.QVBoxLayout(), [posBox, resBox, buttons])
47 if self.posLeft.isChecked():
48 self.position = PositionSelection.LEFT
49 elif self.posRight.isChecked():
50 self.position = PositionSelection.RIGHT
52 self.position = PositionSelection.EXTERNAL_ONLY
53 self.resolution = str(self.resolutions.currentText())
54 # go on with default behaviour
55 super(PositionSelection, self).accept()