チュートリアルに従ってwx.Dialogをサブクラス化するwxpythonプログラムがあります。ダイアログ内で、パネルとサイザーを作成します。
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)
ブロックコメントは、私が達成しようとしている機能を説明し、基本的にこれをベースとして使用して、より複雑なダイアログを動的に生成します。それを行うために私は試しました:
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))
InitUIメソッドを介してサブクラスを呼び出して拡張できるようにしますが、親クラスのInitUIのUI生成を上書きすることはできません。私ができないことは、パネルとおそらくサイザー属性を親から子に渡すことです。
panel=StretchDialog.panelとpanel=StretchDialog.InitUI.panelのさまざまなバリエーションを試してみました。
親をサブクラス化することで、wxpythonでこれを実現することは可能ですか?もしそうなら、パネルにアクセスしようとしたときに名前空間をどのように台無しにしていますか?