Hi Soorjith,
>Hi,,, > >Anyone know how to create tray popup in pygtk? > >Pls let me know/ > >Regards >Soorjith P
A simple tray popup in pygtk goes like this (Make sure that PyGTK 2.10 or higher is present in your machine, for gtk.StatusIcon())
____________________________________________
#!/usr/bin/env python
import gtk
class StatusIcc:
# activate callback
def activate( self, widget, data=""
dialog = gtk.MessageDialog(
parent = None,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_INFO,
buttons = gtk.BUTTONS_YES_NO,
message_format = "Did you like this Activation example \n by
Maxin B. John <maxinbj...@gmail.com>?")
dialog.set_title('Popup example')
dialog.connect('response', self.show_hide)
dialog.show()
# Show_Hide callback
def show_hide(self, widget,response_id, data= ""
if response_id == gtk.RESPONSE_YES:
widget.hide()
else:
widget.hide()
# destroyer callback
def destroyer(self, widget,response_id, data= ""
if response_id == gtk.RESPONSE_OK:
gtk.main_quit()
else:
widget.hide()
# popup callback
def popup(self, button, widget, data=""
dialog = gtk.MessageDialog(
parent = None,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_INFO,
buttons = gtk.BUTTONS_OK_CANCEL,
message_format = "Do you want to close this Status Icon
program?")
dialog.set_title('Popup Window')
dialog.connect('response', self.destroyer)
dialog.show()
def __init__(self):
# create a new Status Icon
self.staticon = gtk.StatusIcon()
self.staticon.set_from_stock(gtk.STOCK_ABOUT)
self.staticon.set_blinking(True)
self.staticon.connect("activate", self.activate)
self.staticon.connect("popup_menu", self.popup)
self.staticon.set_visible(True)
# invoking the main()
gtk.main()
if __name__ == "__main__":
statusicon = StatusIcc()
____________________________________________
To test the PyGTK 2.10 requirement, Run these commands
python
import gtk
help(gtk)
then press "end" key to reach the end of document and get the ver =
(x, xx, x) line. If that's not met, then download the pygtk source ,
meet the dependency requirements and build it.
Regards,
Maxin B. John http://maxinbjohn.blog.com
|