Organization: frames, menus, panels, modules ?

I'm struggling with organizational issues. Particularly as regards the wxPython items and where to put them in the Python modules. (Modules provide a degree of isolation that is somewhat a new experience for a guy who grew up on .include asm directives).

Here's a sketch of my application:

MyApp Panels Lists
MyFrame -- Menus -- Grids -- Database
MainLoop Controls

There is one MyApp and one MyFrame, but many Panels and (I would like to have multiple Menus but that appears to be discouraged) the Menu will need to be massively reworked depending on what panel is showing at a given moment.

I put all the panels, menus, grids and such each in their own module which is great from a code editing standpoint, but it gets really spagetti-like with the interaction that must go on between the Frame, Menus and Panels.

In particular ... It would be nice to keep all the menu code in one module, but the frame must do the event bindings and it must know what IDs have been assigned to the various menu items. So, among other things, it's beginning to look like a whole platoon of global constants that need to be imported and then line after line of tearing down and rebinding menu items each time the panel changes.

I don't intend this as a rant. Is there some clever/accepted solution to all this?

Any help (tutoring, handholding) appreciated.

Michael

Michael Hipp wrote:

There is one MyApp and one MyFrame, but many Panels and (I would like to have multiple Menus but that appears to be discouraged) the Menu will need to be massively reworked depending on what panel is showing at a given moment.

You should be able to call the frame's SetMenuBar with a new menubar as needed.

I put all the panels, menus, grids and such each in their own module which is great from a code editing standpoint, but it gets really spagetti-like with the interaction that must go on between the Frame, Menus and Panels.

In particular ... It would be nice to keep all the menu code in one module, but the frame must do the event bindings and it must know what IDs have been assigned to the various menu items. So, among other things, it's beginning to look like a whole platoon of global constants that need to be imported and then line after line of tearing down and rebinding menu items each time the panel changes.

I would have a function in the frame that took the menubar to use, and a list of (ID, handler) and then the panel can just call that function and the frame will tear-down the old event bindings, attach the menubar and Bind the new handlers.

Another approach is to have the frame catch *all* EVT_MENU events with a single handler (by binding it with id=-1) and in that handler just resend the event to the current panel. Then the panel can just Bind all the handlers that it needs to itself. You just need to be careful that you don't get into an endless recursion if the panel doesn't handle the event because the frame will end up getting the event again. A simple guard condition should take care of that.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Michael Hipp wrote:

There is one MyApp and one MyFrame, but many Panels and (I would like to have multiple Menus but that appears to be discouraged) the Menu will need to be massively reworked depending on what panel is showing at a given moment.

You should be able to call the frame's SetMenuBar with a new menubar as needed.

Thank you. The docs say this about SetMenuBar ...

"Note that on some platforms, it is not possible to call this function twice for the same frame object."

So I took that to mean it is nonportable and should therefore be avoided. Any idea which platforms don't allow this?

Thanks,
Michael

Michael Hipp wrote:

Robin Dunn wrote:

Michael Hipp wrote:

There is one MyApp and one MyFrame, but many Panels and (I would like to have multiple Menus but that appears to be discouraged) the Menu will need to be massively reworked depending on what panel is showing at a given moment.

You should be able to call the frame's SetMenuBar with a new menubar as needed.

Thank you. The docs say this about SetMenuBar ...

"Note that on some platforms, it is not possible to call this function twice for the same frame object."

So I took that to mean it is nonportable and should therefore be avoided. Any idea which platforms don't allow this?

I'm not completely sure, but I think that all of the big 3 do.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!