dynamic menu with bad callback function
oyster
lepto.python at gmail.com
Sun Jun 4 04:39:49 PDT 2006
I want to create a dyanmic menu accoring to varialbe cfg(in fact I read this
from a user-defined file)
cfg=3D[['a', 'this is a'],['b', 'this is b']]
where cfg[i][0] is the text of menu, and cfg[i][1] is passed to the callback
function
but now, the display are always 'this is b'. how to correct this? thanx
[code]
#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] =3D wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
# Menu Bar
self.frame_1_menubar =3D wx.MenuBar()
self.SetMenuBar(self.frame_1_menubar)
self.mnFile =3D wx.Menu()
cfg=3D[['a', 'this is a'],['b', 'this is b']]
for i in cfg:
exec 'self.IDmnFile%s =3D%d' % (i[0],wx.NewId() ) in locals()
self.mnFile.Append(eval('self.IDmnFile%s' % i[0]), i[0], i[1])
pass
self.frame_1_menubar.Append(self.mnFile, "File")
# Menu Bar end
self.__set_properties()
self.__do_layout()
for i in cfg:
wx.EVT_MENU(self,eval('self.IDmnFile%s' % i[0]) , lambda e:self.event
(i[1]))
def __set_properties(self):
self.SetTitle("frame_1")
def __do_layout(self):
sizer_1 =3D wx.BoxSizer(wx.VERTICAL)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
def event(self, event):
print 'event=3D',event
class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame_1 =3D MyFrame(None, -1, "")
self.SetTopWindow(frame_1)
frame_1.Show()
return 1
if __name__ =3D=3D "__main__":
app =3D MyApp(0)
app.MainLoop()
[/code]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200606=
04/0286c797/attachment.htm
More information about the wxpython-users
mailing list