Commits

Vladimir Kolev committed 08b1f38

Added example functionality for using multimedia keys for controlling the player
Currently in very early alpha stage, since no test is made if this is working on
computers without multimedia keys.

  • Participants
  • Parent commits 6444c21

Comments (0)

Files changed (2)

File gsharkdown.py

 from lib.tfuncs import t_download
 from lib.tfuncs import t_play
 from lib.tfuncs import t_search
+from lib.tfuncs import t_key_listener
 import urllib2
 import webbrowser
 import pickle
         self.progress_bar = builder.get_object('progressbar1')
         self.play_button = builder.get_object('toolbutton3')
         self.ff_button = builder.get_object('toolbutton9')
+        self.prev_button = builder.get_object('toolbutton14')
         self.songinfo = builder.get_object('songinfo')
         self.songinfo.set_text("")
         repeat_button = builder.get_object('togglebutton1')
             pynotify.init("gSharkDown")
 
         builder.connect_signals(self)
-
+        self.tlisten = t_key_listener(self)
+        self.tlisten.start()
         self.window.show_all()
 
     def load_saved_playlist(self):

File lib/tfuncs.py

 import sys
 import gtk
 import gobject
+import dbus
+import dbus.service
+import dbus.mainloop.glib
 import time
 from urllib import urlretrieve
 import threading
         else:
             self.win.play_button.set_stock_id(gtk.STOCK_MEDIA_STOP)
 
+class t_key_listener(threading.Thread):
+
+    def __init__(self, _window):
+        threading.Thread.__init__(self)
+        self.win = _window
+
+    def run(self):
+        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+        bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
+        bus_object = bus.get_object('org.gnome.SettingsDaemon',
+                                '/org/gnome/SettingsDaemon/MediaKeys')
+    
+        dbus_interface = 'org.gnome.SettingsDaemon.MediaKeys'
+        bus_object.GrabMediaPlayerKeys("MyMultimediaThingy", 0,
+                                  dbus_interface=dbus_interface)
+
+        bus_object.connect_to_signal('MediaPlayerKeyPressed',
+                                self.on_media_key)
+    
+    def on_media_key(self, comes_from, what):
+        if what in ['Stop', 'Play', 'Next', 'Previous']:
+            if what == 'Stop':
+                self.win.play_selected(self.win.play_button)
+            elif what == 'Play':
+                self.win.play_selected(self.win.play_button)
+            elif what == 'Next':
+                self.win.play_next(self.win.ff_button)
+            elif what == 'Previous':
+                self.win.play_previous(self.win.prev_button)
 
 class t_search(threading.Thread):