Reputation: 2737
My main wxPython application wx.Frame is presently full of buttons and text fields as well as the main application display area. All of the event handlers and UI code is contained in the MainFrame class which passes commands to a Control class.
I would like to move some of these controls from the MainFrame to a new SecondaryFrame that can be hidden. I create an instance of SecondaryFrame and then use a menu item to Show and Hide it.
I seem to have a couple of choices for implementation:
Is seems like all of these options with require a significant refactoring of my code. Am I missing a more obvious way to move already functional controls to a new frame?
Upvotes: 1
Views: 216
Reputation: 33071
Each frame will need to have its own widgets. If you want both frames to have the same controls for some reason, then I would create a base class frame and have the other two inherit from it.
The handler code itself could be kept in a controller module. Then you would import the controller and do something like this:
mySecondaryFramesBtn.Bind(wx.EVT_BUTTON, controller.btnHandler)
That way you can bind the button in the first frame and the second frame to the same handler, so to speak.
You might also look into the idea of model-view-controller. You can read more about it at the following links:
Upvotes: 1