I am trying to use a timer with pyqt. The code is below, but it does not print anything and I do not get an error. Does anyone know what is wrong?
Thanks
import functools
from PyQt4.QtCore import QTimer
def onTimer(initParams):
print initParams
print "HERE"
# your code here...
def update():
print "Upd"
myInitParams = "Init!"
timerCallback = functools.partial(onTimer, myInitParams)
myTimer = QTimer()
myTimer.timeout.connect(timerCallback)
myTimer.start(1000) #once a sec
t = QTimer()
t.start(500)
t.timeout.connect(update)
EDIT UPDATE:
So this is a snip of the full code im using, which is a bit more complicated and maybe is a different problem, but the result is the same.
The structure is like this:
from PyQt4 import QtCore, QtGui
# Import the UI Classes from the ui directory in this package
from ui.MoAnGUI import Ui_MoAnWindow
class MoAnWin(QtGui.QDialog, Ui_MoAnWindow):
def __init__(self, parent=None):
super(MoAnWin, self).__init__(parent=parent)
self.setupUi(self)
self.playMarkers.clicked.connect(self._PlayMarkers)
self.connect(self,QtCore.SIGNAL("PlayMarker"),PlayMarkerCall)
#Marker Stop
self.stopMarkers.clicked.connect(self._StopMarkers)
self.connect(self,QtCore.SIGNAL("StopMarker"),StopMarkerCall)
def _StopMarkers(self):
arg = "Stop"
self.emit(QtCore.SIGNAL("StopMarker"),arg)
def _PlayMarkers(self):
fps = self.fpsBox.value()
starttime = self.fromTime.value()
endtime = self.ToTime.value()
arg = [fps,starttime,endtime]
self.emit(QtCore.SIGNAL("PlayMarker"),arg)
def StopMarkerCall(arg):
#I want to stop the timer here
def PlayMarkerCall(arg):
#I tried this, but again, nothing happens, no error
myInitParams = "Init!"
timerCallback = functools.partial(TimerCall, myInitParams)
myTimer = QtCore.QTimer()
myTimer.timeout.connect(timerCallback)
myTimer.start(1000) #once a sec
#I Imagine something like this:
myTimer = QtCore.QTimer()
for i in range(start,end):
# I want to connect to my view marker function but i need to pass a variable
myTimer.timeout.connect(ViewMarkerCall(i))
myTimer.start(1000)
def TimerCall(args):
print "HERE", args
def show():
global globalMoAnWindow
app = QtGui.QApplication(sys.argv)
globalMoAnWindow = MoAnWin()
globalMoAnWindow.show()
sys.exit(app.exec_())
return globalMoAnWindow
show()
My goal is to have a button click play, and stuff happens in a qtgraphic widget at a certain time interval, then the stop button stops the playing. I found the functools from another question on here, but im not sure if its the correct thing to do.