The woes of event handling in wxPython
sparky
sparky at gottachat.com
Fri Apr 25 17:43:20 EDT 2003
I recently took over a project from another programmer. His code is
about 80% done and very buggy.
The one major bug that I have found in his code is the event handling.
He used wxPython's pubsub.py and evtmgr.py. Which means that I am kinda
stuck with it.
In several places the software launches custom dialogs for the user to
input data.
The first time any of these are launched they work fine.
However, on the second time that I launch any one of them the following
exception is raised from evtmgr.py:
wxPython.wx.wxPyDeadObjectError: The C++ part of the EditMemberDialog
object has been deleted, attribute access no longer allowed.
Ok, I've dove into Python before, so I dove straight into the evtmgr.py
file to find out what was going on.
It looks pretty straight forward. So I added a __del__() function to do
clean up and unregister/unsubscribe the listeners and publishers.
This didn't work quite as planned. I continued to get the same exception.
So I started wrapping code in a try/except. It only took adding that
twice to see that this was futile and not solving the problem.
Using the evtmgr interface to deal with cleaning up the old dead objects
created by sending dialogs to the great bit bucket in the sky doesn't
seem to work.
Here is some example code (sorry I cannot give you a complete class,
they asked us not to post any code):
import pubsub, evtmgr
class EditMemberDialog(EditDialog):
def __init__(self, parent, *args):
.
.
<snip a bunch of stuff that works>
.
.
.
eventManager.Register(self.__saveMemberGoals, EVT_TEXT,
self.descriptionText)
server.subscribe(topic = CommandPattern.CommandHistory,
listener = self.__notifyObjectOfChange)
<snip a bunch of stuff that works>
def __del__(self):
eventManager.Deregister(self.__saveMemberGoals)
server.unsubscribe(self.__notifyObjectOfChange)
self.parent.__del__()
So, now when I launch the dialog the first time. It works just fine.
The second time it gets launched I get the:
wxPython.wx.wxPyDeadObjectError: The C++ part of the EditMemberDialog
object has been deleted, attribute access no longer allowed.
What am I missing?
More information about the Python-list
mailing list