peng3d/gui/widgets.py
def delete(self):
        """
        Deletes resources of this widget that require manual cleanup.
        
        Currently removes all actions, event handlers and the background.
        
        The background itself should automatically remove all vertex lists to avoid visual artifacts.
        
        Note that this method is currently experimental, as it seems to have a memory leak.
        """
        # TODO: fix memory leak upon widget deletion
        del self.bg.widget
        del self.bg
        
        #self.clickable=False
        
        del self._pos
        del self._size
        
        self.actions = {}
        
        for e_type,e_handlers in self.peng.eventHandlers.items():
            if True or e_type in eh:
                to_del = []
                for e_handler in e_handlers:
                    # Weird workaround due to implementation details of WeakMethod
                    if isinstance(e_handler,weakref.ref): 
                        if super(weakref.WeakMethod,e_handler).__call__() is self: 
                            to_del.append(e_handler) 
                    elif e_handler is self: 
                        to_del.append(e_handler)
                for d in to_del:
                    try:
                        #print("Deleting handler %s of type %s"%(d,e_type))
                        del e_handlers[e_handlers.index(d)]
                    except Exception:
                        #print("Could not delete handler %s, memory leak may occur"%d)
                        import traceback;traceback.print_exc()
def delete(self):
        """
        Deletes resources of this widget that require manual cleanup.
        
        Currently removes all actions, event handlers and the background.
        
        The background itself should automatically remove all vertex lists to avoid visual artifacts.
        
        Note that this method is currently experimental, as it seems to have a memory leak.
        """
        # TODO: fix memory leak upon widget deletion
        del self.bg.widget
        del self.bg
        
        #self.clickable=False
        
        del self._pos
        del self._size
        
        self.actions = {}
        
        for e_type,e_handlers in self.peng.eventHandlers.items():
            if True or e_type in eh:
                to_del = []
                for e_handler in e_handlers:
                    # Weird workaround due to implementation details of WeakMethod
                    if isinstance(e_handler,weakref.ref): 
                        if super(weakref.WeakMethod,e_handler).__call__() is self: 
                            to_del.append(e_handler) 
                    elif e_handler is self: 
                        to_del.append(e_handler)
                for d in to_del:
                    try:
                        #print("Deleting handler %s of type %s"%(d,e_type))
                        del e_handlers[e_handlers.index(d)]
                    except Exception:
                        #print("Could not delete handler %s, memory leak may occur"%d)
                        import traceback;traceback.print_exc()
Deletes resources of this widget that require manual cleanup.
        
        Currently removes all actions, event handlers and the background.
        
        The background itself should automatically remove all vertex lists to avoid visual artifacts.
        
        Note that this method is currently experimental, as it seems to have a memory leak.