Help wanted with GTK+ program

DBenjamin davidben at fmtc.com
Wed Jan 16 15:01:32 EST 2008


On Jan 8, 5:49 pm, Hollabu... at gmail.com wrote:
> I'm working on a simple GTK+ wrapper around the flash Pandora Radio
> player (Pandora.com).
>
> It's very basic right now but I've got it almost working.
> I'm using gtkmozembed to fetch and use the player and dbus to detect
> multimedia keys.
> The only problem I'm having is that the mozembed widget doesn't seem
> to recognize the fake keypress event sent to it.
>
> CODE
>
> #!/usr/bin/env python
>
> import gtk
> import gtkmozembed
> import dbus
> from dbus.mainloop.glib import DBusGMainLoop
>
> class Wrapper:
>     def __init__(self):
>         # Set-up the wrapper for the player
>
>         self.win = gtk.Window() # Create a new GTK window called 'win'
>
>         self.win.set_title("Pandora Player") # Set the title of the
> window
>         self.win.set_icon_from_file('favicon.ico') # Set the window
> icon to a web browser icon
>         self.win.set_position(gtk.WIN_POS_CENTER) # Position the
> window in the centre of the screen
>
>         self.win.connect("destroy", self.close_window) # Connect the
> 'destroy' event to the 'CloseWindow' function, so that the app will
> quit properly
>
>         # Handle media keys under Gnome
>         DBusGMainLoop(set_as_default=True)
>         bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
>         settings = bus.get_object('org.gnome.SettingsDaemon', '/org/
> gnome/SettingsDaemon') # Connect to gnome settings D-Bus
>         settings.connect_to_signal("MediaPlayerKeyPressed",
> self.action)
>
>         # Create the browser widget
>         gtkmozembed.set_profile_path("/tmp", "simple_browser_user") #
> Set a temporary Mozilla profile (works around some bug)
>         self.mozbrowser = gtkmozembed.MozEmbed() # Create the browser
> widget
>
>         # Set-up the browser widget before we display it
>         self.win.add(self.mozbrowser) # Add the 'mozbrowser' widget to
> the main window 'win'
>         self.mozbrowser.load_url("https://www.pandora.com:443/radio/
> tuner_8_2_0_2_pandora.swf") # Load Pandora
>         self.mozbrowser.set_size_request(640,540) # Size arrived at
> after careful trial and error
>         self.mozbrowser.show() # Needed for correct size
>
>         self.win.show_all() # Show the window
>
>     def PlayPause(self, ):
>         event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
>         event.keyval = gtk.keysyms.space
>         event.time = 0 # assign current time
>         self.mozbrowser.grab_focus()
>         self.win.emit('key_press_event', event)
>
>     def ThumbsDown(self):
>         event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
>         event.keyval = gtk.keysyms.minus
>         event.time = 0 # assign current time
>         self.mozbrowser.grabfocus()
>         self.win.emit('key_press_event', event)
>
>     def ThumbsUp(self):
>         event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
>         event.keyval = gtk.keysyms.plus
>         event.time = 0 # assign current time
>         self.mozbrowser.grabfocus()
>         self.win.emit('key_press_event', event)
>
>     def Skip(self):
>         event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
>         event.keyval = gtk.keysyms.Right
>         event.time = 0 # assign current time
>         self.mozbrowser.grabfocus()
>         self.win.emit('key_press_event', event)
>
>     # Handles key presses
>     def action(self, *keys):
>         for key in keys:
>             if key == "Play":
>                 self.PlayPause()
>             elif key == "Stop":
>                 self.ThumbsUp()
>             elif key == "Previous":
>                 self.ThumbsDown()
>             elif key == "Next":
>                 self.Skip()
>
>     def close_window(self, caller_widget):
>         """Close the window and exit the app"""
>         gtk.main_quit() # Close the app fully
>
> if __name__ == "__main__":
>         wrapper = Wrapper()
>         gtk.main()

I was looking for something like you are writing and seen this post,
maybe it would help you?
http://rjoblog.wordpress.com/2007/12/19/pandora-4-all/
He is showing this url:  https://www.pandora.com/radio/tuner_8_2_0_2_pandora.swf



More information about the Python-list mailing list