def test_reference_child_update(self, set_name): from kivy.properties import NumericProperty, ReferenceListProperty x = NumericProperty(0) if set_name: x.set_name(wid, 'x') x.link_eagerly(wid) else: x.link(wid, 'x') x.link_deps(wid, 'x') y = NumericProperty(0) if set_name: y.set_name(wid, 'y') y.link_eagerly(wid) else: y.link(wid, 'y') y.link_deps(wid, 'y') pos = ReferenceListProperty(x, y) if set_name: pos.set_name(wid, 'pos') pos.link_eagerly(wid) else: pos.link(wid, 'pos') pos.link_deps(wid, 'pos') pos.get(wid)[0] = 10 self.assertEqual(pos.get(wid), [10, 0]) pos.get(wid)[:] = (20, 30) self.assertEqual(pos.get(wid), [20, 30])
def test_reference(self, set_name): from kivy.properties import NumericProperty, ReferenceListProperty x = NumericProperty(0) if set_name: x.set_name(wid, 'x') x.link_eagerly(wid) else: x.link(wid, 'x') x.link_deps(wid, 'x') y = NumericProperty(0) if set_name: y.set_name(wid, 'y') y.link_eagerly(wid) else: y.link(wid, 'y') y.link_deps(wid, 'y') pos = ReferenceListProperty(x, y) if set_name: pos.set_name(wid, 'pos') pos.link_eagerly(wid) else: pos.link(wid, 'pos') pos.link_deps(wid, 'pos') self.assertEqual(x.get(wid), 0) self.assertEqual(y.get(wid), 0) self.assertEqual(pos.get(wid), [0, 0]) x.set(wid, 50) self.assertEqual(pos.get(wid), [50, 0]) y.set(wid, 50) self.assertEqual(pos.get(wid), [50, 50]) pos.set(wid, [0, 0]) self.assertEqual(pos.get(wid), [0, 0]) self.assertEqual(x.get(wid), 0) self.assertEqual(y.get(wid), 0) # test observer global observe_called observe_called = 0 def observe(obj, value): global observe_called observe_called = 1 pos.bind(wid, observe) self.assertEqual(observe_called, 0) x.set(wid, 99) self.assertEqual(observe_called, 1)
def test_reference_child_update(self): from kivy.properties import NumericProperty, ReferenceListProperty x = NumericProperty(0) x.link(wid, 'x') x.link_deps(wid, 'x') y = NumericProperty(0) y.link(wid, 'y') y.link_deps(wid, 'y') pos = ReferenceListProperty(x, y) pos.link(wid, 'pos') pos.link_deps(wid, 'pos') pos.get(wid)[0] = 10 self.assertEqual(pos.get(wid), [10, 0]) pos.get(wid)[:] = (20, 30) self.assertEqual(pos.get(wid), [20, 30])
def test_reference(self): from kivy.properties import NumericProperty, ReferenceListProperty x = NumericProperty(0) x.link(wid, 'x') x.link_deps(wid, 'x') y = NumericProperty(0) y.link(wid, 'y') y.link_deps(wid, 'y') pos = ReferenceListProperty(x, y) pos.link(wid, 'pos') pos.link_deps(wid, 'pos') self.assertEqual(x.get(wid), 0) self.assertEqual(y.get(wid), 0) self.assertEqual(pos.get(wid), [0, 0]) x.set(wid, 50) self.assertEqual(pos.get(wid), [50, 0]) y.set(wid, 50) self.assertEqual(pos.get(wid), [50, 50]) pos.set(wid, [0, 0]) self.assertEqual(pos.get(wid), [0, 0]) self.assertEqual(x.get(wid), 0) self.assertEqual(y.get(wid), 0) # test observer global observe_called observe_called = 0 def observe(obj, value): global observe_called observe_called = 1 pos.bind(wid, observe) self.assertEqual(observe_called, 0) x.set(wid, 99) self.assertEqual(observe_called, 1)