From: Constantin Berhard Date: Tue, 24 Nov 2015 12:41:33 +0000 (+0100) Subject: lastSetup support in question frontends X-Git-Url: https://git.ralfj.de/lilass.git/commitdiff_plain/158f0efbe4109a5d3df516404caa8567ddf5e03c?ds=inline lastSetup support in question frontends --- diff --git a/database.py b/database.py index c65b4b9..e4ec011 100644 --- a/database.py +++ b/database.py @@ -60,7 +60,7 @@ class Database: _, intres, extres, mode, extprim = result intres = Resolution.fromDatabase(intres) # this method is safe for NULLs extres = Resolution.fromDatabase(extres) - mode = RelativeScreenPosition(mode) + mode = RelativeScreenPosition(mode) if mode else None extprim = bool(extprim) # 0 => False, 1 => True return ScreenSetup(intres, extres, mode, extprim) def __exit__(self, type, value, tb): diff --git a/qt_frontend.py b/qt_frontend.py index 05c33ae..b3ee61e 100644 --- a/qt_frontend.py +++ b/qt_frontend.py @@ -53,7 +53,6 @@ try: self.intEnabled.setChecked(last.intResolution is not None) self.extEnabled.setChecked(last.extResolution is not None) if last.relPosition: - print("YO:",last.relPosition.value-1) self.relPos.setCurrentIndex(last.relPosition.value-1) # make sure we are in a correct state diff --git a/question_frontend.py b/question_frontend.py index a17b7ca..fc9e8c6 100644 --- a/question_frontend.py +++ b/question_frontend.py @@ -40,6 +40,13 @@ class QuestionFrontend: return self.userChoose("Select resolution for %s"%displayname, modedescs, availablemodes, None) def setup (self, situation): + if situation.lastSetup: + applyLast = self.userChoose("This display is known. The last setup for it was like this:\n%s.\nApply the last used configuration?" % str(situation.lastSetup), ("Apply last setup", "Enter different setup"), (True,False), None) + if applyLast is None: + return None + if applyLast is True: + return situation.lastSetup + assert applyLast is False operationmodes = list(OperationMode) operationmodedescs = list(map(lambda x: x.text, operationmodes)) operationmode = self.userChoose ("Display setup", operationmodedescs, operationmodes, None) diff --git a/screen.py b/screen.py index 456c0bd..21774df 100644 --- a/screen.py +++ b/screen.py @@ -47,6 +47,8 @@ class RelativeScreenPosition(Enum): cls = self.__class__ self._value_ = len(cls.__members__) + 1 self.text = text + def __str__(self): + return self.text class Resolution: '''Represents a resolution of a screen''' @@ -134,6 +136,13 @@ class ScreenSetup: RelativeScreenPosition.MIRROR: '--same-as', }[self.relPosition], intName] return args + + def __str__(self): + if self.intResolution is None: + return "External display only, at "+str(self.extResolution) + if self.extResolution is None: + return "Internal display only, at "+str(self.intResolution) + return "External display %s at %s %s internal display %s at %s" % ("(primary)" if self.extIsPrimary else "", str(self.extResolution), str(self.relPosition), "" if self.extIsPrimary else "(primary)", str(self.intResolution)) class Connector: def __init__(self, name=None): diff --git a/zenity_frontend.py b/zenity_frontend.py index 7dd4d82..f6834b5 100644 --- a/zenity_frontend.py +++ b/zenity_frontend.py @@ -29,7 +29,7 @@ class ZenityFrontend(QuestionFrontend): def userChoose (self, title, choices, returns, fallback): assert len(choices) == len(returns) - args = ["zenity", "--list", "--text="+title, "--column="]+choices + args = ["zenity", "--list", "--text="+title, "--column="]+list(choices) switch = dict (list(zip (choices,returns))) try: for line in processOutputIt(*args):