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

Discussion in 'Python' started by python newbie, Sep 26, 2004.

  1. 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.
    ---------------------------------------------


    Here's how I add the wxStaticBox: ------------------------
    # ok, first, the code below is actually in this __init__ function
    class main_window(wxFrame):
    def __init__(self, parent, id, title):
    wxFrame.__init__(self, parent, -1, title, size = (650, 500),
    style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)

    # first the left panel
    # -------------------
    self.MyLeftPanel = wxPanel(splitter,10004) #<--a random number I used
    #
    didn't want to use -1
    self.MyLeftPanel.SetDimensions(0, 0, 100, 220)
    self.leftSizer=wxBoxSizer(wxVERTICAL) # the sizer is born
    self.MyLeftPanel.SetSizer(self.leftSizer)
    self.MyLeftPanel.SetAutoLayout(true)

    # then add the static text
    # -------------------
    self.aNewID=wxNewId()
    self.testLabel = wxStaticText(self.MyLeftPanel,self.aNewID,'test label')
    self.leftSizer.Add(self.testLabel)


    Here's how I code the event handler: ------------------

    def OnNodeChanged(self,event):
    item = self.tree.GetSelection()
    if (self.tree.ItemHasChildren(item) == 0):
    #self.testLabel.SetLabel(self.tree.GetItemText(item))
    self.testLabel.SetLabel('test')
    # The commented-out line works too.. the static text does change
    # to the static of the node --- very nice, if it weren't
    # for the error when you close the app.

    Any suggestions would be great.
    -S

    p.s.
    Here's the kicker:
    Try running C:\Python23\Lib\site-packages\wx\samples\wxProject\wxProject.py
    yourself. (but first remove, say, the editor on the right side,
    add a panel and a sizer,and then add a statictext control
    and add a tree handler to set the label). And it will work
    fine. No error dump when you close it!

    I double and triple checked that I am doing the same thing as in the
    original file. I don't want to dump my own py file, and start over
    with the original sample file. i've written too much probably for that.

    ----------------------------
    WX: wxPython WIN32-2.5.1.5
    OS: Windows XP
    PYTHON: From python.org, Version2.3
     
    python newbie, Sep 26, 2004
    #1
    1. Advertising

  2. Sorry about the two extra posts. Using Outlook Expr ( which told me it
    didn't send it the first 2 times, though it did)
     
    python newbie, Sep 26, 2004
    #2
    1. Advertising

  3. Re: Please Hlp with msg: "The C++ part of the StaticText object hasbeen deleted"

    wxPyDeadObjectError is a catch that prevents you from getting a core
    dump/memory-access-violation when you try to call a method or access an
    attribute of an object which has already been cleaned up/destroyed by
    the system. wxPyDeadObject's evaluate to false, so you can do this:
    if self.testLab:
    self.testLab.SetLabel('test')
    or you can just catch the error:

    try:
    self.testLab.SetLabel( 'test' )
    except wx.PyDeadObjectError, err:
    pass # just ignore it...

    In this case, it looks like the event is occurring after the testLab
    widget has been destroyed. Since you likely don't want to change the
    appearance of it at that point, nothing is lost.

    HTH,
    Mike

    python newbie wrote:
    ....

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

    ....
    ________________________________________________
    Mike C. Fletcher
    Designer, VR Plumber, Coder
    http://www.vrplumber.com
    http://blog.vrplumber.com
     
    Mike C. Fletcher, Sep 26, 2004
    #3
  4. Sounds like a plan. Did a google group search originally, and I couldn't
    find this info you just provided, so thanks a lot.

    "Mike C. Fletcher" <> wrote in message
    news:...
    > wxPyDeadObjectError is a catch that prevents you from getting a core
    > dump/memory-access-violation when you try to call a method or access an
    > attribute of an object which has already been cleaned up/destroyed by the
    > system. wxPyDeadObject's evaluate to false, so you can do this:
    > if self.testLab:
    > self.testLab.SetLabel('test')
    > or you can just catch the error:
    >
    > try:
    > self.testLab.SetLabel( 'test' )
    > except wx.PyDeadObjectError, err:
    > pass # just ignore it...
    >
    > In this case, it looks like the event is occurring after the testLab
    > widget has been destroyed. Since you likely don't want to change the
    > appearance of it at that point, nothing is lost.
    >
    > HTH,
    > Mike
    >
    > python newbie wrote:
    > ...
    >
    >> 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.
    >>

    > ...
    > ________________________________________________
    > Mike C. Fletcher
    > Designer, VR Plumber, Coder
    > http://www.vrplumber.com
    > http://blog.vrplumber.com
    >
     
    python newbie, Sep 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. python newbie
    Replies:
    1
    Views:
    380
    Cliff Wells
    Sep 27, 2004
  2. StvB
    Replies:
    2
    Views:
    638
    python newbie
    Sep 27, 2004
  3. Alex Nordhus
    Replies:
    0
    Views:
    276
    Alex Nordhus
    Apr 12, 2005
  4. akila_natarajan

    Read .msg attachment from a mail(.msg)

    akila_natarajan, May 13, 2011, in forum: Java
    Replies:
    0
    Views:
    423
    akila_natarajan
    May 13, 2011
  5. Charles Lowe
    Replies:
    0
    Views:
    256
    Charles Lowe
    May 13, 2007
Loading...

Share This Page