backup_cl_taskbaricon.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #! /usr/bin/env python
  2. #-*- coding: utf-8 -*-
  3. # Classe permettant l'affichage d'une icone dans la barre des taches
  4. # avec menu
  5. # avec choix de l'icone ou choix d'une grandeur à monitorer
  6. import wx
  7. import string
  8. class Menu_item:
  9. def __init__(self, name, action, type_item="entry"):
  10. self.name=name
  11. self.action=action
  12. self.type_item=type_item
  13. self.icon=None
  14. class Tray(wx.TaskBarIcon):
  15. """ Classe pour l'affichage de l'icone et des menus
  16. dans la barre des taches. """
  17. #Entrées du menu
  18. TBMENU_SET_POWERSAVE = wx.NewId()
  19. TBMENU_SET_ONDEMAND = wx.NewId()
  20. TBMENU_PARAM = wx.NewId()
  21. TBMENU_CLOSE = wx.NewId()
  22. TBMENU_CREATE = []
  23. def __init__(self, app):
  24. wx.TaskBarIcon.__init__(self)
  25. self.app = app
  26. self.menu_tmp = {}
  27. #liaisons Boutons-Méthodes (actions en dur)
  28. self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.OnTaskBarActivate)
  29. def MenuAddItem(self, nom, action):
  30. """ Add an item to the menu and link it to corresponding method """
  31. self.menu_tmp[nom]=wx.NewId()
  32. self.Bind(wx.EVT_MENU, action, id=self.menu_tmp[nom])
  33. def CreatePopupMenu(self):
  34. """ Method called when we need to display the menu """
  35. menu = wx.Menu()
  36. for nom,action in self.menu_tmp.items():
  37. menu.Append(action, nom)
  38. menu.AppendSeparator()
  39. return menu
  40. def ChangeIcon(self, imgpath):
  41. """ Change taskbar icon """
  42. img = wx.Image(imgpath,wx.BITMAP_TYPE_PNG)
  43. bmp = img.ConvertToBitmap()
  44. # bmp.SetMask(wx.Mask(bmp, wx.Colour().Alpha()))
  45. icon = wx.IconFromBitmap(img.ConvertToBitmap())
  46. icon = wx.EmptyIcon()
  47. icon.CopyFromBitmap(bmp)
  48. self.SetIcon(icon, "pycpufreq")
  49. def IconMonitor(self, l=2, r=4):
  50. l_off=[128,0,0] # couleurs
  51. l_on=[255,0,0]
  52. r_off=[0,128,0]
  53. r_on=[0,255,0]
  54. s_line = "\xff\xff\xff"+"\0"*45
  55. s_border = "\xff\xff\xff\0\0\0"
  56. s_point = "\0"*3
  57. sl_off = string.join(map(chr,l_off),'')*6
  58. sl_on = string.join(map(chr,l_on),'')*6
  59. sr_off = string.join(map(chr,r_off),'')*6
  60. sr_on = string.join(map(chr,r_on),'')*6
  61. s=""+s_line
  62. for i in range(5):
  63. if i<(5-l):
  64. sl = sl_off
  65. else:
  66. sl = sl_on
  67. if i<(5-r):
  68. sr = sr_off
  69. else:
  70. sr = sr_on
  71. s+=s_border+sl+s_point+sr+s_point
  72. s+=s_border+sl+s_point+sr+s_point
  73. s+=s_line
  74. image = wx.EmptyImage(16,16)
  75. image.SetData(s)
  76. bmp = image.ConvertToBitmap()
  77. bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white
  78. icon = wx.EmptyIcon()
  79. icon.CopyFromBitmap(bmp)
  80. self.SetIcon(icon, "")