I’m creating 2 layouts for manual segmentation. And I’m trying to create QtAction s to trigger these layouts (slicerrc.py-file can be found here):
# XML definitions (definitions omitted)
LAYOUTXML_MANUALSEGMENTATION_3D = "..."
LAYOUTXML_MANUALSEGMENATION = "..."
# out-of-the-blue values
LAYOUTID_MANUALSEGMENTATION_3D = 440
LAYOUTID_MANUALSEGMENTATION = 442
# switch layout
def setLayout(idx):
slicer.app.layoutManager().setLayout( idx )
# global variables to access our layout actions
actionSegmentation3D = None
actionSegmentation = None
# callback for action
def triggerLayoutManualSegmentation():
# set layout
setLayout( LAYOUTID_MANUALSEGMENTATION )
# callback for action
def triggerLayoutManualSegmentation3D():
# set layout
setLayout( LAYOUTID_MANUALSEGMENTATION_3D )
# callback for shortcut
def toggleLayoutManualSegmentation():
lm = slicer.app.layoutManager()
if lm.layout == LAYOUTID_MANUALSEGMENTATION_3D:
actionSegmentation.triggered()
else:
actionSegmentation3D.triggered()
# create our custom layouts, add actions in layout menu, create shortcut
def createCustomLayouts():
# create layouts
slicer.app.layoutManager().layoutLogic().GetLayoutNode().AddLayoutDescription( LAYOUTID_MANUALSEGMENTATION_3D, LAYOUTXML_MANUALSEGMENTATION_3D )
slicer.app.layoutManager().layoutLogic().GetLayoutNode().AddLayoutDescription( LAYOUTID_MANUALSEGMENTATION, LAYOUTXML_MANUALSEGMENTATION )
# create menu entries
global actionSegmentation3D
global actionSegmentation
actionSegmentation3D = mainWindow().findChild('QMenu', 'LayoutMenu').addAction( "Segmentation+3D" ) # TODO: create Icon: #.setIcon(qt.QIcon(':Icons/Go.png'))
actionSegmentation3D.setToolTip("Manual Segmentation")
actionSegmentation3D.connect('triggered()', lambda: triggerLayoutManualSegmentation3D() )
actionSegmentation = mainWindow().findChild('QMenu', 'LayoutMenu').addAction( "Segmentation" ) # TODO: create Icon: #.setIcon(qt.QIcon(':Icons/Go.png'))
actionSegmentation.setToolTip("Manual Segmentation, fullscreen")
actionSegmentation.connect('triggered()', lambda: triggerLayoutManualSegmentation() )
# create toggle shortcut
shortcutToggleSeg = qt.QShortcut( mainWindow() )
shortcutToggleSeg.setKey( qt.QKeySequence('g') )
shortcutToggleSeg.connect( 'activated()', lambda: toggleLayoutManualSegmentation() )
# set custom layout right now. this makes sure volumes are loaded into our custom Slice Views
#actionSegmentation3D.triggered() # TODO: enable when slicerrc.py works
createCustomLayouts()
However, I can’t get this working. And if I do actionSegmentation3D.triggered()
and then actionSegmentation.triggered()
in the Python console, Slicer hangs and stops working. What am I doing wrong? I don’t know Python, so help would be appreciated.