Creating a 3D Slicer extension with minimal programming skills

I’ve created a small example project of a slicelet (3D Slicer running with a simplified GUI) that you might find useful. It is only for loading an image, segmenting it, and saving the result. See more details here: Documentation/Nightly/Developers/Slicelets - Slicer Wiki

You can easily customize everything and can switch between simplified/full Slicer GUI by adding a keyboard shortcut.

Wow that’s a lot of information from everyone, thanks !

This is quite exactly what I need indeed ! And I managed to adapt it to the Qt created Widget in Andras’ Slicelet example ! That is so great !

Yes I saw it before but I didn’t have the knowledge to understand it, now I do understand a lot more! This is very useful and very close to what I want to achieve, thank you!

I am testing it and there are a few things I notice :

  • My Slicer seems to run a bit slower when using the module, is it to be expected?
  • When I run it, and then I load or select a DICOM file in the Database, I don’t find a way to come back to the module page. Is there any way for me to add the icon of the module in the toolbars? So that the user can come back to it? I have tried to edit the code in the showSingleModule section (adding lines in keeptoolbars, commenting others underneath,…) but didn’t succeed.
  • the same way, I would like to show the ToolBars to control the views and the 3D (switching between views, navigating through the Slices, etc…) but commenting the slicer.util.setViewControllersVisible(not singleModule) line doesn’t seem to work

I think the Slicelet example is a great base for me to learn and do trials to achieve what I want ! thank you !

It is exactly the same Slicer (just some widgets are hidden), so it should not be any slower. If it is indeed slower then maybe there are some error/warning messages flooding the application log - you will see it when you check the logs.

All the other things that you describe should work, probably there are just some trivial errors. You can find them easily by attaching a Python debugger (PyCharm, Visual Studio Code, …) and step through your code line by line.

Okay I see, then it was also maybe my computer struggling a bit!

Since then, I managed to handle a lot better the interface changes and I’m starting to build a fairly satisfying interface for my use. But I still didn’t find the way to add an icon to get back to the module on the toolbar (to come back from the DICOM database), neither a way to display the navigating tool for the axis and 3D view displays (usually there is a slider with also a pin to show various options to switch between files, etc…) Is it possible to get these two things back on the interface by modifying the ToolBar section in the code?

image

Around there I guess? Did various tries without success…

You can add a button that switches the active module and/or changes the view layout (that shows slice and 3D views instead of the DICOM browser). You can find examples in the script repository.

You can show/hide view controllers by calling setViewControllersVisible.

Thanks ! It worked and I understand a lot better how the hide/show works.

I have searched the repository but I don’t think that what I want is adding a view layout. To be precise, what I am trying to do is displaying the “Favorite Modules” toolbar, and if possible edit it to display only my module or at least adding my module to the list through Python. I don’t know if I can do that. I have been trying to do the same hide/show manipulation as for the other toolbars but I don’t find the right way to call it and I wasn’t able to find any documentation on that.

I am getting really close to what I want so thanks for the patience ! Helps a lot

DICOM browser is shown in the view layout that’s why changing the view layout may be useful (you can be in the DICOM module and show the browser or show slice&3D viewers).

You may show the favorites toolbar (using standard Qt functions or convenience methods in slicer.util) but if you know exactly which modules you want to use then you can have a simpler, more compact GUI by placing a few buttons for switching between modules.

I am not sure I understand it correctly. What you mean by “view layout” is the toolbar just under File/Edit/View/Help, or is it the place where you can chose different layouts for the 2D and 3D views like “Four up” “Only 3D” etc?

Yes that’s exactly what I need ! But the thing is that I didn’t manage to add a button at the same level as the DICOM Database button so that it stays there when I switch.
image
I want to add a button there, can be through Python to avoid building a higher level window with Qt…

By view layout I mean four-up, red slice only, dicom browser, etc.

You don’t need the favorite toolbar, you can hide it and instead add buttons for switching between modules. If you prefer to have a tool bat then you can of course do that, too. Just make sure to set the Favorites toolbar visibility to True.

Yeah if I can avoid the favorite toolbar I will, the thing is I didn’t find the syntaxe to add a button at the level I showed (which doesn’t appear in Qt Designer) or the right way to right the line for the Favorites Toolbar set visible either. I am not familiar with the “old” way to create GUI elements but I feel it’s what I need for this particular button

You can only save space if you remove all the toolbars (then the toolbar area disappears). List of toolbars are specified here:

So, either add ModuleToolBar there or remove all the other toolbars and create a row of buttons using Qt designer.

Hello.

I´d recommend to go
→ Developer Tools → Extension Wizard

image

This helpful tool will put up a development system within slicer and comes with a working templet of a simple extension with it´s own GUI.

You can edit the python code in a text editor of your coice and play around with the GUI after editing it in the in the QT designer.

image

Reload the extension from within slider and directly test your changes, All basic and necessary functions for a slicer extension are included. But you will need to write some lines of code …

Best regards

Rudolf

1 Like

Okay ModuleToolBar is indeed what I tried to find, at least I got the Favorites so it’s quite good enough for now. The next step would be to set my Slicelet to be the only module in here I guess but that’s not urgent to do. Thanks a lot anyway !!

1 Like

Thank you very much Rudolf ! Indeed I have seen this tool and tried it a few times ! I found more convenient to use the QuickSegment Slicelet mentionned by @lassoan tho because it was closer to what I want to achieve.

Hey Vincebisca,

I’m a student who is also working on creating a custom application with a custom workflow and starting to learn everything. If it’s okay with you, could I ask you some questions before I get started? I feel a bit overwhelmed with learning everything at the moment and would love to receive some advice/help from you.

Many thanks

Sean

Hello !

I’ve been there so I know :wink: if I can help you I will do so gladly ! I think that reading this thread might help you a great deal ! I am not a developper and all I am capable of doing is fiddling around with the extension template and slicelet template that are available. Anyway feel free to ask !

Vincent

Hey Vincent! Thanks so much

Actually I’m not a professional developer either which is why I’m struggling too LOL
Anyway, similar to your case, I’m also looking to optimize my workflow, as my project only requires specific modules (ALPACA, Model-to-model distance, and ShapePopulationViewer, and Models). So my goal would be to recreate a custom GUI using only these features.

How did you go about this? Did you primarily use QtDesigner? Did you create a custom slicelet/guidelet? It’d be great if you could give an overview, and maybe if it’s okay with you, share your template with maybe a few screenshots as I have no idea where to start.

Thank you so much

Ok just to be sure: do you want to use the modules as they are? Like you only need to show the modules in the upper toolbar? In that case you could just modify the “favorite modules” on your Slicer.

If you want to merge the use and create your own module that take advantage internaly of the modules you mentioned, then you should check the answer above :

This will give you a template of Slicelet for 3D Slicer, from there you can activate the Editor Mode of 3D Slicer and modify directly the QtDesigner Interface created in the Slicelet (basically a blank one, but it’s created and linked) and you can edit the code to slowly add what you need. Using this template you have at least something that is already functionnal in terms of base settings !

Thanks Vincent! How can I run this slicelet on my mac? I’ve downloaded the .zip file on github but not sure where to go from there. And yes I’m looking to merge the user and create my own model.

Btw can I ask what platform you use? MacOS or window?
As I’m having trouble launching QtDesigner on my mac.