I too thought of a way to introduce a callback, by using threads (this
is based on the scheme used in the graphing module, vis/graph.py, to
enable the feature that dragging the mouse shows crosshairs on a
graph).
from visual import *
import time
from threading import Thread, RLock
lock = RLock()
run = True
class timer(Thread): # This timer thread watches for mouse events.
def run(self):
global run
while True:
time.sleep(0.05)
lock.acquire()
if scene.mouse.clicked:
scene.mouse.getclick()
run = not run
lock.release()
b = box()
thr = timer()
thr.start()
while True:
rate(100)
if run: b.rotate(angle=.01, axis=(0,1,0))
|