add options to select primary screen and internal screen resolution
[lilass.git] / selector_window.py
1 #!/usr/bin/python
2 from PyQt4 import QtCore, QtGui
3
4 def makeLayout(layout, members):
5         for m in members:
6                 if isinstance(m, QtGui.QLayout):
7                         layout.addLayout(m)
8                 else:
9                         layout.addWidget(m)
10         return layout
11
12 class PositionSelection(QtGui.QDialog):
13         LEFT = 10
14         RIGHT = 20
15         EXTERNAL_ONLY = 30
16         
17         def __init__(self, internalResolutions, externalResolutions):
18                 # set up main window
19                 super(PositionSelection, self).__init__()
20                 self.setWindowTitle('External screen setup')
21                 
22                 # position selection
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]))
30                 
31                 # primary screen
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]))
38                 
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]))
56                 
57                 # last row: buttons
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)
61                 
62                 # add them all to the window
63                 self.setLayout(makeLayout(QtGui.QVBoxLayout(), [posBox, primBox, resBox, buttons]))