SHARE
TWEET

blackbeard

a guest Dec 1st, 2010 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import dbus, gobject, dbus.glib
  4.  
  5. # A function to change the status Message on Pidgin without changing the status itself.
  6. def set_message(message):
  7.         # Get current status type (Available/Away/etc.)
  8.         current = pidgin.PurpleSavedstatusGetType(pidgin.PurpleSavedstatusGetCurrent())
  9.         # Create new transient status and activate it
  10.         status = pidgin.PurpleSavedstatusNew("", current)
  11.         pidgin.PurpleSavedstatusSetMessage(status, message)
  12.         pidgin.PurpleSavedstatusActivate(status)
  13.  
  14. # A callback for when the song changes.
  15. def status_changer_func(*args, **kwargs):
  16.     mydict = rhythmshell.getSongProperties(rhythm.getPlayingUri())
  17.     set_message("Now Playing: " + mydict['artist-folded'] + " - " + mydict['title'])
  18.  
  19. # Don't need the system bus for this. Connect to the per-Session Bus
  20. bus = dbus.SessionBus()
  21.  
  22. # Associate Pidgin's dbus interface with Python objects
  23. obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
  24. pidgin = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
  25.  
  26. # Associate Rhythmbox's dbus player and shell interface(s) with Python objects
  27. # Shell is needed for getting info about the song being played - the Artist, etc.
  28. rhythm_obj = bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Player")
  29. rhythmshell_obj = bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
  30.  
  31. rhythm = dbus.Interface(rhythm_obj, "org.gnome.Rhythmbox.Player")
  32. rhythmshell= dbus.Interface(rhythmshell_obj, "org.gnome.Rhythmbox.Shell")
  33.  
  34. # Add handler for when the song changes.
  35. bus.add_signal_receiver(status_changer_func,dbus_interface="org.gnome.Rhythmbox.Player",signal_name="playingChanged")
  36.  
  37. #begin the loop that checks for signals being generated and calls the registered callbacks.
  38. loop = gobject.MainLoop()
  39. loop.run()
RAW Paste Data
Top