slicer.modules.SegmentEditorWidget does not exists anymore

I haven’t updated Slicer for a while, but now my .slicerrc does not work as usual. I have the line slicer.modules.SegmentEditorWidget.editor.findChild( "QWidget", "EffectsGroupBox" ), but in the newest Slicer version the SegmentEditorWidget is not there unless I have opened that module in Slicer window (for example by slicer.utils.selectModule( "SegmentEditor" )). However, opening that module creates a Segmentation node which I do not want.

How do I get access to the SegmentEditorWidget, without creating a Segmentation node?


My context: I use the following code in my startup file in order to set up shortcuts which I can access with my Wacom tablet menu:

def setupSegmentEditorShortcuts():
    # find buttons
    widget = slicer.modules.SegmentEditorWidget.editor.findChild("QWidget", "EffectsGroupBox")
    def addEffectShortcut(name, keysequence ):
        but = widget.findChild( 'QToolButton', name )
        shortcut = qt.QShortcut( mainWindow() ) # ^TODO: use SegmentEditorWidget for focused shortcut, does thtat work?
        shortcut.setKey( keysequence )
        shortcut.connect( 'activated()', lambda: but.click() )
    addEffectShortcut( "NULL", qt.QKeySequence( 'Shift+F4' ) )
    addEffectShortcut( "Paint", qt.QKeySequence( 'Shift+F5' ) )
    addEffectShortcut( "Draw", qt.QKeySequence( 'Shift+F6' ) )
    addEffectShortcut( "Erase", qt.QKeySequence( 'Shift+F7' ) )
    addEffectShortcut( "Scissors", qt.QKeySequence( 'Shift+F8' ) )
    # add shortcut for brush size
    qt.QShortcut( qt.QKeySequence( "Shift+F9"), mainWindow() ).connect( 'activated()', lambda: updateBrushSize( -1 ) )
    qt.QShortcut( qt.QKeySequence( "Shift+F10"), mainWindow() ).connect( 'activated()', lambda: updateBrushSize( 1 ) )

You can simply create a segment editor widget for your own purposes

segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)

then set a vtkMRMLSegmentEditorNode, segmentation node, source volume node, etc. just as you would with “the” segment editor widget. If you look at the Segment Editor module code, you’ll see that it’s basically a placeholder for a segment editor widget instance, which is completely reusable.

Using slicer.qMRMLSegmentEditorWidget()instead of slicer.modules.SegmentEditorWidget did not work. However, turned out that there is another way that works: slicer.util.getModuleWidget("SegmentEditor")

So now I am able to add my shortcuts again, and hence use my Wacom tablet for efficient segmentation works :slight_smile:

It is always useful to tell about your use case, because without it, one can only assume things and possibly give you an answer that does not help.