# -*- coding: cp932 -*- #import japanese.sjis # for setup.py import os import win32con import trayicon def hello(sysTrayIcon): sysTrayIcon.show_balloon('Hello', 'Hello World!') def error_balloon(sysTrayIcon): sysTrayIcon.show_balloon('Error! Error!', 'Error message line1\nError message line2\ndisplay 3 secs', trayicon.NIIF_ERROR, 3000) def switch_icon(sysTrayIcon): sysTrayIcon.set_icon('python.ico') def dump_menu(sysTrayIcon): from pprint import pprint pprint(sysTrayIcon.get_menus()) def on_opentrash(sysTrayIcon, msg, wp, lp): """ゴミ箱を開きます。""" os.startfile("::{645FF040-5081-101B-9F08-00AA002F954E}") #上記がうまく動かない場合は以下のコードで直接exeを指定。 #explorer = os.environ['SystemRoot'] + os.sep + 'explorer.exe' #os.spawnl( os.P_NOWAIT, explorer, explorer, "::{645FF040-5081-101B-9F08-00AA002F954E}" ) return 0 if __name__ == '__main__': import itertools, glob # get icons from current dir. icons = itertools.cycle(glob.glob('*.ico')) # icon hover text hover_text = "trayicon.py Demo" # setup menues menu_options = (('Say Hello', icons.next(), hello), ('Switch Icon', None, switch_icon), ('dump menu', None, dump_menu), ('A sub-menu', icons.next(), (('Say Error', icons.next(), error_balloon), ('Switch Icon', icons.next(), switch_icon), )) ) # on_quit_handler def bye(sysTrayIcon): print 'Bye, then.' # init sys-tray-icon sysTrayIcon = trayicon.SysTrayIcon(icons.next()) sysTrayIcon.set_menus(menu_options) sysTrayIcon.subscribe(win32con.WM_LBUTTONDBLCLK, on_opentrash) sysTrayIcon.set_icon('trayicon.ico') sysTrayIcon.set_hovertext('trayicon DEMO2') sysTrayIcon.mainloop()