System Tray application for Linux using Python and GTK
But, again it is fun to create a simple gui which demonstrates how to create an active System tray application using pygtk. My simple app goes like this.
#######################################################################################
#!/usr/bin/env python
import gtk
class StatusIcc:
# activate callback
def activate( self, widget, data=None):
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 <maxinbjohn@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= None):
if response_id == gtk.RESPONSE_YES:
widget.hide()
else:
widget.hide()
# destroyer callback
def destroyer(self, widget,response_id, data= None):
if response_id == gtk.RESPONSE_OK:
gtk.main_quit()
else:
widget.hide()
# popup callback
def popup(self, button, widget, data=None):
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()
####################################################################################
Hmm , The code is pretty simple . It is using gtk.StatusIcon() for the System Tray app. The most important signal for the StatusIcon are “activate” and “poup_menu”. The callbacks for those singals are also self explanatory. So not much comments on the code. Now lets see my
app in action.

The Information (i) symbol in the system tray area is the running application. Right click and Left clicks will generate the “poup_menu” and “activate” signals respectively.
Try the tray app for you next programming adventure
Find another way to paste your code this is unusable because of whitespace is case sens. in python …
This is really interesting example. I copied it and re-indent the code.. it is working perfectly now