Please Hlp with msg: "The C++ part of the StaticText object has been deleted"

Robin Dunn robin at alldunn.com
Sun Sep 26 14:19:21 EDT 2004


StvB wrote:
> Hi,
> I have  a wxPython app which dump errors when I close it ( in
>  the debug output at bottom of Komodo, when I close my app.  )
> 
> Where I got the code for my GUI:
>    Straight from the wxProject.py file which comes with the samples:
>     ----  
> C:\Python23\Lib\site-packages\wx\samples\wxProject\wxProject.py ----
> 
> It basically consists of  a splitterwindow, and  I have a wxPanel
> on the left side, which is set to a vertical box sizer.  I used
> the Add function of the sizer to simply add a wxStaticText control
> at the very top.
> The bottom half of this same left panel is a tree.
> ( u can ignore the *right* side of the splitter.. nothing exciting is
> happening.. it's the same as in the wxProject.py sample ,
> just a multilined edit contrl)
> 
> Anyway, when I click on a node of this tree, I change the text of the
> static text control at top, to the text of the node. It actually works,
> but when I close the app I get this:
> ----------------------------------------------
> The stack trace:
> E:\MyProjects1\python\backup
> Traceback (most recent call last):
>   File "E:\MyProjects1\python\backup\wxProject.py", line 294, in 
> OnNodeChanged
>     self.testLab.SetLabel('test')
>   File "C:\Python23\Lib\site-packages\wx\_core.py", line 10617, in 
> __getattr__
>     raise PyDeadObjectError(self.attrStr % self._name)
> wx._core.PyDeadObjectError: The C++ part of the StaticText object has been 
> deleted, attribute access no longer allowed.
> ---------------------------------------------


When the treectrl is destroyed it removes each of its items, but when 
the item that is selected is removed the tree will select another item 
which causes the selection event to be sent causing your handler to try 
to call SetLabel.  If the statictext has already been destroyed at that 
time then the Python proxy will raise the exception you reported above. 
To avoid it you can check if the tree is being destroyed by calling its 
IsBeingDeleted method and if it returns True just return immediately 
from your event handler without doing anything.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!



More information about the Python-list mailing list