Introduction

This basically creates a taskbar icon, and makes makes it blink/stop blinking on double-click events and exit on a right click event. You'll need the 3 .ico files (yellow/black/red.ico) to run this example.

   1 #!/usr/bin/env python
   2 import wx
   3 
   4 ID_ICON_TIMER = wx.NewId()
   5 
   6 class TaskBarFrame(wx.Frame):
   7     def __init__(self, parent):
   8         wx.Frame.__init__(self, parent, style=wx.FRAME_NO_TASKBAR | wx.NO_FULL_REPAINT_ON_RESIZE)
   9         self.icon_state = False
  10         self.blink_state = False
  11 
  12         self.tbicon = wx.TaskBarIcon()
  13         icon = wx.Icon('yellow.ico', wx.BITMAP_TYPE_ICO)
  14         self.tbicon.SetIcon(icon, '')
  15         wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarLeftDClick)
  16         wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarRightClick)
  17         self.Show(True)
  18 
  19     def OnTaskBarLeftDClick(self, evt):
  20         try:
  21             self.icontimer.Stop()
  22         except:
  23             pass
  24         if self.icon_state:
  25             icon = wx.Icon('yellow.ico', wx.BITMAP_TYPE_ICO)
  26             self.tbicon.SetIcon(icon, 'Yellow')
  27             self.icon_state = False
  28         else:
  29             self.SetIconTimer()
  30             self.icon_state = True
  31 
  32     def OnTaskBarRightClick(self, evt):
  33         self.Close(True)
  34         wx.GetApp().ProcessIdle()
  35 
  36     def SetIconTimer(self):
  37         self.icontimer = wx.Timer(self, ID_ICON_TIMER)
  38         wx.EVT_TIMER(self, ID_ICON_TIMER, self.BlinkIcon)
  39         self.icontimer.Start(1000)
  40 
  41     def BlinkIcon(self, evt):
  42         if not self.blink_state:
  43             icon = wx.Icon('red.ico', wx.BITMAP_TYPE_ICO)
  44             self.tbicon.SetIcon(icon, 'Red')
  45             self.blink_state = True
  46         else:
  47             icon = wx.Icon('black.ico', wx.BITMAP_TYPE_ICO)
  48             self.tbicon.SetIcon(icon, 'Black')
  49             self.blink_state = False
  50 
  51 
  52 app = wx.App(False)
  53 frame = TaskBarFrame(None)
  54 frame.Show(False)
  55 app.MainLoop()

Masklinn (Xavier Morel)

FlashingTaskbarIcon (last edited 2010-01-17 18:37:31 by 79-65-133-135)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.