When I open multiple documents in my pydocview SDI application,
each with its own view, I get this traceback when closing the app
by selecting "Exit" from the File menu:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/lib/pydocview.py", line 2372, in OnExit
self.Destroy()
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14041, in __getattr__
raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the DocSDIFrame object has been deleted, attribute
access no longer allowed.
I learnded that I have to override the OnClose() method of my view so that
it closes the window - otherwise I get a PyDeadObjectError concerning the document
object:
def OnClose(self, deleteWindow=True):
# Call parent class
close = docview.View.OnClose(self, deleteWindow)
# Close frame
if close and deleteWindow:
self.GetFrame().Close(True)
return close
But the DocSDIFrame seems to try to destroy itself once more:
def OnExit(self, event):
"""
Called when the application is exitting.
"""
# In there, View.OnClose() gets called
if self._childView.GetDocumentManager().Clear(force = False):
self.Destroy() # <- Here the frame is deleted a second time => traceback
else:
event.Veto()
Do I have to handle the closing of the view another way?
Btw, the event object that is passed to OnExit() above is of type CommandEvent,
which does not have a Veto() method.
When I open multiple documents in my pydocview SDI application,
each with its own view, I get this traceback when closing the app
by selecting "Exit" from the File menu:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/lib/pydocview.py", line 2372, in OnExit
self.Destroy()
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14041, in __getattr__
raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the DocSDIFrame object has been deleted, attribute
access no longer allowed.
[...]
I just checked that the same happens with the pydocview demo:
1) open PyDocViewDemo.py
2) Type something into the window
3) Open a second window by selecting File->New
4) Type something into the new window
5) Select File->Exit from the menu of the /second/ window
==> Traceback
This does not happen if you select File->Exit from the first window.
When I open multiple documents in my pydocview SDI application,
each with its own view, I get this traceback when closing the app
by selecting "Exit" from the File menu:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/lib/pydocview.py", line 2372, in OnExit
self.Destroy()
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14041, in __getattr__
raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the DocSDIFrame object has been deleted, attribute
access no longer allowed.
[...]
I just checked that the same happens with the pydocview demo:
1) open PyDocViewDemo.py
2) Type something into the window
3) Open a second window by selecting File->New
4) Type something into the new window
5) Select File->Exit from the menu of the /second/ window
==> Traceback
This does not happen if you select File->Exit from the first window.
It's just lucky that it doesn't do it in that case
It looks like there has been some confusion about what OnExit should do, as in some places in the docview modules a method with that name is used as the handler for the menu event, and in other places it is used as a way for template and view classes to clean up after themselves. Anyway, changing DocSDIFrame.OnExit to just have this one line seems to take care of the problem:
def OnExit(self, event):
"""
Called when the application is exitting.
"""
self._childView.GetDocumentManager().Clear(force = False)
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
I just checked that the same happens with the pydocview demo:
1) open PyDocViewDemo.py
2) Type something into the window
3) Open a second window by selecting File->New
4) Type something into the new window
5) Select File->Exit from the menu of the /second/ window
==> Traceback
This does not happen if you select File->Exit from the first window.
It's just lucky that it doesn't do it in that case
It looks like there has been some confusion about what OnExit should do,
as in some places in the docview modules a method with that name is used
as the handler for the menu event, and in other places it is used as a
way for template and view classes to clean up after themselves. Anyway,
changing DocSDIFrame.OnExit to just have this one line seems to take
care of the problem:
def OnExit(self, event):
"""
Called when the application is exitting.
"""
self._childView.GetDocumentManager().Clear(force = False)
Ah, I see. When I stepped into that method with the debugger I was a bit
confused because the flow of control seemed to 'hop' back and forth
between the document, the view, and the frame. Thank you for clarifying.
Should I report a bug, and if so, is the wxWidgets tracker at wxWidgets download | SourceForge.net the right place
to report wxPython/pydocview bugs?