1 # DSL - easy Display Setup for Laptops
2 # Copyright (C) 2012 Ralf Jung <post@ralfj.de>
3 # Copyright (C) 2012-2015 Constantin Berhard<constantin@exxxtremesys.lu>
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.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 from screen import RelativeScreenPosition, ScreenSetup, processOutputIt
21 def userChoose (title, choices, returns, fallback):
22 assert len(choices) == len(returns)
23 args = ["zenity", "--list", "--text="+title, "--column="]+choices
24 switch = dict (list(zip (choices,returns)))
26 for line in processOutputIt(*args):
27 return switch.get(line.strip(), fallback)
29 # on user cancel, the return code of zenity is nonzero
33 def run (internalResolutions, externalResolutions):
34 relpos = userChoose ("Position of external screen", ["Left of internal screen", "Right of internal screen"], [RelativeScreenPosition.LEFT, RelativeScreenPosition.RIGHT], None)
37 intres = internalResolutions[0]
38 extres = externalResolutions[0]
40 extres = userChoose ("external display resolution", list(map(str,externalResolutions)), externalResolutions, None)
44 extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True], None)
47 return ScreenSetup(intres, extres, relpos, extIsPrimary = extprim)