wxPython创建系统托盘

摘自:
http://wiki.wxpython.org/index.cgi/FlashingTaskbarIcon

完整代如下:
# 导入wxPython模块
from  wxPython.wx  import   *

ICON_STATE 
=  0
BLINK_STATE 
=  0

ID_ICON_TIMER 
=   1000
# 创建继承wxFrame的类
class  TaskBarApp(wxFrame):
    
def   __init__ (self, parent, id, title):
    
# 构造一窗体
    wxFrame. __init__ (self, parent,  - 1 , title, size  =  ( 1 1 ),style = wxFRAME_NO_TASKBAR | wxNO_FULL_REPAINT_ON_RESIZE)
        
    
# 创建系统托盘ICO对象并赋给tbicon
    self.tbicon  =  wxTaskBarIcon()
        
    icon 
=  wxIcon( ' bb_yellow.ico ' , wxBITMAP_TYPE_ICO)

    self.tbicon.SetIcon(icon, 
'' )

    
# 绑定一些事件
    EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarLeftDClick)
    EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarRightClick)
    self.Show(true)

    
# 左键双击事件的处理方法
     def  OnTaskBarLeftDClick(self, evt):
        
global  ICON_STATE
        
try :
            self.icontimer.Stop()
        
except :
            
pass
        
if  ICON_STATE  ==   1 :
            icon 
=  wxIcon( ' bb_yellow.ico ' , wxBITMAP_TYPE_ICO)
            self.tbicon.SetIcon(icon, 
' Yellow ' )
            ICON_STATE 
=  0
        
else :
            self.SetIconTimer()
            ICON_STATE 
=   1

    
# 右键单击处理方法
     def  OnTaskBarRightClick(self, evt):
        self.Close(true)
        wxGetApp().ProcessIdle()

    
def  SetIconTimer(self):
        self.icontimer 
=  wxTimer(self, ID_ICON_TIMER)
        EVT_TIMER(self, ID_ICON_TIMER, self.BlinkIcon)
        self.icontimer.Start(
1000 )

    
def  BlinkIcon(self, evt):
        
global  BLINK_STATE
        
if  BLINK_STATE  ==  0:
            icon 
=  wxIcon( ' bb_red.ico ' , wxBITMAP_TYPE_ICO)
            self.tbicon.SetIcon(icon, 
' Red ' )
            BLINK_STATE 
=   1
        
else :
            icon 
=  wxIcon( ' bb_black.ico ' , wxBITMAP_TYPE_ICO)
            self.tbicon.SetIcon(icon, 
' Black ' )
            BLINK_STATE 
=  0

# 创建App类
class  MyApp(wxApp):
    
def  OnInit(self):
        frame 
=  TaskBarApp(None,  - 1 '   ' )
        frame.Center(wxBOTH)
        frame.Show(false)
        
return  true
# run
def  main():
    app 
=  MyApp(0)
    app.MainLoop()
if   __name__   ==   ' __main__ ' :
    main()

根据自己的理解补了一些注释,希望能够看的清楚点...

你可能感兴趣的:(cgi,UP,wxPython)