how to do tray popup in pygtk

292 views
Skip to first unread message

BR!j!TH

unread,
May 16, 2008, 3:59:35 AM5/16/08
to Kerala Python User Group
Hai,

Do anyone have code sample that implement the tray pop-up in python +
gtk? I googled for getting some help on this but results were not
satisfying.If any one know it please let me know how it can be done

Thanks

maxinbjohn

unread,
May 19, 2008, 3:50:30 AM5/19/08
to Kerala Python User Group
Hi Brijith,

You will have to use the gtk.StatusIcon for tray pop-up in Python +
gtk.

This is a simple System Tray application in Python + Gtk

################## Pygtk Tray application
###############################

#!/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 <maxin...@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()

#########################################################################


Hope this helps.

Regards,

Maxin B. John
http://maxinbjohn.blog.com

BR!j!TH

unread,
May 20, 2008, 12:35:03 AM5/20/08
to python...@googlegroups.com
Thanks for the suggestion,

But When I run the code it says

 python abc.py
Traceback (most recent call last):
  File "abc.py", line 64, in ?
    statusicon = StatusIcc()
  File "abc.py", line 52, in __init__
    self.staticon = gtk.StatusIcon()
AttributeError: 'module' object has no attribute 'StatusIcon'

What might be the reason. Which version of python I have to Use. I am using Python 2.4.4.
--
--------------------------------------------------
Brijith
Programmer
Core Solutions India
NIT Calicut
--------------------------------------------------

maxinbjohn

unread,
May 20, 2008, 1:47:28 AM5/20/08
to Kerala Python User Group
Dear Brijith,

The pygtk documentation says that the gtk.StatusIcon is present in the
PyGTK 2.10 or above (http://www.pygtk.org/docs/pygtk/class-
gtkstatusicon.html) .

Presently I am running the latest Ubuntu 8.04 LTS desktop which has
Python version

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2

pygtk version
ver = (2, 14, 1)

Please ensure that you meet the PyGTK 2.10 requirement. To test
this,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.

Hope this helps.

Regards,

Maxin B. John
http://maxinbjohn.blog.com






On May 20, 9:35 am, BR!j!TH <briji...@gmail.com> wrote:
> Thanks for the suggestion,
>
> But When I run the code it says
>
>  *python abc.py
> Traceback (most recent call last):
>   File "abc.py", line 64, in ?
>     statusicon = StatusIcc()
>   File "abc.py", line 52, in __init__
>     self.staticon = gtk.StatusIcon()
> AttributeError: 'module' object has no attribute 'StatusIcon'
> *
> What might be the reason. Which version of python I have to Use. I am using
> Python 2.4.4.*
> *
>
>
>
> On Mon, May 19, 2008 at 1:20 PM, maxinbjohn <maxinbj...@gmail.com> wrote:
>
> > Hi Brijith,
>
> >  You will have to use the gtk.StatusIcon for tray pop-up in Python +
> > gtk.
>
> > This is a simple System Tray application in Python + Gtk
>
> > ################## Pygtk Tray application
> > ###############################
>
> > #!/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 <maxinbj...@gmail.com>?")
Reply all
Reply to author
Forward
0 new messages