Mark Erbaugh
2007-12-02 22:15:27 UTC
I'm trying to develop applications along the lines of
model-view-controller design.
I think the frame class is the view portion. However, the event handling
routines are part of the controller. How do people separate them?
What I've been doing is writing "stub" event handlers for each event
that basically just pass the event off to a controller object, if one
exists.
# in view
def onClick(self, event):
if self.controller:
self.controller.onClick(self, event)
# in controller
def onClick(self, view, event):
# here view gives the controller access to the view object
# (GUI frame instance)
Is there a better way?
Also, my concept of the controller is that it is independent of the
mechanism used to provide the GUI, so I don't want to import wx into it.
That means that sometimes end up writing more code in the GUI. For
example, if the controller needs to display a dialog box, I have a
method in the GUI frame to do that. The controller can then access the
dialog using this method on the GUI frame. It gets the GUI frame's
instance as the first parameter of its event handling code.
Thanks,
Mark
model-view-controller design.
I think the frame class is the view portion. However, the event handling
routines are part of the controller. How do people separate them?
What I've been doing is writing "stub" event handlers for each event
that basically just pass the event off to a controller object, if one
exists.
# in view
def onClick(self, event):
if self.controller:
self.controller.onClick(self, event)
# in controller
def onClick(self, view, event):
# here view gives the controller access to the view object
# (GUI frame instance)
Is there a better way?
Also, my concept of the controller is that it is independent of the
mechanism used to provide the GUI, so I don't want to import wx into it.
That means that sometimes end up writing more code in the GUI. For
example, if the controller needs to display a dialog box, I have a
method in the GUI frame to do that. The controller can then access the
dialog using this method on the GUI frame. It gets the GUI frame's
instance as the first parameter of its event handling code.
Thanks,
Mark