diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-13 00:09:33 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-13 00:09:33 -0400 |
commit | 4879c57b697b1c804971f8bd4abc3cea5530f2b8 (patch) | |
tree | 70c7f2a455b7288971f3e322da03169e5895cbec /funcGenerator.py | |
parent | c9db13448d4c28b69abac107b495d351558669f5 (diff) | |
download | pyExpControl-4879c57b697b1c804971f8bd4abc3cea5530f2b8.tar.gz pyExpControl-4879c57b697b1c804971f8bd4abc3cea5530f2b8.zip |
made Sweeper agnostic to either Tk or PyQt
Diffstat (limited to 'funcGenerator.py')
-rw-r--r-- | funcGenerator.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/funcGenerator.py b/funcGenerator.py index b4aa5f2..fdd56a5 100644 --- a/funcGenerator.py +++ b/funcGenerator.py @@ -123,7 +123,22 @@ class Sweeper: # this function modelled after Tk.after # it is execute 'cmnd' after idle time given in mS # idleTime_mS = 0 means execute immediately - self.widget.after(idleTime_mS, cmnd) + try: + # Tk style + self.widget.after(idleTime_mS, cmnd) + return + except AttributeError: + pass + + try: + # PyQt style + t = QtCore.QTimer() + t.singleShot( idleTime_mS, cmnd ) + return + except NameError: + pass + + raise Exception("Something went horribly wrong: we have no mechanism for Sweeper.after()") def cmdRestart(self): @@ -172,6 +187,7 @@ def testOnTicTk(sweeper): sweeper.widget.quit() def testSweeperTk(): + print("test Sweeper with Tk") root=Tk() root.geometry("800x600") root.withdraw(); # do not show window @@ -184,11 +200,36 @@ def testSweeperTk(): root.mainloop() +def testOnTicPyQtGraph(sweeper): + print( sweeper.getPos() ) + if sweeper.getPos() == sweeper.Npoints: + print("PyQtGraph sweeper is done") + sweeper.cmdStop() + sweeper.widget.exit() + +def testSweeperPyQtGraph(): + print("test Sweeper with PyQtGraph") + app = QtGui.QApplication([]) + + Np = 10 + SweepTime = Np + print(f'Test sweeper: you should see a sequence of {Np} numbers updating about every {SweepTime/Np} seconds') + sweeper = Sweeper(app, Npoints=Np, SweepTime=SweepTime, onTicCallbacks=[testOnTicPyQtGraph]) + sweeper.cmdStart() + + app.exec() + if __name__ == '__main__': try: from tkinter import Tk testSweeperTk() except ModuleNotFoundError: print("Tk module not found, skipping testSweeperTk") + + try: + from pyqtgraph.Qt import QtGui, QtCore + testSweeperPyQtGraph() + except ModuleNotFoundError: + print("pyqtgraph.Qt module not found, skipping testSweeperPyQtGraph") print("Done with tests") |