Quoting Aaron Digulla <[EMAIL PROTECTED]>:

Another wa would be to save all objects which pass through SIP in map
(QObject -> Python wrapper), connect to the destroyed(QObject) signal
and check the state when it is emitted. Does SIP notice when the python
wrapper is destroyed? If not, it's probably possible to patch the GC
code of Python to call an additional routine for the wrapper objects.

I whipped together a quick example of what I have in mind:

------------------------------------------------------------
import traceback
from PyQt4.QtCore import SIGNAL, QObject

guards = {}

class Ouch(QObject):
    def __init__(self):
        QObject.__init__(self)
        self.st = traceback.format_stack()

    def punch(self):
        print 'Guarded object was destroyed'
        print self.st[-3]

def guard(o):
    g = Ouch()
    assert g.connect(o, SIGNAL('destroyed()'), g.punch)
    guards[g] = None
    return o

o = guard(QObject())
del o
------------------------------------------------------------

That prints:

Guarded object was destroyed
  File "t.py", line 31, in <module>
    o = guard(QObject())

Probably not the whole nine yards but maybe two, or so...

Regards,

--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://www.pdark.de/

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to