hmm, the taskbarmenu is not working at all with self.Bind....
I made an example (see myCode), the event is working but not in the
subMenu...
tempDict['SubMenu'] = {'subMenu1': 's1', 'subMenu2': 's2', 'subMenu3': 's3'}
myCode... (copy, paste and run)
----------------------------------------------------------------------------
import wx
import types
from wx.lib.embeddedimage import PyEmbeddedImage
class myFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, '')
self.loadMenuSetup()
self.taskbarMenu = self.initMenu()
icon = self.getImage()
self.taskbar = wx.TaskBarIcon()
self.taskbar.SetIcon(icon, '')
self.taskbar.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.onTaskBarMenu)
def getImage(self):
t = PyEmbeddedImage(
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAWNJ"
"REFUOI3Fk7FOlkEQRc/sLgVBbbU18Q2gpPAVbLSwtTE2dj6BiVYSEh5CGh+HEixoqRAM+829"
"Frsf+YnVHwsn2ewUu+feO8nAP1a8+vj9w+HL/a9Xt+zZgIQlUollZOFMZONMUuLJTv91dnb5"
"6cfRm5N2cLh/vLP7qDzd3Up47/p2OQZO2k2n3Fxdb239d6cANKf5/PbF1oB3X34yABYAd0ti"
"wDIpEEYyKZGLx7G4S/P82WNSOQDYAEQJwsYlcJhQUEoQUYhIopqqQlvGey0TsJIK4AgIqAYF"
"SKYaSlRaQIbJMhwrNSNoEIkA+wEoApxGAQ6gBFV1ANYIazMYMZoNkFrQJOThUvOJNB0svd87"
"CMA2EYE3QJRCBdKmxHC89GVGmFkqjE8zygNHgIAagafyerfVCkDMw8bHtep9M2cwRdrl+cXp"
"+2/9tTJRisxEEtk7ksYOKMcwPfZkaPr0L5X/Un8Ay9zpBmk1I4QAAAAASUVORK5CYII=")
return t.GetIcon()
def loadMenuSetup(self):
self.popM =
tempDict = {}
tempDict['Test1'] = 'n1'
tempDict['Test2'] = 'n2'
tempDict['Test3'] = 'n3'
self.popM.append(tempDict)
tempDict = {}
tempDict['SubMenu'] = {'subMenu1': 's1',
'subMenu2': 's2',
'subMenu3': 's3'}
self.popM.append(tempDict)
def onTaskBarMenu(self, event):
self.taskbar.PopupMenu(self.taskbarMenu)
def initMenu(self):
taskbarMenu = wx.Menu()
for menuList in self.popM:
self.createMenu(menuList, taskbarMenu)
taskbarMenu.AppendSeparator()
newid = wx.NewId()
menuItem = wx.MenuItem(taskbarMenu, newid, 'Exit', '',
wx.ITEM_NORMAL, None)
taskbarMenu.AppendItem(menuItem)
taskbarMenu.Bind(wx.EVT_MENU, self.onExit, id=newid)
return taskbarMenu
def createMenu(self, menuList, menu):
for key in menuList:
if type(menuList[key]) == types.DictType:
newMenu = wx.Menu()
self.createMenu(menuList[key], newMenu)
menu.AppendSubMenu(newMenu, key)
else:
newid = wx.NewId()
menuItem = wx.MenuItem(menu, newid, key, '', wx.ITEM_NORMAL,
None)
menu.AppendItem(menuItem)
menu.Bind(wx.EVT_MENU, self.onRun, id=newid)
def onRun(self, event):
print '...'
key = event.GetEventObject().GetLabel(event.GetId())
print key
def onExit(self, event):
self.Destroy()
class myApp(wx.App):
def OnInit(self):
self.main = myFrame(None)
self.main.Hide()
return True
def main():
application = myApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
----------------------------------------------------------------------------
Tnx
Holmis
"Robin Dunn" wrote in message news:4D82AD48.4020908@alldunn.com...
On 3/17/11 4:04 PM, Tim Roberts wrote:
I think you meant:
self.Bind(wx.EVT_MENU, self.onRun, menuItem, id=newid)
You want the event bound to the window, but it needs to be for this
specific menuItem.
Using both menuItem and id=newid is redundant in this case. Using just
one or the other is fine.
--
Robin Dunn
Software Craftsman
http://wxPython.org
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en