Final thoughts Payday loan Top Advantages of our payday loans

System Tray application for Linux using Python and GTK

Creating an application which resides in the System tray adds charms to an otherwise simple application. Pleople tend to value accessibility and userfriendliness  than the quality of the program itself (pardon my friends, I am sure that you are not one of those chaps)

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 :)

Readmore

Python and Cairo – There will be blood…

What will a huge Hollywood fan do after Daniel Day Lewis won Best actor award for “There will be Blood” beating legendary actor like George Cluny..? Well, he will definitely watch “There will be blood”. But as that film hasn’t yet released in India, I decided to do something which is no way related to that movie..  Learn to do something interesting with Cairo in Python…

As I was thrilled about the movie- “there will be blood”, I decided to create a simple GTK animation which shows the spreading of blood in the floor.. obviously insipired from the name of the movie :)

Python code

#########################################################################
#
#PyCairo Demo:- There will be blood ..
#By Maxin B. John
#An animation to show the capabilites of PyCairo
#
# About Cairo
# Cairo is a software library used to provide a vector graphics based,
# device-independent API for software developers. It is designed to provide
# primitives for 2-dimensional drawing across a number of different backends.
#Cairo is designed to use hardware acceleration when available.
# #########################################################################
#!/usr/bin/env python

import sys
import gobject
import pygtk
pygtk.require(’2.0′)
import gtk
from gtk import gdk
import cairo

if gtk.pygtk_version < (2,10,0):
print “PyGtk 2.10.0 or later required”
raise SystemExit

win = None

#The blood is a circle filled with red color whose radius grows with time :)

def expose(widget, event):
global radius
cr= widget.window.cairo_create()
cr.set_source_rgba(1.0, 0, 0, 0.7)
cr.arc(float(radius)/2, float(radius)/2, radius, 0, 2.0*3.14)
cr.fill()
cr.stroke()
return True

# this keeps the blood flowing…

def update_clock():
global win
global radius
radius = radius +1
win.queue_draw()
return True

# the ‘main’ function

def main(args):
global win
global radius
radius =0
win = gtk.Window()
win.set_app_paintable(True)
win.set_title(‘PyCairo Demo’)
win.connect(‘delete-event’, gtk.main_quit)
win.connect(‘expose-event’, expose)
gobject.timeout_add(100, update_clock)

win.show_all()
gtk.main()
return True

# The pythonic way to start the animation
if __name__ == ‘__main__’:
     sys.exit(main(sys.argv))

And the output Cool

Don’t you feel the smell of blood…  ??? Undecided

Readmore