Hi again. I have a main.py in which I have my MainFrame, and a separate MainMenu.py in which I subclass wx.MenuBar. My menu has lots of items, each requiring a handler, of course. Presently I’ve got things structured so the handlers are methods of MainFrame and defined in main.py, but there are so many I’m thinking of putting the handlers in another file (in general, I don’t like large code files) but if there’s a “standard practice,” I’d like to follow it: A) is it “customary” to have menu item handlers methods of the menu bar object, the parent frame object, the app object, or what? and B) is it “customary,” regardless of number, to define the handlers in the file in which their “owning” class is defined, or is it “programmer’s choice”? Thanks as always!
DG
···
–
Note my address change and please update your address books. Thanks!
Hi again. I have a main.py in which I have my MainFrame, and a separate
MainMenu.py in which I subclass wx.MenuBar. My menu has _lots_ of
items, each requiring a handler, of course. Presently I've got things
structured so the handlers are methods of MainFrame and defined in
main.py, but there are so many I'm thinking of putting the handlers in
another file (in general, I don't like large code files) but if there's
a "standard practice," I'd like to follow it: A) is it "customary" to
have menu item handlers methods of the menu bar object, the parent frame
object, the app object, or what?
Usually the frame. In fact I usually do not subclass wx.MenuBar because I consider it to be part of the frame. So the frame code creates and manages the menubar and it also has the handlers for the menu events.
and B) is it "customary," regardless of
number, to define the handlers in the file in which their "owning" class
is defined, or is it "programmer's choice"?
Customary, yes. But ultimately it is always programmer's choice.
BTW, this sounds like another good use for pubsub. You can have your menu events simple publish a message indicating that the menu item has been selected. And then there can be one or more subscribers to that message located in any part of your program that catches the message and does something in response.
I’ve sub-classed wx.MenuBar to a MainMenuBar class to add boiler-plate code–inclusion, bindings, handler declarations, etc.–for “common” menu items–New, Open, Save, Undo/Redo, Cut/Copy/Paste, Preferences, Window selection, About, etc.–so that I neither have to recreate nor cut and paste this each time I wan to start a new app. I plan on releasing it into the wild when I’ve used it for a while and thus am reasonably confident in it.
Yes, I was convinced about pubsub immediately–I’ve already downloaded, installed, and imported.
DG
···
On Fri, Mar 16, 2012 at 10:45 AM, Robin Dunn robin@alldunn.com wrote:
On 3/16/12 10:16 AM, David Goldsmith wrote:
Hi again. I have a main.py in which I have my MainFrame, and a separate
MainMenu.py in which I subclass wx.MenuBar. My menu has lots of
items, each requiring a handler, of course. Presently I’ve got things
structured so the handlers are methods of MainFrame and defined in
main.py, but there are so many I’m thinking of putting the handlers in
another file (in general, I don’t like large code files) but if there’s
a “standard practice,” I’d like to follow it: A) is it “customary” to
have menu item handlers methods of the menu bar object, the parent frame
object, the app object, or what?
Usually the frame. In fact I usually do not subclass wx.MenuBar because I consider it to be part of the frame. So the frame code creates and manages the menubar and it also has the handlers for the menu events.
and B) is it “customary,” regardless of
number, to define the handlers in the file in which their “owning” class
is defined, or is it “programmer’s choice”?
Customary, yes. But ultimately it is always programmer’s choice.
BTW, this sounds like another good use for pubsub. You can have your menu events simple publish a message indicating that the menu item has been selected. And then there can be one or more subscribers to that message located in any part of your program that catches the message and does something in response.
Purely a personal choice that I like is to have all the code to do with
a given object/class/logical group in a single file/package of files
depending on the size. I find that this makes both maintenance and code
reuse easier. The "tricks" that I have found worthwhile in the case of
menus is for each such group/class to have a fixed name function, such
as AddMenu, that is passed the parent & menu bar as a parameter and adds
its own items and bindings.
Gadget/Steve
···
On 16/03/2012 5:16 PM, David Goldsmith wrote:
Hi again. I have a main.py in which I have my MainFrame, and a
separate MainMenu.py in which I subclass wx.MenuBar. My menu has
_lots_ of items, each requiring a handler, of course. Presently I've
got things structured so the handlers are methods of MainFrame and
defined in main.py, but there are so many I'm thinking of putting the
handlers in another file (in general, I don't like large code files)
but if there's a "standard practice," I'd like to follow it: A) is it
"customary" to have menu item handlers methods of the menu bar object,
the parent frame object, the app object, or what? and B) is it
"customary," regardless of number, to define the handlers in the file
in which their "owning" class is defined, or is it "programmer's
choice"? Thanks as always!
DG
--
Note my address change and please update your address books. Thanks!
Steve, do you still use this and could you post an example?
···
On Friday, March 16, 2012 4:40:00 PM UTC-4, Gadget Steve wrote:
On 16/03/2012 5:16 PM, David Goldsmith wrote:
Hi again. I have a main.py in which I have my MainFrame, and a
separate MainMenu.py in which I subclass wx.MenuBar. My menu has lots of items, each requiring a handler, of course. Presently I’ve
got things structured so the handlers are methods of MainFrame and
defined in main.py, but there are so many I’m thinking of putting the
handlers in another file (in general, I don’t like large code files)
but if there’s a “standard practice,” I’d like to follow it: A) is it
“customary” to have menu item handlers methods of the menu bar object,
the parent frame object, the app object, or what? and B) is it
“customary,” regardless of number, to define the handlers in the file
in which their “owning” class is defined, or is it “programmer’s
choice”? Thanks as always!
DG
–
Note my address change and please update your address books. Thanks!
–
To unsubscribe, send email to
or visit http://groups.google.com/group/wxPython-users?hl=en
Purely a personal choice that I like is to have all the code to do with
a given object/class/logical group in a single file/package of files
depending on the size. I find that this makes both maintenance and code
reuse easier. The “tricks” that I have found worthwhile in the case of
menus is for each such group/class to have a fixed name function, such
as AddMenu, that is passed the parent & menu bar as a parameter and adds
its own items and bindings.
Gadget/Steve
On Monday, July 9, 2012 1:05:53 AM UTC-4, Gadget Steve wrote:
On 09/07/2012 2:41 AM, DevPlayer wrote:
Yes I do - I will try to extract/abstract a simple example and post it to the group if you think it would be useful.
Gadget/Steve
Still a little rough in places and not a 100% tested but I believe
that the attached is a good starting point. Executing standalone
does a number of tests and gives a rough and ready example.
Any comments are welcomed.
Gadget/Steve