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