views:

159

answers:

2

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

A: 
  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.

J.F. Sebastian
A: 

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.

Frank Niessink