Interactor from old version to 4.10.2

Hi, i’m try to convert this code that was build for 3DSlicer 3.6 to the newest 3DSlicer 4.10.2, but i have some issues to define the interactor.
Can you help me?

self.RedSliceInteractor=slicer.ApplicationGUI.GetMainSliceGUI(“Red”).GetSliceViewer().GetRenderWidget().GetRenderWindowInteractor()
self.RedSliceLeftButtonReleaseTag=self.RedSliceInteractor.AddObserver(“LeftButtonReleaseEvent”,self.HandleClickInRedSlice)

This is a part of the function that needs the interactor:

def HandleClickInRedSlice(self):
if not self.Selecting:
return
coordinates = self.RedSliceInteractor.GetLastEventPosition()
ctrlKey = self.RedSliceInteractor.GetControlKey()

I’m trying to observe the mouse left-click on the Red Slice of 3DSlicer, and i have also to check if Ctrl-key is pressed and to take the coordinates on the image of the point pressed

Hi, i’m trying to update this code (build for 3DSlicer 3.6) for 3DSlicer 4.10.2 but i have some issues with the interactor. I want to observe the “LeftButtonReleaseEvent” when i press only on the Red Slice Viewer (in 3DSlicer).

self.RedSliceInteractor=slicer.ApplicationGUI.GetMainSliceGUI(“Red”).GetSliceViewer().GetRenderWidget().GetRenderWindowInteractor() self.RedSliceLeftButtonReleaseTag=self.RedSliceInteractor.AddObserver(“LeftButtonReleaseEvent”,self.HandleClickInRedSlice)

This is the first part of the function that i call above:

def HandleClickInRedSlice(self):
if not self.Selecting:
return
coordinates = self.RedSliceInteractor.GetLastEventPosition()
ctrlKey = self.RedSliceInteractor.GetControlKey()

So i want to obatin also the coordinates of the point where i clicked and i i pressed the Ctrl key.
Can you help me?

Interactors are hard. I would not recommend to implement features at such low level but instead utilize Markups widgets to define point positions, lines, curves, etc. See examples in script repository: https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulating_objects_in_the_slice_viewer

1 Like

Thanks for your suggestion. There’s a way to run a function when i create only one markup node with mouse-click? I tried to do something with AddObserver, but i found some issues.

See working examples in the script repository, for example: https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulating_objects_in_the_slice_viewer