[wxPython] How to clean up member data in wxPython window? - please help

Hi all,
How can I delete wxPython's window attributes when window
is about to close.
For example: I have a Inner class:

    class Inner:
        def __init__(self):
            print 'Creating inner'

        def __del__(self):
            print 'Destroying inner'

and I create an instance of this class in __init__ def of my window:

    class MyWindow(wxDialog):
        def __init__(ble, ble...)
            self.Attr = Inner()

The __del__ method of my Inner class is never called after destroying
window.
It works OK in any class other then window.
How can I solve this problem? Please help.
Grzegorz Fura

Grzegorz Fura writes:

The __del__ method of my Inner class is never called after destroying
window.
It works OK in any class other then window.
How can I solve this problem? Please help.

In Python, an object's __del__ method is called only before the object is
actually destroyed--since you generally can't manually destroy Python
objects (if you could manually destroy objects, Bad Things could happen),
the only thing that causes an object to be destroyed is its being
garbage-collected. If you have any references to an object, it won't be
garbage-collected.

I have tried this and see no problem in my application.

The dialog is called like so (bound to a button press in MyFrame):

class Inner:
    def __init__(self):
        print "Constructing Inner"

    def __del__(self):
        print "Destroying Inner"

class MyDlg(wxDialog):
    def __init__(self, parent, ID):
        wxDialog.__init__(self, parent, ID, 'My Dialog')
        self.myInner = Inner()

<snip>

    def __del__(self):
        print "Destroying MyDlg"

<snip>

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                         wxDefaultPosition, wxSize(200, 150))

<snip>

    def evHEntryReg(self, event):
        dlg = MyDlg(self, -1)
        if dlg.ShowModal() == wxID_OK:
  # Do something...
        dlg.Destroy()

Try overriding the __del__ method of MyWindow to see if this is called. If
it isn't, then I can only guess that there is a residual reference to an
instance of MyWindow which is causing the problem.

···

-----Original Message-----
From: wxpython-users-admin@wxwindows.org
[mailto:wxpython-users-admin@wxwindows.org]On Behalf Of Grzegorz Fura
Sent: 14 July 2000 09:09
To: wxpython-users@wxwindows.org
Subject: [wxPython] How to clean up member data in wxPython
window? - please help

Hi all,
How can I delete wxPython's window attributes when window
is about to close.
For example: I have a Inner class:

    class Inner:
        def __init__(self):
            print 'Creating inner'

        def __del__(self):
            print 'Destroying inner'

and I create an instance of this class in __init__ def of my window:

    class MyWindow(wxDialog):
        def __init__(ble, ble...)
            self.Attr = Inner()

The __del__ method of my Inner class is never called after destroying
window.
It works OK in any class other then window.
How can I solve this problem? Please help.
Grzegorz Fura

_______________________________________________
wxPython-users mailing list wxPython-users@wxwindows.org
http://wxwindows.org/mailman/listinfo/wxpython-users