-class ZenityFrontend:
- def error(message):
- '''Displays a fatal error to the user'''
- subprocess.check_call(["zenity", "--error", "--text="+message])
-
- def setup(self, internalResolutions, externalResolutions):
- from zenity_dialogue import run
- run(internalResolutions, externalResolutions)
-
- @staticmethod
- def isAvailable():
- try:
- from dsl import processOutputIt
- processOutputIt("zenity", "--version")
- return True
- except Exception:
- return False
-
+class ZenityFrontend(QuestionFrontend):
+ def error(self, message):
+ '''Displays a fatal error to the user'''
+ subprocess.check_call(["zenity", "--error", "--text="+message])
+ def userChoose (self, title, choices, returns, fallback):
+ assert len(choices) == len(returns)
+ args = ["zenity", "--list", "--text="+title, "--column="]+choices
+ switch = dict (list(zip (choices,returns)))
+ 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
+ # if the output was empty
+ return fallback
+ def isAvailable():
+ try:
+ processOutputIt("zenity", "--version")
+ return True
+ except FileNotFoundError:
+ return False
+ except PermissionError:
+ return False