convert uses of QTimer.singleShot to QTimer instances

On macOS and Linux with PyQt bindings, QTimer.singleShot continues
to fire on python interpreter shutdown.
This commit is contained in:
KIU Shueng Chuan 2021-03-01 13:45:00 +08:00
parent 1ad7d49908
commit 85e894dd73
2 changed files with 12 additions and 3 deletions

View File

@ -36,6 +36,10 @@ i = 0
updateTime = ptime.time()
fps = 0
timer = QtCore.QTimer()
timer.setSingleShot(True)
# not using QTimer.singleShot() because of persistence on PyQt. see PR #1605
def updateData():
global img, data, i, updateTime, fps
@ -43,7 +47,7 @@ def updateData():
img.setImage(data[i])
i = (i+1) % data.shape[0]
QtCore.QTimer.singleShot(1, updateData)
timer.start(1)
now = ptime.time()
fps2 = 1.0 / (now-updateTime)
updateTime = now
@ -51,7 +55,7 @@ def updateData():
#print "%0.1f fps" % fps
timer.timeout.connect(updateData)
updateData()
## Start Qt event loop unless running in interactive mode.

View File

@ -61,6 +61,10 @@ wave_speed = 0.3
wave_length = 10
color_speed = 0.3
timer = QtCore.QTimer()
timer.setSingleShot(True)
# not using QTimer.singleShot() because of persistence on PyQt. see PR #1605
i=0
def updateData():
global i
@ -74,8 +78,9 @@ def updateData():
new_z)
i += wave_speed
QtCore.QTimer.singleShot(1000//fps, updateData)
timer.start(1000//fps)
timer.timeout.connect(updateData)
updateData()
## Start Qt event loop unless running in interactive mode.