added experimental code for a zenity "gui", yet untested as I can't find my vga cable
[lilass.git] / zenity_dialogue.py
1 # DSL - easy Display Setup for Laptops
2 # Copyright (C) 2012 Ralf Jung <post@ralfj.de>
3 #
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.
8 #
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.
13 #
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.
17
18 import subprocess
19 from dsl import RelativeScreenPosition, ScreenSetup, res2user
20
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)
25         for line in p.stdout:
26                 return switch.get(line, None)
27
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])
30         if relpos == None:
31                 return None
32         intres = internalResolutions[0]
33         if relpos != RelativeScreenPosition.EXTERNAL_ONLY:
34                 intres = userChoose ("internal display resolution", map(res2user,internalResolutions), internalResolutions)
35         if intres == None:
36                 return None
37         extres = userChoose ("external display resolution", map(res2user,externalResolutions), externalResolutions)
38         if extres == None:
39                 return None
40         extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True])
41         if extprim == None:
42                 return None
43         return ScreenSetup(relpos,intres,extres,extprim)