I have a wxpython program where I subclass wx.Dialog as per a tutorial. Within the dialog I create a panel and a sizer.
class StretchDialog(wx.Dialog):
'''A generic image processing dialogue which handles data IO and user interface.
This is extended for individual stretches to allow for the necessary parameters
to be defined.'''
def __init__(self, *args, **kwargs):
super(StretchDialog, self).__init__(*args, **kwargs)
self.InitUI()
self.SetSize((600,700))
def InitUI(self):
panel = wx.Panel(self)
sizer = wx.GridBagSizer(10,5)
The block comment describes what functionality I am trying to achieve, essentially dynamically generating more complex dialogs using this as the base. To do that I have tried:
class LinearStretchSubClass(StretchDialog):
'''This class subclasses Stretch Dialog and extends it by adding
the necessary UI elements for a linear stretch'''
def InitUI(self):
'''Inherits all of the UI items from StretchDialog.InitUI if called as a method'''
testtext = wx.StaticText(panel, label="This is a test")
sizer.Add(testtext, pos=(10,3))
I call the subclass via the InitUI method to be able to extend, but not overwrite the UI generation in the parent class’ InitUI. What I am not able to do is pass the panel and presumably sizer attributes from the parent to the child.
I tried many variations of panel = StretchDialog.panel and panel = StretchDialog.InitUI.panel to no end.
Is it possible to achieve this in wxpython by subclassing a parent? If so, how am I messing up the namespace when trying to access panel?
your InitUI in the child class causes InitUI not to be called in StretchDialog
you can do it like this
Then in your child class