Re: [dabo-users] PyDeadObject from Modal Form

Author: Paul McNett

Posted: 2009-08-03 at 13:02:14

(revisited thread from July 7):

http://leafe.com/archives/showFullThd/422649

Miguel Lopes wrote:

> The bulk of my application is hand coded, and I'm planing to use cdxml dForm

> (instantiated as Modal) to edit simple records.

>

> I'm experimenting with such a form, but ran into a PyDeadObjectError

> exception that I can figure out how to avoid. his exception is significant

> since I can no longer reinstantiate the same form!

>

> Here's my traceback:

>

> Traceback (most recent call last):

> File

> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dControlMixin.py",

> line 27, in _onWxHit

> self.raiseEvent(dEvents.Hit, evt, *args, **kwargs)

> File

> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",

> line 949, in raiseEvent

> super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args,

> **kwargs)

> File

> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/lib/eventMixin.py",

> line 93, in raiseEvent

> bindingFunction(event)

> File

> "/Users/miguelek/Documents/programming/daboprgs/HandCoding_02/ui/appModules/AccountPages.py",

> line 160, in onEdit

> frm.showForm(contactsForAccount, 'EditRec') #, parentPK, childPK

> File "/var/folders/XN/XNKKbB+9EVeY1y0rXolJBE+++TI/-Tmp-/tmpLfCKRL.py",

> line 247, in showForm

> self.show()

> File

> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",

> line 1282, in show

> self.Visible = True

> File

> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dForm.py",

> line 964, in _setVisible

> self._hackToFrame()

> File

> "//usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/_core.py",

> line 14524, in __getattr__

> raise PyDeadObjectError(self.attrStr % self._name)

> wx._core.PyDeadObjectError: The C++ part of the dForm_43298 object has been

> deleted, attribute access no longer allowed.

>

> The "form" (dialog) class is created from the cdxml file in the normal way.

> Since I pass a bizobj to the dialog with the record to edit, I have my own

> method to show the form:

>

> # This method lives in the dialog

> def showForm(self, contactsBizobj, usage):

>

> # set the forms Bizobj - this makes the form reusable for different

> origins

> # of contacts (e.g. Children of account, children of opportunity, ...)

> self.VCRactive = True

>

> self.addBizobj(contactsBizobj)

> self.requery()

>

> if usage == 'NewRec':

>

> self.new()

>

> self.show()

>

> #to close the form I just use close:

> ## *!* ## Dabo Code ID: dButton-dPanel-956

> def onHit(self, evt):

> self.Form.close()

>

> I suppose this is either a wxPython or a Dabo bug, since I'm not doing

> anything special here.

>

> Platform: Mac

> Python Version: 2.5.4 on darwin

> Dabo Version: Version 0.9.2; Revision 5254M

> UI Version: 2.8.9.2 on wxMac

Does this patch fix it?

{{{

Index: dabo/ui/uiwx/dForm.py

===================================================================

--- dabo/ui/uiwx/dForm.py (revision 5305)

+++ dabo/ui/uiwx/dForm.py (working copy)

@@ -924,30 +924,30 @@

# This is a normal SDI form:

preClass = wx.PreFrame

self._mdi = False

- self._hackToFrame()

+ dForm._hackToFrame()

## (Note that it is necessary to run the above blocks each time, because

## we are modifying the dForm class definition globally.)

BaseForm.__init__(self, preClass, parent, properties, attProperties,

*args, **kwargs)

- self._hackToFrame()

+ dForm._hackToFrame()

def _hackToDialog(self):

dForm.__bases__ = (BaseForm, wx.Dialog)

- def _hackToFrame(self):

- if self._mdi:

+ def _hackToFrame(cls):

+ if dabo.settings.MDI:

dForm.__bases__ = (BaseForm, wx.MDIChildFrame)

else:

dForm.__bases__ = (BaseForm, wx.Frame)

+ _hackToFrame = classmethod(_hackToFrame)

-

def Show(self, show=True, *args, **kwargs):

self._gtk_show_fix(show)

if self.Modal:

self._hackToDialog()

dForm.__bases__[-1].Show(self, show, *args, **kwargs)

- self._hackToFrame()

+ dForm._hackToFrame()

def _getModal(self):

return getattr(self, "_modal", False)

@@ -961,7 +961,7 @@

if val and self.Modal:

self._hackToDialog()

self.ShowModal()

- self._hackToFrame()

+ dForm._hackToFrame()

else:

self.Show(val)

else:

}}}

Paul

©2009 Paul McNett