#! /usr/bin/env python #-*- coding: utf-8 -*- # Classe permettant l'affichage d'une icone dans la barre des taches # avec menu # avec choix de l'icone ou choix d'une grandeur à monitorer import wx import string class Menu_item: def __init__(self, name, action, type_item="entry"): self.name=name self.action=action self.type_item=type_item self.icon=None class Tray(wx.TaskBarIcon): """ Classe pour l'affichage de l'icone et des menus dans la barre des taches. """ #Entrées du menu TBMENU_SET_POWERSAVE = wx.NewId() TBMENU_SET_ONDEMAND = wx.NewId() TBMENU_PARAM = wx.NewId() TBMENU_CLOSE = wx.NewId() TBMENU_CREATE = [] def __init__(self, app): wx.TaskBarIcon.__init__(self) self.app = app self.menu_tmp = {} #liaisons Boutons-Méthodes (actions en dur) self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.OnTaskBarActivate) def MenuAddItem(self, nom, action): """ Add an item to the menu and link it to corresponding method """ self.menu_tmp[nom]=wx.NewId() self.Bind(wx.EVT_MENU, action, id=self.menu_tmp[nom]) def CreatePopupMenu(self): """ Method called when we need to display the menu """ menu = wx.Menu() for nom,action in self.menu_tmp.items(): menu.Append(action, nom) menu.AppendSeparator() return menu def ChangeIcon(self, imgpath): """ Change taskbar icon """ img = wx.Image(imgpath,wx.BITMAP_TYPE_PNG) bmp = img.ConvertToBitmap() # bmp.SetMask(wx.Mask(bmp, wx.Colour().Alpha())) icon = wx.IconFromBitmap(img.ConvertToBitmap()) icon = wx.EmptyIcon() icon.CopyFromBitmap(bmp) self.SetIcon(icon, "pycpufreq") def IconMonitor(self, l=2, r=4): l_off=[128,0,0] # couleurs l_on=[255,0,0] r_off=[0,128,0] r_on=[0,255,0] s_line = "\xff\xff\xff"+"\0"*45 s_border = "\xff\xff\xff\0\0\0" s_point = "\0"*3 sl_off = string.join(map(chr,l_off),'')*6 sl_on = string.join(map(chr,l_on),'')*6 sr_off = string.join(map(chr,r_off),'')*6 sr_on = string.join(map(chr,r_on),'')*6 s=""+s_line for i in range(5): if i<(5-l): sl = sl_off else: sl = sl_on if i<(5-r): sr = sr_off else: sr = sr_on s+=s_border+sl+s_point+sr+s_point s+=s_border+sl+s_point+sr+s_point s+=s_line image = wx.EmptyImage(16,16) image.SetData(s) bmp = image.ConvertToBitmap() bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white icon = wx.EmptyIcon() icon.CopyFromBitmap(bmp) self.SetIcon(icon, "")