##// END OF EJS Templates
Change 'bind' to 'link'
Jason Grout -
Show More
@@ -32,7 +32,7 b' from IPython.utils.traitlets import ('
32 HasTraits, MetaHasTraits, TraitType, Any, CBytes, Dict,
32 HasTraits, MetaHasTraits, TraitType, Any, CBytes, Dict,
33 Int, Long, Integer, Float, Complex, Bytes, Unicode, TraitError,
33 Int, Long, Integer, Float, Complex, Bytes, Unicode, TraitError,
34 Undefined, Type, This, Instance, TCPAddress, List, Tuple,
34 Undefined, Type, This, Instance, TCPAddress, List, Tuple,
35 ObjectName, DottedObjectName, CRegExp, bind
35 ObjectName, DottedObjectName, CRegExp, link
36 )
36 )
37 from IPython.utils import py3compat
37 from IPython.utils import py3compat
38 from IPython.testing.decorators import skipif
38 from IPython.testing.decorators import skipif
@@ -974,9 +974,9 b' def test_dict_assignment():'
974 nt.assert_equal(d, c.value)
974 nt.assert_equal(d, c.value)
975 nt.assert_true(c.value is d)
975 nt.assert_true(c.value is d)
976
976
977 class TestBind(TestCase):
977 class TestLink(TestCase):
978 def test_connect_same(self):
978 def test_connect_same(self):
979 """Verify two traitlets of the same type can be bound together using bind."""
979 """Verify two traitlets of the same type can be linked together using link."""
980
980
981 # Create two simple classes with Int traitlets.
981 # Create two simple classes with Int traitlets.
982 class A(HasTraits):
982 class A(HasTraits):
@@ -985,9 +985,9 b' class TestBind(TestCase):'
985 b = A(value=8)
985 b = A(value=8)
986
986
987 # Conenct the two classes.
987 # Conenct the two classes.
988 c = bind((a, 'value'), (b, 'value'))
988 c = link((a, 'value'), (b, 'value'))
989
989
990 # Make sure the values are the same at the point of binding.
990 # Make sure the values are the same at the point of linking.
991 self.assertEqual(a.value, b.value)
991 self.assertEqual(a.value, b.value)
992
992
993 # Change one of the values to make sure they stay in sync.
993 # Change one of the values to make sure they stay in sync.
@@ -996,8 +996,8 b' class TestBind(TestCase):'
996 b.value = 6
996 b.value = 6
997 self.assertEqual(a.value, b.value)
997 self.assertEqual(a.value, b.value)
998
998
999 def test_bind_different(self):
999 def test_link_different(self):
1000 """Verify two traitlets of different types can be bound together using bind."""
1000 """Verify two traitlets of different types can be linked together using link."""
1001
1001
1002 # Create two simple classes with Int traitlets.
1002 # Create two simple classes with Int traitlets.
1003 class A(HasTraits):
1003 class A(HasTraits):
@@ -1008,9 +1008,9 b' class TestBind(TestCase):'
1008 b = B(count=8)
1008 b = B(count=8)
1009
1009
1010 # Conenct the two classes.
1010 # Conenct the two classes.
1011 c = bind((a, 'value'), (b, 'count'))
1011 c = link((a, 'value'), (b, 'count'))
1012
1012
1013 # Make sure the values are the same at the point of binding.
1013 # Make sure the values are the same at the point of linking.
1014 self.assertEqual(a.value, b.count)
1014 self.assertEqual(a.value, b.count)
1015
1015
1016 # Change one of the values to make sure they stay in sync.
1016 # Change one of the values to make sure they stay in sync.
@@ -1019,8 +1019,8 b' class TestBind(TestCase):'
1019 b.count = 4
1019 b.count = 4
1020 self.assertEqual(a.value, b.count)
1020 self.assertEqual(a.value, b.count)
1021
1021
1022 def test_unbind(self):
1022 def test_unlink(self):
1023 """Verify two binded traitlets can be unbinded."""
1023 """Verify two linked traitlets can be unlinked."""
1024
1024
1025 # Create two simple classes with Int traitlets.
1025 # Create two simple classes with Int traitlets.
1026 class A(HasTraits):
1026 class A(HasTraits):
@@ -1028,17 +1028,17 b' class TestBind(TestCase):'
1028 a = A(value=9)
1028 a = A(value=9)
1029 b = A(value=8)
1029 b = A(value=8)
1030
1030
1031 # Conenct the two classes.
1031 # Connect the two classes.
1032 c = bind((a, 'value'), (b, 'value'))
1032 c = link((a, 'value'), (b, 'value'))
1033 a.value = 4
1033 a.value = 4
1034 c.unbind()
1034 c.unlink()
1035
1035
1036 # Change one of the values to make sure they stay in sync.
1036 # Change one of the values to make sure they don't stay in sync.
1037 a.value = 5
1037 a.value = 5
1038 self.assertNotEqual(a.value, b.value)
1038 self.assertNotEqual(a.value, b.value)
1039
1039
1040 def test_callbacks(self):
1040 def test_callbacks(self):
1041 """Verify two binded traitlets have their callbacks called once."""
1041 """Verify two linked traitlets have their callbacks called once."""
1042
1042
1043 # Create two simple classes with Int traitlets.
1043 # Create two simple classes with Int traitlets.
1044 class A(HasTraits):
1044 class A(HasTraits):
@@ -1057,8 +1057,8 b' class TestBind(TestCase):'
1057 callback_count.append('b')
1057 callback_count.append('b')
1058 b.on_trait_change(b_callback, 'count')
1058 b.on_trait_change(b_callback, 'count')
1059
1059
1060 # Conenct the two classes.
1060 # Connect the two classes.
1061 c = bind((a, 'value'), (b, 'count'))
1061 c = link((a, 'value'), (b, 'count'))
1062
1062
1063 # Make sure b's count was set to a's value once.
1063 # Make sure b's count was set to a's value once.
1064 self.assertEqual(''.join(callback_count), 'b')
1064 self.assertEqual(''.join(callback_count), 'b')
@@ -184,8 +184,8 b' def getmembers(object, predicate=None):'
184 return results
184 return results
185
185
186 @skip_doctest
186 @skip_doctest
187 class bind(object):
187 class link(object):
188 """Bind traits from different objects together so they remain in sync.
188 """Link traits from different objects together so they remain in sync.
189
189
190 Parameters
190 Parameters
191 ----------
191 ----------
@@ -194,7 +194,7 b' class bind(object):'
194 Examples
194 Examples
195 --------
195 --------
196
196
197 >>> c = bind((obj1, 'value'), (obj2, 'value'), (obj3, 'value'))
197 >>> c = link((obj1, 'value'), (obj2, 'value'), (obj3, 'value'))
198 >>> obj1.value = 5 # updates other objects as well
198 >>> obj1.value = 5 # updates other objects as well
199 """
199 """
200 updating = False
200 updating = False
@@ -233,7 +233,7 b' class bind(object):'
233 if obj is not sending_obj or attr != sending_attr:
233 if obj is not sending_obj or attr != sending_attr:
234 setattr(obj, attr, new)
234 setattr(obj, attr, new)
235
235
236 def unbind(self):
236 def unlink(self):
237 for key, callback in self.objects.items():
237 for key, callback in self.objects.items():
238 (obj,attr) = key
238 (obj,attr) = key
239 obj.on_trait_change(callback, attr, remove=True)
239 obj.on_trait_change(callback, attr, remove=True)
General Comments 0
You need to be logged in to leave comments. Login now