为什么 wx.SingleChoiceDialog 没有正确子类化

发布于 2024-07-15 21:42:14 字数 1222 浏览 4 评论 0原文

我正在尝试对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光是把杀猪刀 2024-07-22 21:42:14
  1. __init__ 的调用似乎没问题(__init__ 的第一个参数始终是 self)。
  2. 您可能有错误的 wx 版本。 swig 的警告消息表明没有为 wxSingleChoiceDialog 生成析构函数,请参阅 此内存泄漏讨论

该消息可能与 __init__ 调用无关。

  1. The call to __init__ seems alright (the first argument to __init__ is always self).
  2. You might have a wrong build of wx. The swig's warning message indicates that there is no desctructor was generated for wxSingleChoiceDialog, see this memory leak discussion.

The message may be unrelated to the __init__ call.

ゞ花落谁相伴 2024-07-22 21:42:14

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 for wx.SingleChoiceDialog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文