Help wanted with GTK+ program

Discussion in 'Python' started by Hollaburoo@gmail.com, Jan 9, 2008.

  1. Guest

    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()
     
    , Jan 9, 2008
    #1
    1. Advertising

  2. DBenjamin Guest

    On Jan 8, 5:49 pm, 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
     
    DBenjamin, Jan 16, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harvey
    Replies:
    0
    Views:
    736
    Harvey
    Jul 16, 2004
  2. Harvey
    Replies:
    1
    Views:
    868
    Daniel
    Jul 16, 2004
  3. Replies:
    2
    Views:
    525
  4. Gergely Kontra
    Replies:
    2
    Views:
    251
    Joao Pedrosa
    Jun 18, 2004
  5. Alex Shulgin
    Replies:
    1
    Views:
    180
    thefed
    Nov 21, 2007
Loading...

Share This Page