rename COPYING
[lilass.git] / zenity_dialogue.py
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>
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; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 from screen import RelativeScreenPosition, ScreenSetup, processOutputIt
20
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)))
25     try:
26         for line in processOutputIt(*args):
27             return switch.get(line.strip(), fallback)
28     except Exception:
29         # on user cancel, the return code of zenity is nonzero
30         return fallback
31     return fallback
32
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)
35     if relpos == None:
36         return None
37     intres = internalResolutions[0]
38     extres = externalResolutions[0]
39     extprim = True
40     extres = userChoose ("external display resolution", list(map(str,externalResolutions)), externalResolutions, None)
41     if extres == None:
42         return None
43     if extprim == None:
44         extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True], None)
45     if extprim == None:
46         return None
47     return ScreenSetup(intres, extres, relpos, extIsPrimary = extprim)