Esempio n. 1
0
    def __set__(self, instance, value):
        try:
            try:
                old = self._getter(instance)
            except AttributeError:
                old = NoDefault
            super(trait, self).__set__(instance, value)

        except Exception as exc:
            self.trigger(instance, "error", exc=exc)
            raise

        self.trigger(instance, "changed", old=old, new=value)

        if hasattr(old, "__snitch__"):
            disconnect(instance, old, self)

        if hasattr(value, "__snitch__"):
            connect(instance, value, self)
Esempio n. 2
0
    def __set__(self, instance, value):
        try:
            try:
                old = self._getter(instance)
            except AttributeError:
                old = NoDefault
            super(trait, self).__set__(instance, value)

        except Exception as exc:
            self.trigger(instance, 'error', exc=exc)
            raise

        self.trigger(instance, 'changed', old=old, new=value)

        if hasattr(old, '__snitch__'):
            disconnect(instance, old, self)

        if hasattr(value, '__snitch__'):
            connect(instance, value, self)
Esempio n. 3
0
    def test_chain(self):
        global id1, id2

        id1, id2 = 0, 0

        obj1 = AnyObject()
        obj2 = AnyObject()
        obj3 = AnyObject()
        obj4 = AnyObject()

        init_events(
            obj1,
            obj2,
            obj3,
            obj4,
        )

        connect(obj1, obj2, 'c12')
        connect(obj2, obj3, 'c23')
        connect(obj2, obj4, 'c24')

        def seen3(event):
            global id1
            id1 = True
            self.assertEqual(event.target, ('c12', 'c23', 'x'))

        events(obj1).listen(('c12', 'c23', 'x'), seen3)

        events(obj3).etrigger('x')
        self.assertTrue(id1)

        disconnect(obj1, obj2, 'c12')
        id1 = False
        events(obj3).etrigger('x')
        self.assertFalse(id1)

        connect(obj1, obj2, 'c12')

        del obj2  #Brake Link
        gc.collect()
        events(obj3).etrigger('x')
        self.assertFalse(id1)
Esempio n. 4
0
    def test_chain(self):
        global id1, id2
        
        id1, id2 = 0, 0
        
        obj1 = AnyObject()
        obj2 = AnyObject()
        obj3 = AnyObject()
        obj4 = AnyObject()
        
        init_events(obj1, obj2, obj3, obj4,)
        
        connect(obj1, obj2, 'c12')
        connect(obj2, obj3, 'c23')
        connect(obj2, obj4, 'c24')
        
        def seen3(event):
            global id1
            id1 = True
            self.assertEqual(event.target, ('c12', 'c23', 'x'))

        events(obj1).listen(('c12', 'c23', 'x'), seen3)
        
        events(obj3).etrigger('x')
        self.assertTrue(id1)
        
        disconnect(obj1, obj2, 'c12')
        id1 = False
        events(obj3).etrigger('x')
        self.assertFalse(id1)
        
        connect(obj1, obj2, 'c12')
        
        del obj2 #Brake Link 
        gc.collect()
        events(obj3).etrigger('x')
        self.assertFalse(id1)