From: Constantin Berhard Date: Wed, 4 Feb 2015 15:22:38 +0000 (+0100) Subject: fixed zenity X-Git-Url: https://git.ralfj.de/lilass.git/commitdiff_plain/4dd0918b62956f292f8448c32d8c61fbbeacfeb4 fixed zenity --- diff --git a/gui.py b/gui.py index 50cb3a3..40cafa5 100644 --- 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(): diff --git a/zenity_dialogue.py b/zenity_dialogue.py index 93213e9..e926b3a 100644 --- a/zenity_dialogue.py +++ b/zenity_dialogue.py @@ -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)