def test_setMax(self): global wasCalled # test that we do not call the callback when we set the maximum value def foo(val): global wasCalled # print "I should not be called" wasCalled=1 tw = ThumbWheel(width=100, height=26) tw.callbacks.AddCallback(foo) tw.master.update() pause() wasCalled=0 # set the value without calling callback tw.setValue(4) # change maximum without affecting value ==> nocallback tw.configure(max=6) if wasCalled: raise RuntimeError # change maximum with affecting value ==> callback tw.configure(max=2) if wasCalled==0: raise RuntimeError tw.master.update() pause() tw.master.destroy()
def test_setMin(self): global wasCalled # test that we do not call the callback when we set the minimum value def foo(val): global wasCalled # print "I should not be called" wasCalled=1 from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel tw = ThumbWheel(width=100, height=26) tw.callbacks.AddCallback(foo) wasCalled=0 # set the value without calling callback tw.setValue(4) # change minimum without affecting value ==> nocallback tw.configure(min=2) tw.master.update() pause() if wasCalled: raise RuntimeError # change minimum with affecting value ==> callback tw.configure(min=6) if wasCalled==0: raise RuntimeError tw.master.update() pause() tw.master.destroy()
def test_setOneTurn(self): """tests setOneturn """ tw = ThumbWheel(width=100, height=26) tw.configure(oneTurn=23.0) tw.master.update() self.assertEqual(tw.oneTurn,23.0) tw.master.update() pause() tw.master.destroy()
def test_setContinuous(self): """tests setContinuous """ tw = ThumbWheel(width=100, height=26) tw.configure(continuous=1) tw.master.update() pause() self.assertEqual(tw.continuous,(1 or True)) tw.configure(continuous=0) self.assertEqual(tw.continuous,(0 or False)) tw.master.update() pause() tw.master.destroy()
def test_setIncrement(self): #THIS IS A BUG #it is not working correctly tw = ThumbWheel(width=100, height=26) tw.set(5.0) tw.master.update() pause() tw.configure(increment=10) tw.set(24.0) self.assertEqual(tw.increment,10.0) #24 is shown instead of 25 self.assertEqual(tw.get(),24.0) tw.master.update() pause() tw.master.destroy()
def test_setValue(self): # test setting of a value root = Tkinter.Tk() tw = ThumbWheel(width=100, height=26, value=1.0,master = root) tw.set(10) tw.master.update() #tw.master.update() pause() self.assertEqual(tw.value,10.0) tw.configure(type=float) tw.set(20.0) tw.master.update() #tw.master.update() pause() self.assertEqual(tw.value,20.0) tw.master.destroy()
def test_setType(self): # test setting of type tw = ThumbWheel(width=100, height=26, type='float') tw.set(100.0) # we can mix configure(type=float) and configure(type='float') tw.configure(type=float) self.assertEqual(tw.type,float) self.assertEqual(type(tw.get()),type(1.0)) tw.configure(type='int') tw.master.update() pause() self.assertEqual(tw.type,int) self.assertEqual(type(tw.get()),type(1)) tw.master.update() pause() tw.master.destroy()
def test_setPrecision(self): tw = ThumbWheel(width=100, height=26) tw.configure(type='float') tw.configure(precision=5) # increase precision to 5 - this is only visual. value is not changed self.assertEqual(tw.precision,5) tw.set(4.123456789) tw.master.update() pause() # make sure that value did not change self.assertEqual(tw.value,4.123456789) # test that out-of-range values are set to 1 - 10 tw.configure(precision=0) self.assertEqual(tw.precision,1) tw.configure(precision=11) self.assertEqual(tw.precision,10) tw.master.update() pause() tw.master.destroy()
def test_setShowLabel(self): """tests setShowLAbel """ tw = ThumbWheel(width=100, height=26) tw.configure(showLabel=0) self.assertEqual(tw.showLabel,0) tw.configure(showLabel=1) tw.master.update() pause() self.assertEqual(tw.showLabel,1) tw.configure(showLabel=2) self.assertEqual(tw.showLabel,2) tw.master.update() pause() tw.master.destroy()