Dear Alan,
> > It works now from Python prompt. I just wanted to put this
> > functionality
> > into a small wxpython application and building up the menus like
> > pythoncard.
> And Ok with this I think, but....
> Are you actually using PythonCard or are you using wxPython directly?
wxPython directly.
> > So, when there was a functionname like OnMenuShowAssetNumber,
> > I would append a new menuitem with ShowAssetNumber.
> OK, But I still don't see why you need getattr.
> Its your code, you know what the functions are, you can build
> the menu directly. Why use getattr?
> Alan G.
It just tried to do it another way.
There is a file for wx, and another for visio, they aren't joined together.
wx is filled up based on the functionnames of the other.
class ShellFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title='PyCrustVisio'):
...
self.FillUpMenu()
def FillUpMenu(self):
MenuItems = [item for item in dir(visio) if item.startswith('OnMenu')]
for FunctionName in MenuItems:
menuID = wx.NewId()
menuText = FunctionName[6:]
self.menu.Append(menuID, menuText, menuText)
self.Bind(wx.EVT_MENU, getattr(visio, FunctionName), id=menuID)
So I can write it with this way:
self.Bind(wx.EVT_MENU, getattr(visio, FunctionName), id=menuID)
Every function in the visio module starting with 'OnMenu' will be appeared in the application menu.
Probably its a bad habit, but it is just for trial.
Yours sincerely,
______________________________
János Juhász
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor