+# CLI frontend
+class CLIFrontend:
+ def error(self, message):
+ print(message, file=sys.stderr)
+
+ def setup(self, internalResolutions, externalResolutions):
+ raise Exception("Choosing the setup interactively is not supported with the CLI frontend")
+
+ @staticmethod
+ def isAvailable():
+ return True
+
+# list of available frontends
+frontends = collections.OrderedDict()
+frontends["qt"] = QtFrontend
+frontends["zenity"] = ZenityFrontend
+frontends["cli"] = CLIFrontend
+
+# get a frontend
+def getFrontend(name = None):
+ # by name
+ if name is not None:
+ if name in frontends:
+ if frontends[name].isAvailable():
+ return frontends[name]() # call constructor
+ # frontend not found or not available
+ raise Exception("Frontend %s not found or not available" % name)
+ # auto-detect
+ for frontend in frontends.values():
+ if frontend.isAvailable():
+ return frontend() # call constructor
+ raise Exception("No frontend is available - this should not happen")