added command line argument --show
authorConstantin Berhard <git.mail.enormator@xoxy.net>
Tue, 24 Nov 2015 10:52:03 +0000 (11:52 +0100)
committerConstantin Berhard <git.mail.enormator@xoxy.net>
Tue, 24 Nov 2015 10:52:03 +0000 (11:52 +0100)
lilass
screen.py

diff --git a/lilass b/lilass
index 42c15c67775b08774cfb8d3ba3a73f10a1300079..5dfd19a70cd21d0bb7a38400ecef4dcb65c421a8 100755 (executable)
--- a/lilass
+++ b/lilass
@@ -112,7 +112,7 @@ if __name__ == "__main__":
                             dest="internal_only", action='store_true',
                             help="Enable internal screen, disable all the others.")
         parser.add_argument("-s", "--show",
                             dest="internal_only", action='store_true',
                             help="Enable internal screen, disable all the others.")
         parser.add_argument("-s", "--show",
-                            dest="show", choices=ShowLevels.getNames(),
+                            dest="show", choices=ShowLevels.getNames(), default=ShowLevels.ONEXTERNAL.text,
                             help="In which situations should the UI be displayed?")
         cmdArgs = parser.parse_args()
     
                             help="In which situations should the UI be displayed?")
         cmdArgs = parser.parse_args()
     
@@ -163,11 +163,21 @@ if __name__ == "__main__":
                 else:
                     setup = screen.ScreenSetup(intResolution = situation.internalResolutions()[0], extResolution = situation.externalResolutions()[0], relPosition = relPos)
             else:
                 else:
                     setup = screen.ScreenSetup(intResolution = situation.internalResolutions()[0], extResolution = situation.externalResolutions()[0], relPosition = relPos)
             else:
-                # ask the user
-                setup = frontend.setup(situation)
-                if setup is None: sys.exit(1) # the user canceled
-                with database.Database(databaseFilePath) as db:
-                    situation.putDBInfo(db, setup)
+                showlvl = ShowLevels(cmdArgs.show)
+                if showlvl != ShowLevels.ONEXTERNAL and situation.lastSetup:
+                    # use last config
+                    setup = situation.lastSetup
+                elif showlvl == ShowLevels.ONERROR:
+                    # guess config
+                    setup = screen.ScreenSetup(situation.internalResolutions()[0], situation.externalResolutions()[0], screen.RelativeScreenPosition.RIGHT)
+                    # TODO make default relative position configurable in the config file
+                    # TODO this has a bit of code duplication with the cmdArgs method above
+                else:
+                    # ask the user
+                    setup = frontend.setup(situation)
+                    if setup is None: sys.exit(1) # the user canceled
+                    with database.Database(databaseFilePath) as db:
+                        situation.putDBInfo(db, setup)
         else:
             # use first resolution of internal connector
             setup = screen.ScreenSetup(intResolution = situation.internalConnector.getResolutionList()[0], extResolution = None)
         else:
             # use first resolution of internal connector
             setup = screen.ScreenSetup(intResolution = situation.internalConnector.getResolutionList()[0], extResolution = None)
index 39c9367d6b61291bfab410c9318755f194ccf241..456c0bdcd6b9eb08e716dd74b3cf7b54f45ea4db 100644 (file)
--- a/screen.py
+++ b/screen.py
@@ -208,7 +208,7 @@ class ScreenSituation:
         if self.internalConnector == self.externalConnector:
             raise Exception("Internal and external connector are the same. This must not happen. Please fix ~/.dsl.conf.");
         print("Detected external connector:",self.externalConnector)
         if self.internalConnector == self.externalConnector:
             raise Exception("Internal and external connector are the same. This must not happen. Please fix ~/.dsl.conf.");
         print("Detected external connector:",self.externalConnector)
-        # self.preferredSetup is left uninitialized so you can't access it before trying a lookup in the database
+        # self.lastSetup is left uninitialized so you can't access it before trying a lookup in the database
     
     # Run xrandr and fill the dict of connector names mapped to lists of available resolutions.
     def _getXrandrInformation(self):
     
     # Run xrandr and fill the dict of connector names mapped to lists of available resolutions.
     def _getXrandrInformation(self):
@@ -296,13 +296,13 @@ class ScreenSituation:
 
     def fetchDBInfo(self, db):
         if self.externalConnector and self.externalConnector.edid:
 
     def fetchDBInfo(self, db):
         if self.externalConnector and self.externalConnector.edid:
-            self.preferredSetup = db.getConfig(self.externalConnector.edid) # may also return None
+            self.lastSetup = db.getConfig(self.externalConnector.edid) # may also return None
         else:
         else:
-            self.preferredSetup = None
-        if self.preferredSetup:
-            print("SETUP FOUND", self.preferredSetup)
-            self.externalConnector.lastResolution = self.preferredSetup.extResolution
-            self.internalConnector.lastResolution = self.preferredSetup.intResolution
+            self.lastSetup = None
+        if self.lastSetup:
+            print("SETUP FOUND", self.lastSetup)
+            self.externalConnector.lastResolution = self.lastSetup.extResolution
+            self.internalConnector.lastResolution = self.lastSetup.intResolution
         else:
             print("NO SETUP FOUND")
     
         else:
             print("NO SETUP FOUND")