I'm trying to get an event when my mouse is hovering an isosurface in a vispy scene (the goal is to display a text next to this isosurface).
Here's my code:
import sys
from vispy import scene
from vispy.scene.visuals import Text
canvas = scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()
isosurface = scene.visuals.Isosurface(Ld level=Ld.max()/2.,
color=(0.4, 0.6, 1, 1),
shading='smooth',
parent=view.scene)
text = Text("", color='white', font_size=14, bold=True)
text_box = scene.visuals.Rectangle(color=(0, 0, 0, 0.7), radius=4, parent=view.scene)
text_box.transform = scene.transforms.STTransform(translate=(10, 10))
def on_mouse_move(event):
if isosurface.contains(event.pos):
text.text = "Texte à afficher"
text_box.visible = True
else:
text.text = ""
text_box.visible = False
canvas.events.mouse_move.connect(on_mouse_move)
if __name__ == '__main__':
if sys.flags.interactive != 1:
canvas.app.run()