556158c2c108c4f8b18769decc63604218c9684d
[lilass.git] / selector_window.py
1 # DSL - easy Display Setup for Laptops
2 # Copyright (C) 2012 Ralf Jung <post@ralfj.de>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program (gpl.txt); if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 from PyQt4 import QtCore, QtGui
18
19 def makeLayout(layout, members):
20         for m in members:
21                 if isinstance(m, QtGui.QLayout):
22                         layout.addLayout(m)
23                 else:
24                         layout.addWidget(m)
25         return layout
26
27 class PositionSelection(QtGui.QDialog):
28         LEFT = 10
29         RIGHT = 20
30         EXTERNAL_ONLY = 30
31         
32         def __init__(self, externalName, internalResolutions, externalResolutions):
33                 # set up main window
34                 super(PositionSelection, self).__init__()
35                 self.setWindowTitle('External screen setup (connector: %s)' % externalName)
36                 
37                 # position selection
38                 posBox = QtGui.QGroupBox('Position of external screen', self)
39                 self.posLeft = QtGui.QRadioButton('Left of internal screen', posBox)
40                 self.posRight = QtGui.QRadioButton('Right of internal screen', posBox)
41                 self.posRight.setChecked(True)
42                 self.posRight.setFocus()
43                 self.extOnly = QtGui.QRadioButton('Use external screen exclusively', posBox)
44                 posBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.posLeft, self.posRight, self.extOnly]))
45                 
46                 # primary screen
47                 primBox = QtGui.QGroupBox('Which should be the primary screen?', self)
48                 self.extOnly.toggled.connect(primBox.setDisabled) # disable the box if there's just one screen in use
49                 self.primExt = QtGui.QRadioButton('The external screen', primBox)
50                 self.primInt = QtGui.QRadioButton('The internal screen', primBox)
51                 self.primInt.setChecked(True)
52                 primBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [self.primExt, self.primInt]))
53                 
54                 # resolution selection
55                 resBox = QtGui.QGroupBox('Screen resolutions', self)
56                 extResLabel = QtGui.QLabel('Resolution of external screen:', resBox)
57                 self.extResolutions = QtGui.QComboBox(resBox)
58                 for res in externalResolutions:
59                         self.extResolutions.addItem(res)
60                 self.extResolutions.setCurrentIndex(0) # select first resolution
61                 extRow = makeLayout(QtGui.QHBoxLayout(), [extResLabel, self.extResolutions])
62                 intResLabel = QtGui.QLabel('Resolution of internal screen:', resBox)
63                 self.extOnly.toggled.connect(intResLabel.setDisabled) # disable the label if there's just one screen in use
64                 self.intResolutions = QtGui.QComboBox(resBox)
65                 for res in internalResolutions:
66                         self.intResolutions.addItem(res)
67                 self.intResolutions.setCurrentIndex(0) # select first resolution
68                 self.extOnly.toggled.connect(self.intResolutions.setDisabled) # disable the box if there's just one screen in use
69                 intRow = makeLayout(QtGui.QHBoxLayout(), [intResLabel, self.intResolutions])
70                 resBox.setLayout(makeLayout(QtGui.QVBoxLayout(), [extRow, intRow]))
71                 
72                 # last row: buttons
73                 buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self)
74                 buttons.accepted.connect(self.accept)
75                 buttons.rejected.connect(self.reject)
76                 
77                 # add them all to the window
78                 self.setLayout(makeLayout(QtGui.QVBoxLayout(), [posBox, primBox, resBox, buttons]))