[wxPython] OGL: wxShape.GetLines()

Hi,

I'm trying to define a method to delete a shape and the lines connected to
it.

class gpkComp(wxRectangleShape):
    def __del__(self):
        parent = self.Parent
        for line in self.GetLines():
            line.__del__()
        parent.Diagram.RemoveShape(self)
        parent.Comps.remove(self)
        parent.Refresh()

class gpkLine(wxLineShape):
    def __del__(self):
        parent = self.Parent
        fromComp = self.FromComp
        fromComp.RemoveLine(self)
        parent.Diagram.RemoveShape(self)
        parent.Refresh()

The program returns this error:
line.__del__()
AttributeError: 'wxPyLineShapePtr' instance has no attribute '__del__'

It looks like GetLines() returns a list of wxLineShape and __del__() is a
method of gpkLine so there is a type mismatch...

I could define a a new list of gpkLine on gpkComp, but there must be a
better solution.

Thanks,

Greg

I'm trying to define a method to delete a shape and the lines connected to
it.

class gpkComp(wxRectangleShape):
    def __del__(self):
        parent = self.Parent
        for line in self.GetLines():
            line.__del__()
        parent.Diagram.RemoveShape(self)
        parent.Comps.remove(self)
        parent.Refresh()

class gpkLine(wxLineShape):
    def __del__(self):
        parent = self.Parent
        fromComp = self.FromComp
        fromComp.RemoveLine(self)
        parent.Diagram.RemoveShape(self)
        parent.Refresh()

The program returns this error:
line.__del__()
AttributeError: 'wxPyLineShapePtr' instance has no attribute '__del__'

It looks like GetLines() returns a list of wxLineShape and __del__() is a
method of gpkLine so there is a type mismatch...

That is the currently the way that most things work in wxPython. If a
method returns a pointer to some object the wrapper classes have no way to
know if the object was created in C++ or in Python, and if it was created in
Python what the original Python object was, so it just creates a new Python
shadow object around the C++ pointer and returns that.

I could define a a new list of gpkLine on gpkComp, but there must be a
better solution.

Well for one you shouldn't have to call an object's __del__ method directly
as it's just going to be called again when the reference count goes to zero.
You might want to move that code into a cleanup() method or something if you
need to call it before the object is actually deleted by Python.

UNtil there is a way to get the original object back you can solve your
problem by either keeping your own list of lines, or moving the info and
method needed to do the cleanup ourside of your line class. (Or do some
nasty surgery on the objects returned by GetLines, but that isn't
recommended.)

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!