1 # DSL - easy Display Setup for Laptops
2 # Copyright (C) 2012 Ralf Jung <post@ralfj.de>
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.
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.
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.
19 from dsl import RelativeScreenPosition, ScreenSetup, res2user
21 def userChoose (title, choices, returns):
22 assert len(choices) == len(returns)
23 p = subprocess.Popen(["zenity", "--list", "--text="+title, "--column="]+choices, stdout=subprocess.PIPE)
24 switch = zip (choices,returns)
26 return switch.get(line, None)
28 def run (internalResolutions, externalResolutions):
29 relpos = userChoose ("Position of external screen", ["Left of internal screen", "Right of internal screen", "Use external screen only"], [RelativeScreenPosition.LEFT, RelativeScreenPosition.RIGHT, RelativeScreenPosition.EXTERNAL_ONLY])
32 intres = internalResolutions[0]
33 if relpos != RelativeScreenPosition.EXTERNAL_ONLY:
34 intres = userChoose ("internal display resolution", map(res2user,internalResolutions), internalResolutions)
37 extres = userChoose ("external display resolution", map(res2user,externalResolutions), externalResolutions)
40 extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True])
43 return ScreenSetup(relpos,intres,extres,extprim)