def __del__(self): if not sip.isdeleted(self): for obs in self.observed(): # Notify of the subscribed Observables that they have a None # reference if obs is not None: obs._checkRefs() Node.__del__(self)
def __init__(self, react=None, hz=None, parent=None): """:class:`Observer` objects can be subscribed to many :class:`Observable` instances in order to listen to their notifications. The argument *react* can be set to the handler function (it must accept one argument) that will be called as consequence of an observable notification. If *react* is None, the member method :meth:`_react` will be called. *hz* defines the rate at which the observer will react to notifications. Available values are: * None --- immediately; * 0 --- never; * <float> --- at the selected frequency (in hz). *parent* defines the observers parent. .. note:: The list of the subscribed observables is composed by weak references, so it is necessary to keep both observables and observers alive. """ if not sip.ispycreated(self): QtCore.QObject.__init__(self, parent) Node.__init__(self) self._internal = self._InternalQObject() self.__observed = set() self.__queue = set() self.__timer = QtCore.QTimer(timeout=self._update) self.__hz = None if hz is None else float(hz) if self.__hz: self.__timer.start(1000/float(hz)) self.__react = assertIsInstance(react, None, collections.Callable)
def __del__(self): if not sip.isdeleted(self): generator = ((ref(), record) for (ref, record) \ in self.__observers.items() if ref() is not None) for obs, record in generator: # Notify the subscribed observers they have a None reference. record.trigger.disconnect(obs._reactSlot) obs._checkRefs() # To make sure that the children's '__del__' method is invoked. for child in tuple(self.children()): child.setParent(None) Node.__del__(self)
def __init__(self, parent=None): """:class:`Observable` objects can be subscribed by a list of :class:`Observer` instances. An Observable can trigger all or only a subset of the subscribed observers by invoking the method :meth:`trigger`. The attribute *parent* defines the parent object of the observable. .. note:: The list of the subscribed observers is composed by weak references, so it is necessary to keep both observables and observers alive. """ QtCore.QObject.__init__(self, parent) Node.__init__(self) self.__observers = dict()