You can use the vizact.ontimer function to update the stop watch time. I created a simple wrapper class around this for starting/stopping the watch. Here is the sample script:
Code:
import viz
viz.go()
class StopWatch(object):
def __init__(self):
self.time = 0.0
self._timer = vizact.ontimer(0,self._updateTime)
self._timer.setEnabled(False)
def _updateTime(self):
self.time += viz.elapsed()
def start(self):
self._timer.setEnabled(True)
def stop(self):
self._timer.setEnabled(False)
def toggle(self):
self._timer.setEnabled(viz.TOGGLE)
#Create stop watch object
watch = StopWatch()
#Spacebar toggles stop watch
vizact.onkeydown(' ',watch.toggle)
#Create text object to display watch time
text = viz.addText('',parent=viz.ORTHO,fontSize=40)
#Setup timer to update text object with watch time every frame
def DisplayTime():
text.message('%.2f'%(watch.time))
vizact.ontimer(0,DisplayTime)