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; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 from dsl import RelativeScreenPosition, ScreenSetup, res2user, processOutputIt
20 def userChoose (title, choices, returns, fallback):
21 assert len(choices) == len(returns)
22 args = ["zenity", "--list", "--text="+title, "--column="]+choices
23 switch = dict (list(zip (choices,returns)))
25 for line in processOutputIt(*args):
26 return switch.get(line.strip(), fallback)
28 # on user cancel, the return code of zenity is nonzero
32 def run (internalResolutions, externalResolutions):
33 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)
36 intres = internalResolutions[0]
37 extres = externalResolutions[0]
39 if relpos != RelativeScreenPosition.EXTERNAL_ONLY:
40 intres = userChoose ("internal display resolution", list(map(res2user,internalResolutions)), internalResolutions, None)
45 extres = userChoose ("external display resolution", list(map(res2user,externalResolutions)), externalResolutions, None)
49 extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True], None)
52 return ScreenSetup(relpos,intres,extres,extprim)