Simplify
authorJames Bunton <jamesbunton@delx.net.au>
Sun, 13 May 2012 00:07:49 +0000 (10:07 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Sun, 13 May 2012 00:07:49 +0000 (10:07 +1000)
wallchanger.py

index 8230f48..caf7ddb 100755 (executable)
@@ -28,13 +28,15 @@ def check_cmd(cmd):
 def init(*args, **kwargs):
        """Desktop Changer factory"""
 
+       classes = []
+
        if sys.platform == "win32":
-               changers.append(WIN32Changer(*args, **kwargs))
+               classes.append(WIN32Changer)
                return
 
        logging.debug("Testing for OSX (NonX11)")
        if check_cmd("ps ax -o command -c|grep -q WindowServer"):
-               changers.append(OSXChanger(*args, **kwargs))
+               classes.append(OSXChanger)
 
        if 'DISPLAY' not in os.environ or os.environ['DISPLAY'].startswith('/tmp/launch'):
                # X11 is not running
@@ -48,22 +50,25 @@ def init(*args, **kwargs):
 
        logging.debug("Testing for KDE")
        if check_cmd("xwininfo -name 'KDE Desktop'"):
-               changers.append(KDEChanger(*args, **kwargs))
+               classes.append(KDEChanger)
 
        logging.debug("Testing for Gnome")
        if check_cmd("xwininfo -name 'gnome-settings-daemon'"):
                if check_cmd("gsettings get org.gnome.desktop.background picture-uri"):
-                       changers.append(Gnome3Changer(*args, **kwargs))
+                       classes.append(Gnome3Changer)
                else:
-                       changers.append(Gnome2Changer(*args, **kwargs))
+                       classes.append(Gnome2Changer)
 
        logging.debug("Testing for WMaker")
        if check_cmd("xlsclients | grep -qi wmaker"):
-               changers.append(WMakerChanger(*args, **kwargs))
+               classes.append(WMakerChanger)
        
-       if len(changers) == 0:
+       if len(classes) == 0:
                raise Exception("Unknown window manager")
 
+       for klass in classes:
+               changers.append(klass(*args, **kwargs))
+
 
 class BaseChanger(object):
        name = "undefined"