Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help wanted with GTK+ program

Reply
Thread Tools

Help wanted with GTK+ program

 
 
Hollaburoo@gmail.com
Guest
Posts: n/a
 
      01-09-2008
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()
 
Reply With Quote
 
 
 
 
DBenjamin
Guest
Posts: n/a
 
      01-16-2008
On Jan 8, 5:49 pm, (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WANTED: AT desktop cases, wanted for sculpture. Brett NZ Computing 0 09-09-2004 07:14 AM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM
server/client program design advice wanted Junpei Perl 1 05-27-2004 12:09 AM
Video capure program wanted Barry OGrady Computer Support 0 09-03-2003 02:18 PM



Advertisments