I’m building some simple Slicer extension with Python and one of the things I want to implement in one of the modules is to add a widget to the ModuleToolBar. I’m currently doing this through this function:
def modifyWindowUI(self): mainToolBar = slicer.util.findChild(slicer.util.mainWindow(), 'ModuleToolBar') add_widget = True for element in mainToolBar.actions(): if element.text == "vCastSender": add_widget = False if add_widget: moduleIcon = qt.QIcon(self.resourcePath('Icons/BrainZoneClassifier.png')) self.StyleAction = mainToolBar.addAction(moduleIcon, "vCastSender") self.StyleAction.triggered.connect(self.toggleStyle)
And then I called this function in the setup function for the module:
def setup(self): """ Called when the user opens the module the first time and the widget is initialized. """ ScriptedLoadableModuleWidget.setup(self) # Custom toolbar for applying style self.modifyWindowUI() self._loadUI() self.logic = BrainZoneClassifierLogic() # Connections self._setupConnections()
So this is working fine but I’ve seen that the behaviour is that, after launching slicer, the icon is included in the toolbar until I select the module (in the modules dropdown). Is there a way to setup the module when Slicer is launched? Or is there any approach to have my module icon in the toolbar after Slicer is initialized (without the need of changing to the module tab)?