importwxfromwximportImageFromStream,BitmapFromImage,EmptyIconimportcStringIO,zlib# ================================ ICON ======================================defgetData():returnzlib.decompress('x\xda\x01\x97\x03h\xfc\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\\x08\x08\x08|\x08d\x88\x00\x00\x03NIDAT8\x8dm\xd2ML\x9bu\x00\xc7\xf1\xef\xf3\\xb2\xd9\xc7\tI0$\xc0\xd5d\x06\xa5\\x17q\xf9O\xa5\x0b$$\x85KB\xa2\xec\xcb\xbc\x1e}\x81\xdf\x01$q\x9a`>\xce\xc9`\\xc7\x91#\xa1\xce\xa3;\xed\xdbg\xb3s\x19c\xe1\x9cz\xbe*A\x0f\x80\x80\xf4A\\xeb\xb0\xfcPG\xa2;\x10\x8aI\xe5\xd9\x93\x8bB\xe6`l\x88U)\xf3-\xc7\xc3\xbb_{\;r\xef\xe1Vci\xa4\xb0\xbc:\x17\xb8\xdczQ\xd3B5"A\x1f\x00\xa7"\xe39\x16\xfb\\xd6_\xb1wu\x1f@\xa9\x15-k\xe6\xd4j\xa2D\xbf\xec\x95\x91\xe5PGX_\x18),.\xcei\W\xdb\xbf\xd3:\xb7{49\x0e\xeem\x1dkAG+Z\xb4l\xdf\xc6o-\xc3\xea\x9fK\xbf\x84\\xe5\xa6\xfe&\xa1>\xa8\xad)\xec\x96n}\xc6`E\xa8g7\x95d\xdbD\xf2\x82\xda\xae\\x06\x08\xd95\x1e\xeej\xa2\xa1^F \xa1\x1b5\xae\xcf\xe5\xa8D\x14\xea\xf4\xf3\\xdco\x9es\xb7\x9933\xe1Z\xe9U\t\xe0\xd8\xe7\x17?\t4\xecz7\x99\xd0hp\x05\x87\\xf6u\x927\x0c6-\x87\xf6\xd6\x16\x00\xaa\x02\xbeN\xdd\xc2\xd7\x04\x99\xec:9K\\xf9\xf8\xd37\x07\x8e\xcb\x00\x99\xca=\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07\x85B\xdel\x8e\xc7%]\xd7/\xa7R\xa9\xe4\x96\xc04M\xc7q\x9c\\xb5\x89\x89\x89N!\xc4\xd3S\xdf|4\xcd\xfftw\xff\x97_]\xd3\xf5I\xc0\xf2}\xdf\\x02\xf8\x0b\xc1.\x9e\xd8Y.\x85\x85\x00\x00\x00\x00IEND\xaeB`\x822\x86\xba\\xb3')defgetBitmap():returnBitmapFromImage(getImage())defgetImage():stream=cStringIO.StringIO(getData())returnImageFromStream(stream)defgetIcon():icon=EmptyIcon()icon.CopyFromBitmap(getBitmap())returnicon# ============================================================================classMainWindow(wx.Frame):def__init__(self,*args,**kwargs):wx.Frame.__init__(self,*args,**kwargs)self.number=0self.Bind(wx.EVT_CLOSE,self.OnClose)self.panel=wx.Panel(self)self.button=wx.Button(self.panel,label="Test")self.button.Bind(wx.EVT_BUTTON,self.OnButton)self.tbicon=wx.TaskBarIcon()self.tbicon.SetIcon(getIcon(),"Test")self.sizer=wx.BoxSizer()self.sizer.Add(self.button)self.panel.SetSizerAndFit(self.sizer)self.Show()# --------------------------------------------------------------------------defOnClose(self,e):self.tbicon.Destroy()self.Destroy()wx.Exit()# --------------------------------------------------------------------------defOnButton(self,e):# HERE WE GO!self.number+=1bitmap=getBitmap()# Find unused colorimage=bitmap.ConvertToImage()my_solid_color=wx.Color(*image.FindFirstUnusedColour(0,0,0)[1:])# Use the unused *unique* color to drawdc=wx.MemoryDC()dc.SetTextForeground(my_solid_color)dc.SelectObject(bitmap)dc.DrawText(str(self.number),0,0)dc.SelectObject(wx.NullBitmap)# Convert the bitmap to Image again# and fix the alpha of pixels with that colorimage=bitmap.ConvertToImage()forxinrange(image.GetWidth()):foryinrange(image.GetHeight()):p=wx.Colour(image.GetRed(x,y),image.GetGreen(x,y),image.GetBlue(x,y))ifp==my_solid_color:image.SetAlpha(x,y,255)# Clear the alphaimage.SetRGB(x,y,0,0,0)# Set the color that we want# Convert back to Bitmap and save to Iconbitmap=image.ConvertToBitmap()icon=wx.IconFromBitmap(bitmap)self.tbicon.SetIcon(icon,"Test")app=wx.App(False)win=MainWindow(None)app.MainLoop()