I do a very similar thing, except I use wxGlade instead of wxFormBuilder.
First, I use wxGlade to create a base class for a Form or Dialog. The base class would define all the controls and sizers of the Form or Dialog and specify their layout. I would then derive a new class from that base class and in the derived class I would do things like initialise the values in the controls, bind the required event handlers and then implement those handlers.
For example, if I was developing a music player application I would use wxGlade to create the main frame for the application. I would call the class MusicPlayerMainFrameBase and I would make wxGlade output its code to a file called MusicPlayerMainFrameBase.py
I would then create a new python module called MusicPlayerMainFrame.py and in that I would define a MusicPlayerMainFrame class, derived from the MusicPlayerMainFrameBase class.
The basic outline of the MusicPlayerMainFrame.py module would be like this:
import wx
from MusicPlayerMainFrameBase import MusicPlayerMainFrameBase
class MusicPlayerMainFrame(MusicPlayerMainFrameBase):
def __init__(self, parent, tracks=None):
MusicPlayerMainFrameBase.__init__(self, parent)
# Code to initialise controls and bind event handlers would go here...
# Definitions of event handler methods would go here...
The signature of the derived class’s __init__()
method may need to be modified on a case-by-case basis if any non-default values need to be passed to the ultimate base class (wx.Form or wx.Dialog). However, in most cases I just pass the parent parameter.