Merge branch 'master' of ralfj.de:dsl
[lilass.git] / dsl.py
diff --git a/dsl.py b/dsl.py
index f9c58fa641bb4969c081ded41256f93f2b0f104f..890ea70e8cdc5b24520ea3cf30fe1b1b0fa56f06 100755 (executable)
--- a/dsl.py
+++ b/dsl.py
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program (gpl.txt); if not, write to the Free Software
+# along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
-import sys, os, re, subprocess
+import argparse, sys, os, re, subprocess
 import gui
 
 # for auto-config: common names of internal connectors
 import gui
 
 # for auto-config: common names of internal connectors
@@ -46,7 +46,7 @@ class ScreenSetup:
                return args
        
        def getExternalArgs(self, intName):
                return args
        
        def getExternalArgs(self, intName):
-               args = ["--mode", res2xrandr(self.extResolution)]
+               args = ["--mode", res2xrandr(self.extResolution)] # set external screen to desired resolution
                if self.extIsPrimary:
                        args.append('--primary')
                if self.relPosition == RelativeScreenPosition.LEFT:
                if self.extIsPrimary:
                        args.append('--primary')
                if self.relPosition == RelativeScreenPosition.LEFT:
@@ -173,6 +173,13 @@ def classifyConnectors(allConnectors):
 # if we run top-level
 if __name__ == "__main__":
        try:
 # if we run top-level
 if __name__ == "__main__":
        try:
+               # parse command-line arguments
+               parser = argparse.ArgumentParser(description='easy Display Setup for Laptops')
+               parser.add_argument("-r, --relative-position",
+                                                       dest="rel_position", choices=('left', 'right', 'external-only'),
+                                                       help="Position of external screen relative to internal one")
+               cmdArgs = parser.parse_args()
+               
                # load connectors and classify them
                connectors = getXrandrInformation()
                (internalConnector, externalConnectors) = classifyConnectors(connectors)
                # load connectors and classify them
                connectors = getXrandrInformation()
                (internalConnector, externalConnectors) = classifyConnectors(connectors)
@@ -185,10 +192,20 @@ if __name__ == "__main__":
                # check whether we got an external screen or not
                # Check what to do
                usedExternalConnector = findAvailableConnector(externalConnectors, connectors) # *the* external connector which is actually used
                # check whether we got an external screen or not
                # Check what to do
                usedExternalConnector = findAvailableConnector(externalConnectors, connectors) # *the* external connector which is actually used
-               if usedExternalConnector is not None: # there's an external screen connected, we need to ask what to do
-                       # get setup
-                       dialogue = gui.getDialogue(connectors[internalConnector], connectors[usedExternalConnector])
-                       setup = dialogue.run()
+               if usedExternalConnector is not None:
+                       # there's an external screen connected, we need to get a setup
+                       if cmdArgs.rel_position is not None:
+                               # use command-line arguments (can we do this relPosition stuff more elegant?)
+                               if cmdArgs.rel_position == 'left':
+                                       relPosition = RelativeScreenPosition.LEFT
+                               elif cmdArgs.rel_position == 'right':
+                                       relPosition = RelativeScreenPosition.RIGHT
+                               else:
+                                       relPosition = RelativeScreenPosition.EXTERNAL_ONLY
+                               setup = ScreenSetup(relPosition, connectors[internalConnector][0], connectors[usedExternalConnector][0]) # use default resolutions
+                       else:
+                               # use GUI
+                               setup = gui.setup(connectors[internalConnector], connectors[usedExternalConnector])
                        if setup is None: sys.exit(1) # the user canceled
                        # apply it
                        connectorArgs[internalConnector] = setup.getInternalArgs()
                        if setup is None: sys.exit(1) # the user canceled
                        # apply it
                        connectorArgs[internalConnector] = setup.getInternalArgs()