Commits

Luke Plant committed d06eb0c

Split out 'install_mate' as a separate command from 'install_gnome'

Comments (0)

Files changed (4)

 Change log
 ==========
 
+Version 0.7
+-----------
+
+* Added support for installing shortcuts in Mate
+
 Version 0.6.1
 -------------
 
 (play, pause, next etc.) to Do The Right Thing without having to change anything
 if you switch to a different media player.
 
-It also includes a command 'install_gnome' to help set up keyboard shortcuts
-initially on GNOME. It can, however, be used with any system where you can map
-keyboard shortcuts to commands.
+It also includes commands 'install_gnome' and 'install_mate' to help set up
+keyboard shortcuts initially on GNOME and Mate. It can, however, be used with
+any system where you can map keyboard shortcuts to commands.
 
 The currently supported media players can be seen by running 'player_do
 help'. Those that have been tested include the following:
     ("test", "Tests that all dependencies are available.", do_test),
     ("help", "Prints help.", print_usage),
     ("install_gnome", "Install keybindings for GNOME and launch keybinding editor",
-     lambda *args: install.install_gnome())
+     lambda *args: install.install_gnome()),
+    ("install_mate", "Install keybindings for Mate and launch keybinding editor",
+     lambda *args: install.install_mate()),
 ])
 
 command_dict = dict((name, f) for name, doc, f in commands)

playerdo/install.py

 
 KEYBINDINGS_PREFIX = "/desktop/gnome/keybindings"
 
+
 def force_unicode(s):
     if type(s) is not unicode:
         return s.decode('UTF-8')
     else:
         return s
 
-def install_gnome():
-    """
-    Creates stub keybindings for player_do commands in GNOME, and launches a GUI
-    editor for the user to set keys.
-    """
+
+def install_gnome_shortcuts():
     already_installed = set()
     max_count = 0
     for d in get_gnome_keybindings():
             install_action("custom%d" % n, action, name)
             n += 1
     sys.stdout.write("Launching keybinding editor...\nEdit 'player_do' keybindings in 'Custom shortcuts' section, and close when done.\n")
-    launch_keybinding_editor()
+
+
+def install_gnome():
+    """
+    Creates stub keybindings for player_do commands in GNOME, and launches a GUI
+    editor for the user to set keys.
+    """
+    install_gnome_shortcuts()
+    launch_keybinding_editor("gnome-keybinding-properties")
+
+
+def install_mate():
+    """
+    Creates stub keybindings for player_do commands in Mate, and launches a GUI
+    editor for the user to set keys.
+    """
+    install_gnome_shortcuts()
+    launch_keybinding_editor("mate-keybinding-properties")
 
 
 def get_gnome_keybindings():
     sys.stdout.write("Keybinding slot for action '%s' created\n" % action)
 
 
-KEYBINDING_EDITOR_NAMES = ["gnome-keybinding-properties",
-                           "mate-keybinding-properties"]
-
-def launch_keybinding_editor():
+def launch_keybinding_editor(prog):
     errors = []
     success = False
-    for prog in KEYBINDING_EDITOR_NAMES:
-        p = Popen(["which", prog], stdout=PIPE)
-        stdout, stderr = p.communicate(None)
-        val = force_unicode(stdout).strip()
-        if val == "":
-            continue
-        else:
-            call(["nohup %s &" % val], shell=True, stdout=open("/dev/null"), stderr=open("/dev/null"))
-            success = True
-            break
+    p = Popen(["which", prog], stdout=PIPE)
+    stdout, stderr = p.communicate(None)
+    val = force_unicode(stdout).strip()
+    if val != "":
+        call(["nohup %s &" % val], shell=True, stdout=open("/dev/null"), stderr=open("/dev/null"))
+        success = True
     if not success:
-        sys.stdout.write("Error: Couldn't find a program for editing keybindings. Tried: %s\n"
-                         % ", ".join(KEYBINDING_EDITOR_NAMES))
+        sys.stdout.write("Error: Couldn't find program %s for editing keybindings.\n" % prog)
         raise SystemExit()