1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| class DemoTaskBarIcon(wx.TaskBarIcon):
TBMENU_CLOSE = wx.NewId()
TBMENU_REMOVE = wx.NewId()
def __init__(self, frame):
wx.TaskBarIcon.__init__(self)
self.frame = frame
# Set the image
icon = wx.Image('icon.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.SetIcon(icon, "Name")
self.imgidx = 1
# bind some events
self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate)
self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE)
self.Bind(wx.EVT_MENU, self.OnTaskBarRemove, id=self.TBMENU_REMOVE)
def CreatePopupMenu(self):
menu = wx.Menu()
menu.Append(self.TBMENU_CLOSE, "Close")
menu.AppendSeparator()
menu.Append(self.TBMENU_REMOVE, "Remove Icon")
return menu
def OnTaskBarActivate(self, evt):
if self.frame.IsIconized():
self.frame.Iconize(False)
if not self.frame.IsShown():
self.frame.Show(True)
self.frame.Raise()
def OnTaskBarClose(self, evt):
self.frame.Close()
def OnTaskBarRemove(self, evt):
self.RemoveIcon() |
Partager