mouseclick1.py 819 B

123456789101112131415161718192021222324
  1. """Mouse click and other type of events
  2. will trigger a call to a custom function"""
  3. from vedo import printc, Plotter, Mesh, dataurl
  4. printc("Click object to trigger a function call", invert=1)
  5. # callback functions
  6. def on_left_click(event):
  7. if not event.object:
  8. return
  9. printc("Left button pressed on", [event.object], c=event.object.color())
  10. printc(event) # dump the full event info
  11. def on_drag(event):
  12. printc(event.name, 'happened at mouse position', event.picked2d)
  13. ######################
  14. tea = Mesh(dataurl+"teapot.vtk").c("gold")
  15. mug = Mesh(dataurl+"mug.ply").rotate_x(90).scale(8).pos(2,0,-.7).c("red3")
  16. plt = Plotter(axes=11)
  17. plt.add_callback('LeftButtonPress', on_left_click)
  18. plt.add_callback('Interaction', on_drag) # mouse dragging triggers this
  19. plt.show(tea, mug, __doc__).close()