Hallo people,
I have posted this note in the chats, but eventually nobody is online. Here is the question:
Hallo people, anybody able to give help on the Bind function?
I am trying to build up sort of “strange” architecture
I have a “main” file where I define frames, for instance
Then I make a “Widget builder” which is supposed to take care of button construction, for instance
data for the buttons are stored in a separate module which contains a dictionary: keys are button names and values are named tuples with e.g. labels and handlers.
The builder gets called from the “main” like: button1 = gc.ButtonBuilder(self, “button 1”)
The builder itself is a function in a separate module: def ButtonBuilder(parent, buttonName):
From that “ButtonBuilder” fetching the data from the data container and building a button in the parent frame (other module) is pretty trivial
It would be anyway nice to build, always from the builder, a handler to the button that binds the button to the handler method located in the controller module
I have a controller called GuiController made like that:
GuiController(object):
def OnTest(self, event):
print “Hei I have come up to here!”
Now, given that in the builder I have imported GuiController and instantiated it as gcontrol, it is pretty straigthforward having a handler function parsed out from my dictionary:
handler = getattr(gcontrol, button_data.handler)
(button_data.handler is the reference to my namedtuple in the gui data dictionary)
The problem is that the sytax of Bind is (event, handler, source,…), where handler is a so called “PyObject”
This means that if I place there my handler, which is gcontrol.OnTest() it doesn’t work.
I must place there just “The name”: gcontrol.OnTest
The only non-elegant way I am using to do that is:
name = “controller.” + str(handler.name)
parent.Bind(wx.EVT_BUTTON, eval(name), _button)
I hate that eval. Do anybody know a better way to do that???
I am just learning here… Attached you find the four files, it’s just work in progress.
Thanks in advance!
testguicommons.py.html (5.77 KB)
testguicontroller.py.html (1.79 KB)
testGuiData.py.html (2.65 KB)
senderreceivertest.py.html (6.38 KB)