popup.py

Go to the documentation of this file.
00001 import gtk,gtk.glade,gobject,thread
00002 from plai import config
00003 from plai import lyrics
00004 
00005 
00006 def ShowPopup(event,track):
00007         """Creates a popup context menu for 'track'."""
00008         xml=gtk.glade.XML(config.gladepopupmenufname)
00009         menu=xml.get_widget('popup')
00010         menu.popup(None,None,None,event.button,event.time)
00011 
00012         # Apologies for this line. But it was too fun to write...
00013         # Connects the lyrics menu item to a handler that calls
00014         # GetLyrics in a new thread and then calls LyricsWindow
00015         # back in this thread.
00016         xml.get_widget('GetLyrics').connect('activate',
00017          lambda w,f,a: thread.start_new_thread(f,a),
00018           lambda a,t: gobject.idle_add(
00019            lyrics.LyricsWindow,lyrics.GetLyrics(a,t),a,t),
00020             (track.Artist(),track.Title()))
00021                     
00022         xml.get_widget('Properties').connect('activate',_onProperties,track)
00023 
00024         
00025 def _onProperties(widget,track):
00026         """Handler for clicking Properties in the context menu. Shows a dialog
00027         with the filename of the track."""
00028         # todo - set transient-for properly
00029         dlg=gtk.Dialog('Properties',None,0,(gtk.STOCK_CLOSE,gtk.RESPONSE_ACCEPT))
00030         dlg.connect('response',lambda x,y: dlg.hide())
00031         dlg.set_has_separator(False)
00032         label=gtk.Label('<tt>'+track.Filename()+'</tt>')
00033         label.set_property('use_markup',True)
00034         label.set_line_wrap(True)
00035         label.set_selectable(True)
00036         dlg.vbox.add(label)
00037         dlg.show_all()
00038         

Generated on Mon Aug 6 21:24:20 2007 for plai by  doxygen 1.5.1