#!/usr/bin/python #_*_ coding:utf-8 _*_ import gtk import gobject import sys import gd def makeIcon(temp,humi): im = gd.image((23,22)) white = im.colorAllocate((255,255,255)) black = im.colorAllocate((0,0,0)) red = im.colorAllocate((255,0,0)) blue = im.colorAllocate((0,0,255)) im.filledRectangle((0,0),(23,22),white) im.lines(((0,0),(22,0),(22,0),(22,21),(22,21),(0,21),(0,0)),blue) if temp == '0' or humi == '0': im.string(gd.gdFontTiny,(2,5),"init..",red) else : im.string(gd.gdFontTiny,(2,2),temp,red) im.string(gd.gdFontTiny,(2,12),humi,red) f = open("/tmp/exdt.png","w") im.writePng(f) f.close() def updateIcon(iochannel,condition,*args): systray = args[0] tnh = args[1] tooltip = '' data = iochannel.readline() data = data[:-2] envr = data.split(' ') if len(envr) == 1: return True if envr[1] == '_T' : tnh['temp'] = envr[0] elif envr[1] == '_H' : tnh['humi'] = envr[0] if tnh['temp'] != '0.0' and tnh['humi'] != '0.0': makeIcon(tnh['temp'],tnh['humi']) systray.set_from_file("/tmp/exdt.png") tooltip = "온도: "+tnh['temp']+"°C" + "\n" + "습도: "+tnh['humi']+"%" systray.set_tooltip(tooltip) else : return True return True def endOfThisProgram(widget,*string): sys.exit() def myMenu(systray,button,time,*args): mymenu = gtk.Menu() endItem = gtk.MenuItem("끝내기") mymenu.add(endItem) endItem.connect("activate",endOfThisProgram) endItem.show() mymenu.show() mymenu.popup(None,None,None,button,time) def systemTrayRun(): systray = gtk.StatusIcon() makeIcon("0","0") systray.set_from_file("/tmp/exdt.png") systray.set_tooltip("정보를 받아오는 중입니다.\n잠시기다려주십시오") systray.set_visible(True) systray.connect("popup-menu",myMenu) fd = open('/tmp/exdt','r') gobject.io_add_watch(fd,gobject.IO_IN,updateIcon,systray,tnh) gtk.main() fd.close(); tnh = {'temp':'0','humi':'0'} print "StatusIcon" systemTrayRun()