Probably not the most elegant solution, but one that's short and working:
Code:
wind = False
tree.runAction(vizact.animation(1))
def onKeyDown(key):
global wind
if key == " ":
wind = True
tree.runAction(vizact.animation(3))
def onActionEnd(e):
global wind
if e.object is tree:
if wind:
wind = False
else:
anim = vizact.animation(random.choice([1,5,6]))
tree.runAction(anim)
viz.callback(viz.ACTION_END_EVENT,onActionEnd)
viz.callback(viz.KEYDOWN_EVENT, onKeyDown)