Mouse click to open selected segment in Segment Editor

Operating system: Windows 10
Slicer version: 5.0.3


I have a Slicer extension built that creates 2D segmentations. I want the user to be able to highlight the segments when they hover with their mouse and when they click on the segments to open up Slicer’s Segmentation Editor allowing the user to further edit the segments as necessary.

Currently, I’m using this code to get the user’s mouse position and I’m able to highlight the hovered segment based on that. Now, I’d like it so that if the user clicks on that hovered segment, the Segmentation Editor opens. I’d appreciate any guidance on how I would proceed about doing that. Thanks!

You can switch to the Segment Editor module and select a segmentation / segment like this:

segmentationNode = getNode('Segmentation')
segmentID = "Segment_2"

However, instead of switching between modules, I would recommend to offer all features that your users need in your module. You can easily embed a Segment Editor widget inside your own module (you can use the Segment Editor module in Slice core as an example of how to embed the Segmen Editor widget into a Pythons scripted module). You can put the widget into a collapsible section to only take up space when needed.

1 Like

Thanks for the fast response and the suggestion, I’ll keep that in mind!

For the code you provided, if I wanted to get the string “Segment_2” after the user left clicks the segment region once in the transverse section view, how would I go about doing that using Python. Thanks again!

See this example in the script repository.