0

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()
Robert
  • 7,394
  • 40
  • 45
  • 64
Jonjon
  • 1
  • What is happening now? Any chance you could update your example with some fake data so I could run it? My best guess is that the SceneCanvas is not forwarding the mouse move event on. In general a non-clicked mouse move was expensive in the past so the event is not forwarded on to the user by default. You could try setting this private property of your canvas and see if it helps: `canvas._send_hover_events = True`. – djhoese Jun 27 '23 at 18:16

0 Answers0