[Tutor] Tutor Digest, Vol 29, Issue 68

János Juhász janos.juhasz at VELUX.com
Thu Jul 27 12:18:33 CEST 2006


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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060727/6dbb64d8/attachment.html 


More information about the Tutor mailing list