Пример #1
0
    def test_extended(self):
        """ Tests a dynamic trait change handler using extended names. """

        class Child(HasTraits):
            i = Int

        class Parent(HasTraits):
            child = Instance(Child)

        # Create objects
        parent = Parent(child=Child())
        target = HasTraits()

        # Set up to count changes in i
        self.count = 0

        def count_notifies():
            self.count += 1

        parent.on_trait_change(count_notifies, "child:i", target=target)

        # Change the trait
        parent.child.i = 10
        # Delete the target and change it again
        del target
        parent.child.i = 0
        # The count should be 1
        self.assertEqual(self.count, 1)
Пример #2
0
    def test_simple(self):
        """ Tests a simple dynamic trait change handler. """

        class Test(HasTraits):
            i = Int

        # Create objects
        obj = Test()
        target = HasTraits()

        # Set up to count changes in i
        self.count = 0

        def count_notifies():
            self.count += 1

        obj.on_trait_change(count_notifies, "i", target=target)

        # Change the trait
        obj.i = 10
        # Delete the target and change it again
        del target
        obj.i = 0
        # The count should be 1
        self.assertEqual(self.count, 1)
Пример #3
0
 def test_trait_compound_instance(self):
     """ Test that a deferred Instance() embedded in a TraitCompound handler
     and then a list will not replace the validate method for the outermost
     trait.
     """
     # Pass through an instance in order to make the instance trait resolve
     # the class.
     d = Dummy()
     d.xl = [HasTraits()]
     d.x = "OK"
Пример #4
0
def service_factory(**properties):
    """ A factory for foos. """

    return HasTraits(**properties)
Пример #5
0
 def test_new(self):
     # Should not raise DeprecationWarning.
     HasTraits(x=10)
Пример #6
0
#class TestClass(HasTraits):
#    b1 = Bool
#    b2 = Bool
#    b3 = Bool
#    _updated = Bool(False)

#
#for e in dir(view1):
#    print e

#for attr in ['b1', "title", "handler", "buttons"]:
#    print attr, getattr(view1, attr, None)

#tc = TestClass()
#tc.add_trait( 'b4',Bool)

t = HasTraits()
nameL = []
for i in range(4):
    name = 'r%d' % i
    t.add_trait(name, Range(1, 10, i))
    nameL.append(name)

view1 = View(nameL,
             title="Alter Title",
             handler=TC_Handler(),
             buttons=['OK', 'Cancel'])

t.configure_traits(view=view1)