为什么 wx.SingleChoiceDialog 没有正确子类化
我正在尝试对 wxpython SingleChoiceDialog 类进行子类化。 我有一个继承自 SingleChoiceDialog 的 TableChoiceDialog 类,添加了通用功能,并且我有 2 个子类用于添加更精细的功能。 基本上我是OOP'ing
在我的TableChoiceDialog类中我有一行调用超类的__init__
,即
class TableChoiceDialog(wx.SingleChoiceDialog):
def __init__(self, parent, message, caption, list, ...other args...):
wx.SingleChoiceDialog.__init__(self, parent, message, caption, list)
我遇到的问题是根据SingleChoiceDialog.__init__
docstring(和 wxPython API),SingleChoiceDialog 没有 self 参数作为其 __init__
方法的一部分。
__init__(Window parent, String message, String caption,
List choices=EmptyList, long style=CHOICEDLG_STYLE,
Point pos=DefaultPosition) -> SingleChoiceDialog
正如我上面所说,程序打印错误:
swig/python detected a memory leak of type 'wxSingleChoiceDialog *', no destructor found.
如果我取出 self 参数,系统会抱怨它期望一个 SingleChoiceDialog
对象作为第一个参数,这似乎表明它实际上想要一个参考自我。
当我取出父参数,留下 self (以及其他 3 个,我很确定没问题)时,系统抱怨说它只收到了 3 个参数,而它需要 4 个参数。我很确定我传递了 4 个参数。
所以。 我犯了什么明显的错误? 我是否完全误解了 python 处理对象的方式(因此也误解了 python)? 我是否误解了 OOP 的整体含义?
请帮忙。 提前致谢
I'm trying to subclass the wxpython SingleChoiceDialog class. I have a TableChoiceDialog class that inherits from SingleChoiceDialog adding generic functionality, and I have 2 sub classes for that add more refined functionality. Basically I'm O.O.P'ing
In my TableChoiceDialog class I have a line which calls the superclass's __init__
, i.e.
class TableChoiceDialog(wx.SingleChoiceDialog):
def __init__(self, parent, message, caption, list, ...other args...):
wx.SingleChoiceDialog.__init__(self, parent, message, caption, list)
The problem I'm having is that according to the SingleChoiceDialog.__init__
docstring (and the wxPython API), SingleChoiceDialog does not have the self argument as part of it's __init__
method.
__init__(Window parent, String message, String caption,
List choices=EmptyList, long style=CHOICEDLG_STYLE,
Point pos=DefaultPosition) -> SingleChoiceDialog
As I have it above, the program prints the error:
swig/python detected a memory leak of type 'wxSingleChoiceDialog *', no destructor found.
If I take out the self parameter the system complains that it was expecting a SingleChoiceDialog
object as a first argument, which seems to point to it actually wanting a reference to self.
When I take out the parent argument, leaving self (and the other 3 which I'm pretty sure are fine) the system complains that it only recieved 3 arguments, when it needed 4. I'm pretty certain I'm passing 4.
So. What blatantly obvious mistake have I made? Have I totally misunderstood how python handles objects (and hence pretty much misunderstood python)? Have I misunderstood OOP as a whole?
Please help. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
__init__
的调用似乎没问题(__init__
的第一个参数始终是self
)。wx
版本。 swig 的警告消息表明没有为wxSingleChoiceDialog
生成析构函数,请参阅 此内存泄漏讨论。该消息可能与 __init__ 调用无关。
__init__
seems alright (the first argument to__init__
is alwaysself
).wx
. The swig's warning message indicates that there is no desctructor was generated forwxSingleChoiceDialog
, see this memory leak discussion.The message may be unrelated to the
__init__
call.wxPython 中的一些对话框是不可子类化的,因为它们不是真正的类,而是用于显示对话框的平台 API 方法的包装器。 我知道
wx.MessageDialog
就是这种情况,wx.SingleChoiceDialog
也可能是这种情况。Some of the dialogs in wxPython are not subclassable because they are not real classes, but instead wrappers around the platform API method for displaying the dialog. I know this is the case for
wx.MessageDialog
, it might also be the case forwx.SingleChoiceDialog
.