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, fallback):
22 assert len(choices) == len(returns)
23 p = subprocess.Popen(["zenity", "--list", "--text="+title, "--column="]+choices, stdout=subprocess.PIPE)
24 switch = dict (zip (choices,returns))
26 return switch.get(line.strip(), fallback)
29 def run (internalResolutions, externalResolutions):
30 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], None)
33 intres = internalResolutions[0]
34 if relpos != RelativeScreenPosition.EXTERNAL_ONLY:
35 intres = userChoose ("internal display resolution", map(res2user,internalResolutions), internalResolutions, internalResolutions[0])
36 extres = userChoose ("external display resolution", map(res2user,externalResolutions), externalResolutions, externalResolutions[0])
37 extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True], None)
40 return ScreenSetup(relpos,intres,extres,extprim)