Link slice views outside of slicerrc.py

I’m writing an extension and I would like that it automatically links the slice views. I know I can add it to .slicerrc.py, and this works, however, I wouldn’t want to ‘ship’ a custom .slicerrc.py together with my extension.

I tried to take the code from Set all slice views linked by default, put it in a function linkViews() in my MyExtension.py and add it to the the __init__() of class MyExtension(ScriptedLoadableModule) similarily to the sample data:
slicer.app.connect("startupCompleted()", linkViews)

However, this doesn’t work - it doesn’t throw any error - the code gets executed (if I add a print() it prints to the console) but the views remain unlinked.

Can this be done as part of an extension?

This is probably a timing issue - the startupCompleted signal comes after the windows already exist, while the slicerrc.py is processed during command line processing where the windows must not have been set up yet.

Can you try calling linkViews directly in the __init__()?

1 Like

Calling linkViews directly in the __init__() of MyExtension(ScriptedLoadableModule) doesn’t work.

However, it works when I call it in the __init__() of MyExtensionWidget(ScriptedLoadableModuleWidget, VTKObservationMixin) or MyExtensionLogic(ScriptedLoadableModuleLogic)