aboutsummaryrefslogtreecommitdiff
path: root/funcGenerator.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-12 19:01:47 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-12 19:01:47 -0400
commitc9db13448d4c28b69abac107b495d351558669f5 (patch)
tree552600df1d4620fb256a7aeefd5b273d0efca33a /funcGenerator.py
parent2038f3095041aee4a093dea735fb0f10c30d1900 (diff)
downloadpyExpControl-c9db13448d4c28b69abac107b495d351558669f5.tar.gz
pyExpControl-c9db13448d4c28b69abac107b495d351558669f5.zip
Tk timer test improved
Diffstat (limited to 'funcGenerator.py')
-rw-r--r--funcGenerator.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/funcGenerator.py b/funcGenerator.py
index 4cbef0c..b4aa5f2 100644
--- a/funcGenerator.py
+++ b/funcGenerator.py
@@ -113,7 +113,7 @@ class Sweeper:
if stop > deadline:
runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000
print("Overrun: Callbacks took %s seconds instead of %s" % (runTime, self.dTmS/1000) )
- self.widget.after(0, self.onTic)
+ self.after(0, self.onTic)
idleTime_mS = round((deadline-stop).seconds * 1000 + (deadline-stop).microseconds/1000)
# print("Will idle for %s" % (idleTime_mS) )
@@ -163,16 +163,15 @@ class Sweeper:
def getRelPos(self):
return self.relPos
-def testSweeper(sweeper):
+def testOnTicTk(sweeper):
print( sweeper.getPos() )
if sweeper.getPos() == sweeper.Npoints:
- print("Done")
+ print("Tk sweeper is done")
sweeper.cmdStop()
sweeper.widget.destroy()
sweeper.widget.quit()
-if __name__ == '__main__':
- from tkinter import Tk
+def testSweeperTk():
root=Tk()
root.geometry("800x600")
root.withdraw(); # do not show window
@@ -180,7 +179,16 @@ if __name__ == '__main__':
Np = 10
SweepTime = Np
print(f'Test sweeper: you should see a sequence of {Np} numbers updating about every {SweepTime/Np} seconds')
- sweeper = Sweeper(root, Npoints=Np, SweepTime=SweepTime, onTicCallbacks=[testSweeper])
+ sweeper = Sweeper(root, Npoints=Np, SweepTime=SweepTime, onTicCallbacks=[testOnTicTk])
sweeper.cmdStart()
root.mainloop()
+
+if __name__ == '__main__':
+ try:
+ from tkinter import Tk
+ testSweeperTk()
+ except ModuleNotFoundError:
+ print("Tk module not found, skipping testSweeperTk")
+ print("Done with tests")
+