def isAvailable(): try: processOutputIt("zenity", "--version") return True except FileNotFoundError: return False except PermissionError: return False
def userChoose(self, title, choices, returns, fallback): assert len(choices) == len(returns) args = ["zenity", "--list", "--text=" + title, "--column="] + list(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 userChoose(self, title, choices, returns, fallback): assert len(choices) == len(returns) args = ["zenity", "--list", "--text=" + title, "--column=" ] + list(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