0041dd7fc1399b02395f48677a1d9df67d5d631b
[lilass.git] / selector_window.py
1 #!/usr/bin/python
2 from PyQt4 import QtCore, QtGui
3
4 def makeLayout(parent, layout, widgets):
5         for w in widgets:
6                 layout.addWidget(w)
7         parent.setLayout(layout)
8
9 class PositionSelection(QtGui.QDialog):
10         LEFT = 10
11         RIGHT = 20
12         EXTERNAL_ONLY = 30
13         
14         def __init__(self, externalResolutions):
15                 # set up main window
16                 super(PositionSelection, self).__init__()
17                 self.setWindowTitle('External screen setup')
18                 
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])
27                 
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])
36                 
37                 # last row: buttons
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)
41                 
42                 # add them all to the window
43                 makeLayout(self, QtGui.QVBoxLayout(), [posBox, resBox, buttons])
44         
45         def accept(self):
46                 # store return values
47                 if self.posLeft.isChecked():
48                         self.position = PositionSelection.LEFT
49                 elif self.posRight.isChecked():
50                         self.position = PositionSelection.RIGHT
51                 else:
52                         self.position = PositionSelection.EXTERNAL_ONLY
53                 self.resolution = str(self.resolutions.currentText())
54                 # go on with default behaviour
55                 super(PositionSelection, self).accept()