Ejemplo n.º 1
0
    def test_callback_2(self):
        global wasCalled1
        global wasCalled2
        
        def foo1(val):
            global wasCalled1
            wasCalled1=True

        def foo2(val):
            global wasCalled2
            wasCalled2=True
            
        dial = Dial(size=50, value=10.0, callback=[foo1,foo2])
        self.assertEqual(dial.callbacks.callbacks, [foo1,foo2], "Expecting to have foo added to the callbackmanager callbacks list")
        # setValue(val) should NOT call callback
        wasCalled1 = False
        wasCalled2 = False
        dial.setValue(5.0)
        if wasCalled1 and wasCalled2:
            raise RuntimeError

        # set(val) should call callback
        dial.set(6.0)
        if not wasCalled1 and not wasCalled2:
            raise RuntimeError

        wasCalled1 = False
        wasCalled2 = False
        dial.set(7.0, update=0)
        if wasCalled1 and wasCalled2:
            raise RuntimeError
        dial.master.update()
        pause()
        dial.master.destroy()
Ejemplo n.º 2
0
 def test_callback(self):
     # test callback
     global wasCalled
     dial = Dial(size=50, value=10.0)
     dial.callbacks.AddCallback(MyCallback)
     dial.master.update()
     pause()
     self.assertEqual(len(dial.callbacks.callbacks), 1)
     dial.callbacks.RemoveCallback(MyCallback)
     self.assertEqual(len(dial.callbacks.callbacks), 0)
     # setValue(val) should NOT call callback
     dial.callbacks.AddCallback(MyCallback)
     dial.setValue(5.0)
     dial.master.update()
     pause()
     if wasCalled == True:
         raise RuntimeError
     # set(val) should call callback
     dial.set(6.0)
     dial.master.update()
     pause()
     if wasCalled == False:
         raise RuntimeError
     wasCalled = False
     dial.set(7.0, update=0)
     if wasCalled:
         raise RuntimeError
     dial.master.destroy()
Ejemplo n.º 3
0
 def test_callback(self):
     # test callback
     global wasCalled 
     dial = Dial(size=50, value=10.0)
     dial.callbacks.AddCallback(MyCallback)
     dial.master.update()
     pause()
     self.assertEqual(len(dial.callbacks.callbacks),1)
     dial.callbacks.RemoveCallback(MyCallback)
     self.assertEqual(len(dial.callbacks.callbacks),0)
     # setValue(val) should NOT call callback
     dial.callbacks.AddCallback(MyCallback)
     dial.setValue(5.0)
     dial.master.update()
     pause()
     if wasCalled == True:
         raise RuntimeError
     # set(val) should call callback
     dial.set(6.0)
     dial.master.update()
     pause()
     if wasCalled == False:
         raise RuntimeError
     wasCalled = False
     dial.set(7.0, update=0)
     if wasCalled:
         raise RuntimeError
     dial.master.destroy()    
Ejemplo n.º 4
0
 def test_setValue(self):
     # test setting of a value
     dial = Dial(size=50, value=10.0)
     dial.master.update()
     pause()
     self.assertEqual(dial.value == 10.0,True)
     dial.configure(type=float)
     dial.set(20.0)
     self.assertEqual(dial.value == 20.0,True)
     dial.master.update()
     pause()
     dial.master.withdraw()
     dial.master.destroy()
Ejemplo n.º 5
0
 def test_setValue(self):
     # test setting of a value
     dial = Dial(size=50, value=10.0)
     dial.master.update()
     pause()
     self.assertEqual(dial.value == 10.0, True)
     dial.configure(type=float)
     dial.set(20.0)
     self.assertEqual(dial.value == 20.0, True)
     dial.master.update()
     pause()
     dial.master.withdraw()
     dial.master.destroy()
Ejemplo n.º 6
0
 def test_setPrecision(self):
     """tests set precision
     """
     dial = Dial(size=50)
     dial.configure(type='float')
     dial.configure(precision=5)
     dial.master.update()
     pause()
     # increase precision to 5 - this is only visual. value is not changed
     self.assertEqual(dial.precision == 5,True)
     dial.set(4.123456789)
     dial.master.update()
     pause()
     # make sure that value did not change
     self.assertEqual(dial.value == 4.123456789,True)
     dial.master.destroy()
Ejemplo n.º 7
0
 def test_setPrecision(self):
     """tests set precision
     """
     dial = Dial(size=50)
     dial.configure(type='float')
     dial.configure(precision=5)
     dial.master.update()
     pause()
     # increase precision to 5 - this is only visual. value is not changed
     self.assertEqual(dial.precision == 5, True)
     dial.set(4.123456789)
     dial.master.update()
     pause()
     # make sure that value did not change
     self.assertEqual(dial.value == 4.123456789, True)
     dial.master.destroy()
Ejemplo n.º 8
0
 def test_setType(self):
     # test setting of type
     dial = Dial(size=50, type='float')
     dial.set(100.0)
     dial.master.update()
     pause()
     # we can mix configure(type=float) and configure(type='float')
     dial.configure(type=float)
     self.assertEqual(dial.type == float,True)
     self.assertEqual(type(dial.get()) == type(1.0),True)
     dial.configure(type='int')
     self.assertEqual(dial.type == int,True)
     self.assertEqual(type(dial.get()) == type(1),True)
     dial.master.update()
     pause()
     dial.master.withdraw()
     dial.master.destroy()
Ejemplo n.º 9
0
 def test_setType(self):
     # test setting of type
     dial = Dial(size=50, type='float')
     dial.set(100.0)
     dial.master.update()
     pause()
     # we can mix configure(type=float) and configure(type='float')
     dial.configure(type=float)
     self.assertEqual(dial.type == float, True)
     self.assertEqual(type(dial.get()) == type(1.0), True)
     dial.configure(type='int')
     self.assertEqual(dial.type == int, True)
     self.assertEqual(type(dial.get()) == type(1), True)
     dial.master.update()
     pause()
     dial.master.withdraw()
     dial.master.destroy()
Ejemplo n.º 10
0
 def test_setValueWithIncrement(self):
     
     dial = Dial(size=50, value=5.0)
     dial.master.update()
     pause()
     self.assertEqual(dial.increment == 0.0,True) # increment is 0.0 if not set
     self.assertEqual(dial.value == 5.0,True)
     # now set increment and then set a new value
     dial.configure(increment=2.0)
     self.assertEqual(dial.increment == 2.0,True)
     dial.set(21.0)
     #set value is 21 but 23 is shown
     #print dial.value
     self.assertEqual(dial.value == 21.0,True)
     dial.master.update()
     pause()
     dial.master.withdraw()
     dial.master.destroy()
Ejemplo n.º 11
0
    def test_setValueWithIncrement(self):

        dial = Dial(size=50, value=5.0)
        dial.master.update()
        pause()
        self.assertEqual(dial.increment == 0.0,
                         True)  # increment is 0.0 if not set
        self.assertEqual(dial.value == 5.0, True)
        # now set increment and then set a new value
        dial.configure(increment=2.0)
        self.assertEqual(dial.increment == 2.0, True)
        dial.set(21.0)
        #set value is 21 but 23 is shown
        #print dial.value
        self.assertEqual(dial.value == 21.0, True)
        dial.master.update()
        pause()
        dial.master.withdraw()
        dial.master.destroy()
Ejemplo n.º 12
0
    def test_callback_2(self):
        global wasCalled1
        global wasCalled2

        def foo1(val):
            global wasCalled1
            wasCalled1 = True

        def foo2(val):
            global wasCalled2
            wasCalled2 = True

        dial = Dial(size=50, value=10.0, callback=[foo1, foo2])
        self.assertEqual(
            dial.callbacks.callbacks, [foo1, foo2],
            "Expecting to have foo added to the callbackmanager callbacks list"
        )
        # setValue(val) should NOT call callback
        wasCalled1 = False
        wasCalled2 = False
        dial.setValue(5.0)
        if wasCalled1 and wasCalled2:
            raise RuntimeError

        # set(val) should call callback
        dial.set(6.0)
        if not wasCalled1 and not wasCalled2:
            raise RuntimeError

        wasCalled1 = False
        wasCalled2 = False
        dial.set(7.0, update=0)
        if wasCalled1 and wasCalled2:
            raise RuntimeError
        dial.master.update()
        pause()
        dial.master.destroy()