Tutorials:CallbackExamples
From OpenRAVE
Running the Example
python:
openrave.py --example testviewcallback
Description
from openravepy import * from numpy import * ghandle = None # called whenever the mouse is pressed def itemselectioncb(link,pos,org,env): global ghandle print 'in python: body ',link.GetParent().GetName(),':',link.GetName(),'at',reshape(pos,(3)) # store the plotted handle in a global variable, or otherwise it will get deleted ghandle = env.plot3(points=reshape(pos,(3)),pointsize=25.0,colors=array((1,0,0))) # tell the viewer to not handle the selection return 0 if __name__=='__main__': env = Environment() env.Load('data/lab1.env.xml') env.SetViewer('qtcoin') # register the callback handle = env.GetViewer().RegisterCallback(Viewer.ViewerEvents.ItemSelection, lambda link,pos,org: itemselectioncb(link,pos,org,env)) raw_input('In selection mode, click anywhere on the viewer. Press any key to quit: ')

