About the right click on mainwindow’s toolbar

Hi, how can I edit here?

1 Like

Can you be more specific please? What do you want to edit?

I’m using SlicerCAT right now and I would like to modify the default checked options in this dropdown menu. Can you guide me on how to configure which items are selected by default when the application starts.

You can do this for example:
slicer.util.mainWindow().findChildren('qMRMLCaptureToolBar')[0].visible = False

But there may be a better way to customize this.

The code
slicer.util.mainWindow().findChildren('qMRMLCaptureToolBar')[0].visible = False
works fine in 3D Slicer to hide the Capture/Restore Toolbar. However, in SlicerCAT, the setting doesn’t persist after restarting the application, and the toolbar reverts to its default visibility.

Do you know what the equivalent name is for the “Favorite Modules” in the code? For example, qMRMLCaptureToolBar is used for the Capture/Restore toolbar—what would it be for the Favorite Modules?

Did you try drag and drop the module you want to the favorites tab in user preferences?

I know how to add modules to Favorite Modules, so that’s not my question. I’m currently using SlicerCAT, and in SlicerCAT, the “Favorite Modules” section is not checked by default. I want to change this behavior. I have a few ideas to try, but I’m struggling to find the exact name used in the code to represent this section.

For instance, in the code, they used the name “qMRMLCaptureToolBar” to control the “Capture/Restore” functionality. Similarly, I’m looking for the name they used to represent the “Favorite Modules” section shown in the image below. Could anyone point me in the right direction?

As you begin your customization journey I would suggest reviewing the following technique:

https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html#how-to-find-a-python-function-for-any-slicer-features

Which would lead you to do the following search in the Slicer repository:

Which contains a result for the object name of the QToolBar for that has the display name of “Favorite Modules”.

Hi, thanks for your response. I’ve already added my own modules and buttons to SlicerCAT, but I’m facing an issue. Even though I’ve found the name of the “Favorite Modules” toolbar, my initial solution didn’t work as expected, so I need some help.

Here’s the situation: I’ve successfully added my custom modules and their buttons, and I’ve also included some 3D Slicer modules to the “Favorite Modules” section. However, in SlicerCAT, “Favorite Modules” is invisible by default. I need to right-click and manually enable them. I’d like to change this default behavior so that the modules are visible by default.

Additionally, I want to disable right-click functionality on the main toolbar to prevent users from modifying the module visibility. This would allow me to hide unnecessary modules from the users.

For reference, here is the source code of SlicerCAT:

It seems that the file previously named Example.py is now called Home.py.

I’ve been struggling to implement these changes. Do you have any suggestions or guidance on how I can achieve this?

Although you can look at SlicerCAT as an example, it is just a snapshot in time of what SlicerCustomAppTemplate produced over 3 years ago. The Home.py is what SlicerCustomAppTemplate currently creates and has last customization examples.

In the below linked code you can customize which toolbars are set as visible on startup.

^Regarding this type of customization it is something I’ve never done before. Editing toolbar visibility through right-click is standard Qt behavior. Since this would be standard Qt type customization not unique to Slicer you may be able to search on various Qt forums about how to accomplish this task.

If there are modules that you don’t need at all, you can modify your Slicer custom application to not include the modules in the first place rather than worrying about trying to hide them. This can be customized at:

Thanks for your response. I actually tried this earlier when you shared the object name for “Favorite Modules.” I believe it’s "ModuleToolBar". However, I tried it, and it didn’t work as expected. Here’s the code I used:

def setSlicerUIVisible(self, visible: bool):
    exemptToolbars = [
        "MainToolBar",
        "ViewToolBar",
        "ModuleToolBar",
        *self.toolbarNames,
    ]

    slicer.util.setDataProbeVisible(visible)
    slicer.util.setMenuBarsVisible(visible, ignore=exemptToolbars)
    slicer.util.setModuleHelpSectionVisible(visible)
    slicer.util.setModulePanelTitleVisible(visible)
    slicer.util.setPythonConsoleVisible(visible)
    slicer.util.setApplicationLogoVisible(visible)
    keepToolbars = [
        slicer.util.findChild(slicer.util.mainWindow(), toolbarName) 
        for toolbarName in exemptToolbars
    ]
    slicer.util.setToolbarsVisible(visible, keepToolbars)

For the CMakeLists.txt, you can see that almost everything is currently disabled. I always thought that we could manage the modules already listed in this file and toggle them between enabled or disabled. My question is: if I add an object name here, will it automatically disable the corresponding module? If that’s the case, I’ll need to identify the object name for every module I want to manage.

Here’s the current configuration of my CMakeLists.txt file:

# Enable Slicer built-in modules
set(Slicer_CLIMODULES_ENABLED
  ResampleDTIVolume             # Needed by ResampleScalarVectorDWIVolume
  ResampleScalarVectorDWIVolume # Depends on DiffusionApplications, needed by CropVolume
)

set(Slicer_QTLOADABLEMODULES_ENABLED
)

set(Slicer_QTSCRIPTEDMODULES_ENABLED
)

# Disable Slicer built-in modules
set(Slicer_CLIMODULES_DISABLED
)

set(Slicer_QTLOADABLEMODULES_DISABLED
  SceneViews
  SlicerWelcome
  ViewControllers
)

set(Slicer_QTSCRIPTEDMODULES_DISABLED
  DataProbe
  DMRIInstall
  Endoscopy
  LabelStatistics
  PerformanceTests
  SampleData
  VectorToScalarVolume
)

I’ll include two images below to show you the current version of my configuration and the target version I aim to achieve.

The version that I have right now looks like this. You can riğht click and enable what you want.

And this is the version that I want to achive, just these modules enabled (They are currently in Favorite Modules) and I don’t want any other thing. I want to start slicer and see this screen. And I don’t need any other functionality.

Have you confirmed that any edits to the Home.py are working? Have you tried a print statement of some sort to see if it gets executed. There may be a Home.pyc file which I believe you will need to delete first as that is the compiled version that is ultimately run. If no pyc version is present it goes back to using the py version of the file.

If you add a module to the disabled list I would expect that you would first new to delete the module contents that were copied into the Slicer build tree and then run the incremental build of Slicer again. I don’t believe the build process will remove module files already copied into the Slicer-build area. For sure if you run a completely new build of the application would it respect the updated module disabled list. Modifying the CMakeLists.txt and running the application without re-running the build won’t do anything.

1 Like