Inherit the FrameClass

Hallo, I am a newbie on this board.

My Question.
The Idea is to inherit the FrameClass that i have build with wxFormBuilder.
Because i want to overlay the Event-Funktions with my own Funktions, so the original FrameClass is
untouched.
Has anyone an solution (pattern) for this.
I know that it is in first a python problem but i hope that i am not the first who want to do this.

Tanks for your answers,
and sorry for my terrible english.

Jörg

Hi Jörg,

I am not a user of wxFormBuilder, but I’m pretty sure you can inherit the FrameClass and override (not “overlay”) the event handlers. It is quite a usual programming pattern in Python and wxPython too.
Note that wx classes such as Window, Frame, Panel, etc. cannot be inherited more than two (so-called diamond inheritance).

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.

Hi komoto4g,

thanks for your answer.
There will be no diamond inheritance, i hope.

I solved my problem myself and with Google.

Hallo RichardT,

as said to komoto48g i have solved my Problem.

Thanks for the detailed description this has helped me a lot.
But I have adjusted this a little bit.

class MusicPlayerMainFrame(MusicPlayerMainFrameBase):
    def __init__(self, parent, tracks=None):
        Super().__init__(self, parent)

        # Code to initialise controls and bind event handlers would go here...

    # Definitions of event handler methods would go here...

Let’s see if I have several windows and frames, what happens then. 
If there are any important changes, I will inform you.