fixed zenity
authorConstantin Berhard <constantin@exxxtremesys.lu>
Wed, 4 Feb 2015 15:22:38 +0000 (16:22 +0100)
committerConstantin Berhard <constantin@exxxtremesys.lu>
Wed, 4 Feb 2015 15:22:38 +0000 (16:22 +0100)
gui.py
zenity_dialogue.py

diff --git a/gui.py b/gui.py
index 50cb3a3d6377c7ce4bed77040fe79099ac08aca4..40cafa55e8dc2cda6c0850cbfa42723f407b8c99 100644 (file)
--- a/gui.py
+++ b/gui.py
@@ -63,7 +63,7 @@ class ZenityFrontend:
     
     def setup(self, internalResolutions, externalResolutions, commonRes):
         from zenity_dialogue import run
-        run(internalResolutions, externalResolutions)
+        return run(internalResolutions, externalResolutions)
     
     @staticmethod
     def isAvailable():
index 93213e9af1a0fc00003aaba46d205275e90e56e1..e926b3a0efdd65d4806f5309e92660a208140dce 100644 (file)
@@ -21,8 +21,12 @@ def userChoose (title, choices, returns, fallback):
     assert len(choices) == len(returns)
     args = ["zenity", "--list", "--text="+title, "--column="]+choices
     switch = dict (list(zip (choices,returns)))
-    for line in processOutputIt(*args):
-        return switch.get(line.strip(), fallback)
+    try:
+        for line in processOutputIt(*args):
+            return switch.get(line.strip(), fallback)
+    except Exception:
+        # on user cancel, the return code of zenity is nonzero
+        return fallback
     return fallback
 
 def run (internalResolutions, externalResolutions):
@@ -30,10 +34,19 @@ def run (internalResolutions, externalResolutions):
     if relpos == None:
         return None
     intres = internalResolutions[0]
+    extres = externalResolutions[0]
+    extprim = None
     if relpos != RelativeScreenPosition.EXTERNAL_ONLY:
-        intres = userChoose ("internal display resolution", list(map(res2user,internalResolutions)), internalResolutions, internalResolutions[0])
-    extres = userChoose ("external display resolution", list(map(res2user,externalResolutions)), externalResolutions, externalResolutions[0])
-    extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True], None)
+        intres = userChoose ("internal display resolution", list(map(res2user,internalResolutions)), internalResolutions, None)
+        if intres == None:
+            return None
+    else:
+        extprim = True
+    extres = userChoose ("external display resolution", list(map(res2user,externalResolutions)), externalResolutions, None)
+    if extres == None:
+        return None
+    if extprim == None:
+        extprim = userChoose ("Which display should be the primary display?", ["internal display", "external display"], [False, True], None)
     if extprim == None:
         return None
     return ScreenSetup(relpos,intres,extres,extprim)