Import WX
Import Images
Class Demotaskbaricon (WX. Taskbaricon):
Tbmenu_restore = wx. NewId ()
Tbmenu_close = wx. NewId ()
Tbmenu_change = wx. NewId ()
Tbmenu_remove = wx. NewId ()
def __init__ (self, frame):
Wx. Taskbaricon.__init__ (self)
Self.frame = Frame
# Set the image
icon = self. Makeicon (Images.getwxpdemoimage ())
Self. SetIcon (Icon, "WxPython Demo")
SELF.IMGIDX = 1
# Bind some events
Self. Bind (WX. Evt_taskbar_left_dclick, self. Ontaskbaractivate)
Self. Bind (WX. Evt_menu, self. Ontaskbaractivate, Id=self. Tbmenu_restore)
Self. Bind (WX. Evt_menu, self. Ontaskbarclose, Id=self. Tbmenu_close)
Self. Bind (WX. Evt_menu, self. Ontaskbarchange, Id=self. Tbmenu_change)
Self. Bind (WX. Evt_menu, self. Ontaskbarremove, Id=self. Tbmenu_remove)
def createpopupmenu (self):
"""
This are called by the base class when it needs to Popup
The menu for the default Evt_right_down event. Just Create
The menu how to want it and return it to this function,
The base class takes care of the rest.
"""
menu = WX. Menu ()
Menu. Append (self. Tbmenu_restore, "RESTORE wxPython Demo")
Menu. Append (self. Tbmenu_close, "Close WxPython Demo")
Menu. Appendseparator ()
Menu. Append (self. Tbmenu_change, "Change the TB Icon")
Menu. Append (self. Tbmenu_remove, "REMOVE the TB Icon")
Return menu
def makeicon (Self, img):
""
the various platforms have different requirements for the
& nbsp; icon Size ...
""
If "WXMSW" in WX. PlatformInfo:
img = img. Scale
elif "WXGTK" in WX. PlatformInfo:
img = img. Scale
# Wxmac can be any size upto 128x128, so leave the source img Alone .....
icon = wx. Iconfrombitmap (IMG. Converttobitmap ())
return icon
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 ontaskbarchange (self, evt):
names = ["Wxpdemo", "Mondrian", "Pencil", "carrot"]
name = Names[self.imgidx]
Getfunc = getattr (Images, "get%simage"% name)
SELF.IMGIDX + 1
If Self.imgidx >= len (names):
SELF.IMGIDX = 0
icon = self. Makeicon (Getfunc ())
Self. SetIcon (Icon, "This is a new icon:" + name)
def ontaskbarremove (self, evt):
Self. RemoveIcon ()
Class MyFrame (WX. Frame):
def __init__ (self):
Wx. Frame.__init__ (self, None,-1, "My Frame", size= (300, 300))
panel = WX. Panel (self,-1)
Panel. Bind (WX. Evt_motion, self. OnMove)
Wx. Statictext (Panel,-1, "Pos:", pos= (10, 12))
Self.posctrl = wx. Textctrl (Panel,-1, "", pos= (40, 10))
Try
Self.tbicon = Demotaskbaricon (self)
Except
Self.tbicon = None
#wx. Callafter (self. Showtip)
#self. Bind (WX. Evt_close, self. Onclosewindow)
#self. Bind (WX. Evt_iconize, self. Oniconfiy)
def onclosewindow (self, event):
self.dying = True
Self.demopage = None
Self.codepage = None
Self.mainmenu = None
If Self.tbicon is not None:
Self.tbicon.Destroy ()
Self. Destroy ()
def oniconfiy (self, evt):
Wx. LogMessage ("oniconfiy:%s"% evt.) Iconized ())
Evt. Skip ()
def onmove (self, event):
pos = event. GetPosition ()
Self.posCtrl.SetValue ("%s,%s"% (pos.x, pos.y))
if __name__ = = ' __main__ ':
App = WX. Pysimpleapp ()
frame = MyFrame ()
Frame. Show (True)
App. Mainloop ()