It’s just data

gtk StatusIcon

From time to time, I have found a need for limited communication with an otherwise background process.  A tray icon serves this purpose well.  Instead of dynamically generated SVG, you certainly can use Cairo or static filesTooltips, blinking, callbacks, and menus are also possibilities.

# enable cron
import os
if not 'DISPLAY' in os.environ:
  os.environ['DISPLAY']=':0.0'
if not 'HOME' in os.environ:
  os.environ['HOME']=os.path.expanduser('~'+os.getlogin())

import gtk
icon = gtk.StatusIcon()

def set_image(color):
  import rsvg
  image = """
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
      <path d="M42,95L50,30L58,95Z" fill="%s" stroke="none"/>
      <path d="M39,20a15,15 0,0,0 0,20 M28,10a30,30 0,0,0 0,40
        M61,20a15,15 0,0,1 0,20 M72,10a30,30 0,0,1 0,40" stroke="%s"
        fill="none" stroke-width="5" stroke-linecap="round"/>
    </svg>
  """
  handle=rsvg.Handle()
  handle.write(image % (color,color))
  handle.close()
  try:
    gtk.gdk.threads_enter()
    icon.set_from_pixbuf(handle.get_pixbuf())
  finally:
    gtk.gdk.threads_leave()
  
# spin GTK off in a background thread
import threading
gtk.gdk.threads_init()
class gtkmain(threading.Thread):
  def run(self):
    gtk.main()
gtkmain().start()

# user logic
import time
set_image('red')
time.sleep(3)
set_image('yellow')
time.sleep(3)
set_image('green')
time.sleep(3)
gtk.main_quit()

Every OS needs a growl: [link]

Posted by Patrick Mueller at

Patrick:  amusing — I was thinking exactly the same thing as I was reading Sam’s post.

Posted by d.w. at

[from hublicious] Sam Ruby: gtk StatusIcon

[link]...

Excerpt from del.icio.us/network/cmillward at

A very, very cool idea....

Excerpt from Talideon.com Linklog at

Does Growl support two way communications with the application?

Posted by Sam Ruby at

Growl is mostly one-way. You can give it a callback, when the notification message is clicked, that’s pretty much it.

But for those kinds of lower-priority notifications that do not require feedback, it is indeed very nice. For example, notifications of downloads finishing, or presence of certain contacts on instant messenging networks.

Posted by Pierre Phaneuf at

Add your comment