1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
!/usr/bin/env python
#coding=utf-8
import wx
class frame_emainfo(wx.Frame):
"""Frame emainfo"""
def __init__(self, *args, **kwds):
"""Création de la frame"""
kwds["style"] = wx.DEFAULT_FRAME_STYLE^wx.MINIMIZE
wx.Frame.__init__(self, *args, **kwds)
self.nLignePopup=4 # Nombre de lignes à afficher lors du popup
self.__create_wx()
def __create_wx(self):
"""Création des objet WX"""
self.popupmenu = wx.Menu() # création du Pop up menu
for n,compte in enumerate(range(self.nLignePopup)) :
text=str(n) # Remplissage de chaque ligne avec le texte du n°
item=self.popupmenu.Append(-1, text) # Création des item pour bindings
print item
self.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item)# Binding du menu
self.tbicon=wx.TaskBarIcon()
icone=wx.Icon("emainfo.ico", wx.BITMAP_TYPE_ICO) # ==> A lier à une icone
self.tbicon.SetIcon(icone,"icone")
wx.EVT_TASKBAR_RIGHT_DOWN(self.tbicon, self.OnShowPopup)
def OnShowPopup(self, event):
"""Affichage du menu contextuel"""
print event
self.tbicon.PopupMenu(self.popupmenu)
def OnPopupItemSelected(self, event):
"""Sélection d'un item"""
item = self.popupmenu.FindItemById(event.GetId())
text = item.GetText()
wx.MessageBox("Item séléctionné :" + text)
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = frame_emainfo(None, -1, "")
app.SetTopWindow(frame_1)
app.MainLoop() |
Partager