Change active widget

I am curious if there is a way to jump from one module to another programmatically using Python.

I have a module in which several automatic segmentations were generated. I would like to give an easy option for the user to jump into the SegmentEditor widget - which was previously configured by certain parameters - showing a certain segmentation over a given master volume.

So far I have tried this:

self.segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
self.segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
self.segmentEditorNode =slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
self.segmentEditorWidget.setMRMLSegmentEditorNode(self.segmentEditorNode)

then later on

self.segmentEditorWidget.show()

but this shows the widget inside a floating window.

So the question is, what is the right way, to show a docked version of the parametrized SegmentEditorWidget?

This is the expected behavior when creating a new widget, unless you integrate it into the layout of your module. I think what you want is to configure the existing segment editor widget instance, then jump to the segment editor module.

segmentEditorWidget = slicer.modules.SegmentEditorWidget.editor
# setup things ...
segmentEditorWidget.setActiveEffectByName("Threshold")

switch to module
slicer.util.selectModule("SegmentEditor")

2 Likes

As you said this needs an existing segment editor widget. But it is instantiated only if the user opens the segment editor module previously. By opening the segment editor, 3 nodes are generated: a vtkMRMLSegmentEditorNode, a vtkMRMLSegmentationNode, and a vtkMRMLSegmentationDisplayNode.

By calling

slicer.util.selectModule("SegmentEditor")

later on, will show this instance of the segment editor - not the one I have instantiated manually.

So the question still remains, but a bit altered:
How can one create all these three nodes, without opening the segment editor?

Since then I have 2 solutions: switching back and forth between the segment editor and my module, or switching to the segment editor - which ensures that there is an instance I can parameterize - and then make the changes I want to.