diff options
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") |