pysystray

pysystray

System tray icon using python

System Tray Icon ( Linux, python, gtk )

If you want to write an application which sits in the System tray of the window manager, which is really important if you dont' need much of interaction with the user.

Thanks to Red Hat Network for eggtrayiconmodule.so!!

The following are the steps for setting up your application window in the tray icon.

  1. import eggtrayiconmodule.so provided in FC2 ( used by rhn_applet_gui )

  2. create an instance of the eggtrayicon.create_window("name")

  3. add and event box and image widget

  4. handle the mouse events ( right click )

  5. Popup a menu when ever right mouse clicked

How to do the above?

trayicon.py

#!/usr/bin/python

import gtk;

import eggtrayicon;

def exit_applet( *args ):

gtk.mainquit( );

return;

def applet_face_click( window, event, *data ):

if event.button == 3 :

menu.popup( None, None, None, 0, event.time );

return;

app_window = eggtrayicon.create_window("Test");

app_window.connect( "destroy", exit_applet );

event_box = gtk.EventBox( );

image_widget = gtk.Image( );

image_widget.set_from_file("");

event_box.set_events( gtk.gdk.BUTTON_PRESS_MASK |

gtk.gdk.POINTER_MOTION_MASK |

gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.CONFIGURE );

event_box.add( image_widget );

event_box.connect("button_press_event", applet_face_click );

menu_items = (

("Check for updates", exit_applet ),

("Launch up2date", exit_applet ),

("Configuration", exit_applet ),

("RHN web interface", exit_applet ),

None,

("About...", exit_applet ),

("Exit", exit_applet),

);

menu = gtk.Menu()

for i in menu_items:

if i is None:

menu.add(gtk.SeparatorMenuItem());

else:

menu_items = gtk.MenuItem( i[0] );

menu_items.connect( 'activate', i[1] );

menu.add( menu_items );

app_window.add( event_box );

menu.show_all()

image_widget.show( );

app_window.show_all( );

gtk.mainloop( );

Note: you need to copy eggtrayiconmodule.so from "/usr/share/rhn/rhn_applet/eggtrayiconmodule.so"

for the above to work