Hi,
I am a newbie at GUI building using wxPython and I'd appreciate advice from more experienced programmers.
If you place a control in a panel and the panel in a frame, you can use various bindings to access the events of the control from (at least) three places: within the code of the control, within the code of the panel, and within the code of the frame. My question is 'where is the most appropriate place for code to deal with events arising from the control?' Do you tend to consolidate event capturing code in one location?
First a warning... I'm not all that experienced... anyway... the way I see it is a problem of availability...
if the event involves only the control (widget) you might wanna do it at control (widget) level (inheritance)
if the event involves the control (widget) and some of its siblings... do it at parent level (panel)
if the event involves controls (widgets) from other panels... it might be a good ideea to implemnt the event handling at the closest common relative (might be the frame)
···
On Tue, 25 May 2004 06:05:09 -0600, gyrof <gyrof@yahoo.com> wrote:
Hi,
I am a newbie at GUI building using wxPython and I'd appreciate advice from more experienced programmers.
If you place a control in a panel and the panel in a frame, you can use various bindings to access the events of the control from (at least) three places: within the code of the control, within the code of the panel, and within the code of the frame. My question is 'where is the most appropriate place for code to deal with events arising from the control?' Do you tend to consolidate event capturing code in one location?
Hi,
I am a newbie at GUI building using wxPython and I'd appreciate advice from more experienced programmers.
If you place a control in a panel and the panel in a frame, you can use various bindings to access the events of the control from (at least) three places: within the code of the control, within the code of the panel, and within the code of the frame. My question is 'where is the most appropriate place for code to deal with events arising from the control?' Do you tend to consolidate event capturing code in one location?
Thanks for your advice.
As Peter said, it really depends on the needs of the UI and App for that particular control and event type. I have a general rule of thumb that I use that goes along with what Peter said, but takes it one step further: If the event is used to maipulate the UI then put the handler wherever it makes the most sense for what it needs to interact with, but if it is used to manipulate the app (data model, "business logic", etc.) then I delegate the event to the main controller class for the application or whatever. The delegation can happen simply by calling a method from the event handler method, or in a more disconnected fashion using pubsub.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!