Guest User

Untitled

a guest
Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. 1. class IconBar:
  2. 2.
  3. 3. ##
  4. 4. # \brief the constructor default left: red, default right: green
  5. 5. #
  6. 6. def __init__(self,l_off=[128,0,0],l_on=[255,0,0],r_off=[0,128,0],r_on=[0,255,0]):
  7. 7. self.s_line = "\xff\xff\xff"+"\0"*45
  8. 8. self.s_border = "\xff\xff\xff\0\0\0"
  9. 9. self.s_point = "\0"*3
  10. 10. self.sl_off = string.join(map(chr,l_off),'')*6
  11. 11. self.sl_on = string.join(map(chr,l_on),'')*6
  12. 12. self.sr_off = string.join(map(chr,r_off),'')*6
  13. 13. self.sr_on = string.join(map(chr,r_on),'')*6
  14. 14.
  15. 15. ##
  16. 16. # \brief gets a new icon with 0 <= l,r <= 5
  17. 17. #
  18. 18. def Get(self,l,r):
  19. 19. s=""+self.s_line
  20. 20. for i in range(5):
  21. 21. if i<(5-l):
  22. 22. sl = self.sl_off
  23. 23. else:
  24. 24. sl = self.sl_on
  25. 25.
  26. 26. if i<(5-r):
  27. 27. sr = self.sr_off
  28. 28. else:
  29. 29. sr = self.sr_on
  30. 30.
  31. 31. s+=self.s_border+sl+self.s_point+sr+self.s_point
  32. 32. s+=self.s_border+sl+self.s_point+sr+self.s_point
  33. 33. s+=self.s_line
  34. 34.
  35. 35. image = wx.EmptyImage(16,16)
  36. 36. image.SetData(s)
  37. 37.
  38. 38. bmp = image.ConvertToBitmap()
  39. 39. bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white
  40. 40.
  41. 41. icon = wx.EmptyIcon()
  42. 42. icon.CopyFromBitmap(bmp)
  43. 43.
  44. 44. return icon
  45. 45.
  46. 46. ##
  47. 47. # The TaskBarIcon class
  48. 48. #
  49. 49. class MyTaskBarIcon(wx.TaskBarIcon):
  50. 50.
  51. 51. l = 0
  52. 52. r = 0
  53. 53.
  54. 54. ##
  55. 55. # \brief the constructor
  56. 56. #
  57. 57. def __init__(self, frame):
  58. 58. wx.TaskBarIcon.__init__(self)
  59. 59. self.frame = frame
  60. 60. self.IconBar = IconBar((127,127,0),(255,255,0),(0,127,127),(0,255,255))
  61. 61. self.SetIconBar(self.l,self.r)
  62. 62.
  63. 63. ##
  64. 64. # \brief sets the icon timer
  65. 65. #
  66. 66. def SetIconTimer(self):
  67. 67. self.icon_timer = wx.Timer(self, ID_ICON_TIMER)
  68. 68. wx.EVT_TIMER(self, ID_ICON_TIMER, self.BlinkIcon)
  69. 69. self.icon_timer.Start(100)
  70. 70.
  71. 71. ##
  72. 72. # \brief blinks the icon and updates self.l and self.r
  73. 73. #
  74. 74. def BlinkIcon(self, event):
  75. 75. self.SetIconBar(self.l,self.r)
  76. 76. self.l += 1
  77. 77. if self.l > 5:
  78. 78. self.l = 0
  79. 79. self.r += 1
  80. 80. if self.r > 5:
  81. 81. self.r = 0
  82. 82. ##
  83. 83. # \brief sets the icon bar and a message
  84. 84. #
  85. 85. def SetIconBar(self,l,r):
  86. 86. icon = self.IconBar.Get(l,r)
  87. 87. self.SetIcon(icon, "L:%d,R:%d"%(l,r))
  88. 88.
  89. 89. ##
  90. 90. # The task bar application
  91. 91. #
  92. 92. class TaskBarApp(wx.Frame):
  93. 93.
  94. 94. ##
  95. 95. # \brief the constructor
  96. 96. #
  97. 97. def __init__(self, parent, id, title):
  98. 98. wx.Frame.__init__(self, parent, -1, title, size = (1, 1),
  99. 99. style=wx.FRAME_NO_TASKBAR|wx.NO_FULL_REPAINT_ON_RESIZE)
  100. 100.
  101. 101. self.tbicon = MyTaskBarIcon(self)
  102. 102. self.tbicon.SetIconTimer()
  103. 103.
  104. 104. self.Show(True)
  105. 105.
  106. 106. ##
  107. 107. # The main application wx.App class
  108. 108. #
  109. 109. class MyApp(wx.App):
  110. 110. def OnInit(self):
  111. 111. frame = TaskBarApp(None, -1, ' ')
  112. 112. frame.Center(wx.BOTH)
  113. 113. frame.Show(False)
  114. 114. return True
  115. 115.
  116. 116. def main(argv=None):
  117. 117. if argv is None:
  118. 118. argv = sys.argv
  119. 119.
  120. 120. app = MyApp(0)
  121. 121. app.MainLoop()
  122. 122.
  123. 123. if __name__ == '__main__':
  124. 124. main()
Add Comment
Please, Sign In to add comment