Workflow that brings together a few modules as tabs in a unifying parent module.

That said, if complete UI of modules need to be composed together. One could use, the function createNewWidgetRepresentation()

For example:

w = slicer.modules.gaussianblurimagefilter.createNewWidgetRepresentation()
w.show()

w = slicer.modules.segmenteditor.createNewWidgetRepresentation()
w.show()

I was not going to go there :slight_smile: but the solution I inherited (below) has some similarity to what you suggested and then I noticed that “my” version caused the UI creation code to be called twice, realized it was ugly causing me to start this thread. Looking into your variation which uses “show”. Also thinking that since I am authoring the tabbed modules I should consider Andras’ advice by making those “more” re-usable. Thank you

Triggers UI creation

igtConnection = slicer.modules.igtconnection.createNewWidgetRepresentation()
self.igtConnectionModule = IGTConnection.IGTConnectionWidget(igtConnection)
self.tabWidget.addTab(self.qWidget1, "IGT Connection")
# Triggers UI creation again bad?
self.igtConnectionModule.setup(qFormLayout1)

Been thinking about what you wrote. Imagine a module called SandBox, a template generated with the python script found in the Slicer 3D source tree. It produces the classes SandBox, SandBoxWidget, SandBoxLogic, SandBoxTest.

So do you recommend that I create a new class say SandBoxWidgetUI with mostly GUI stuff and use it in another module like this?
import SandBox
sdb=SandBox.SandBoxWidgetUI()

It seems that the names SandBox, SandBoxWidget, SandBoxLogic, SandBoxTest are special and Slicer looks for these functions and makes them available via slicer.modules… unlike my new SandBoxWidgetUI class. I could alternatively reorganize the existing SandBoxWidget() class to make it more useful from another module but that seems less flexible as I would inherit other bits like a constructor I might not need.

For complex GUI, you can use Qt designer to create a .ui file and instantiate the widget from that.

I like the idea of having a “UI” class be part of the auto-generated module code. It would encourage best practices. It would mean updating the templates.

I haven’t thought about promoting using .ui files to the general public, but I agree that it could work well.

To make Qt designer (with all custom ctk, qMRML, Slicer widgets) available without requiring users to install a compatible version of Qt, we would need to bundle Qt designer binaries in the installation package. It should be no problem, as it requires only a few extra files of a total size of 6 MB (designer.exe, Qt5Designer.dll, and Qt5DesignerComponents.dll; Qt designer plugins are already included). @jcfr what do you think?

In addition to bundling designer executable, we should add an “Edit .ui file” button to the Reload&Test section and add an ExtensionWizard template.

That seems reasonable.

Additional libraries would have to be listed here and designer executable could be installed using approach done for QtWebEngineProcess.

And if build system not already take care of fixing up the executable … we may have to do something specific.

Wow, bundling Qt Designer with Slicer is a fascinating idea. That could be convenient for everyone, but I also imaging there’s a category of people who might contribute to the ui who wouldn’t think of doing it in C++ or Python but would like using the designer.

I suppose the logical next step would be including all of Qt Creator? We need to draw the line somewhere but this could be an optional install or developer extension.

I’ve tried to update the current scripted module template to use a .ui file to generate GUI and it worked really well. It reduced and simplified the code a lot.

Reload works nicely: to update the GUI, it is enough to save the .ui file in Qt Designer and click Reload in Slicer.

Widget variables can be automatically exposed as self.ui.myWidget (similarly how variables are accessible in C++ by generating a skeleton file).

I’ve submitted a pull request so that you can have a look: https://github.com/Slicer/Slicer/pull/1072/files#diff-c12bcbe4f4bab89847136fc032496bd4R36

@jcfr It works so nicely that I think it would worth the time adding designer to the package. Could you have a look? If it’s very easy then it might make sense to include it in 4.10.1.

1 Like

My group has been using Qt Designer for generating UI files and using them in our Slicer python code using slicer.util.loadUI() for well over a year now. Qt Designer definitely helps with quick prototyping of GUIs and we generally prefer this unless the widget is something extremely simple. For beginners, coding QLayout policies and such is really intimidating and difficult to understand without playing around with something like Qt Designer.

1 Like

I think it is also valuable to maintain the simple template that can be generated via the python script which Jean-Christophe Fillion-Robin et Steve Pieper wrote some years ago. I also think that said script should be in some bin directory associated with slicer binary as well so you don’t have to download the source to get it. It gives you a quick path to writing a “hello world” module.

We’ll maintain both scripted module templates (the current one where GUI is created by scripting, and the new one where GUI is loaded from .ui file). ExtensionWizard module can generate modules from these templates.

1 Like

Following r27706, Qt designer is expected to be packages on the three platform.

On Linux and Windows, it should be started using ./Slicer --designer, on macOS, it should be directly started.

Thinking more about it, we will have to generate a dedicated launcher (similarly to what is done for Python) because we must set variables like QT_PLUGIN_PATH also on macOS

1 Like

If module UI file is found then a new button “Edit UI” appears in Reload&Test section of scripted modules. That button relies on a slicer.util function that uses Slicer --designer to launch the designer. So, it would be great if this would work on all platforms.

Currently, the button is only shown for non-installed Slicer. Now that designer is bundled with installed Slicer, too, the button should be shown for installed Slicer as well. @jcfr please make the change (I’m traveling).

Agreed. The next set of commits should enable that.

1 Like

In addition of supporting Slicer --designer where the Slicer launcher is available, the cross-platform approach to start Qt designer is to run SlicerDesigner executable found in the bin directory.

It was needed to configure a launcher because on macOS it is not possible to run ./Slicer --designer from an install tree.

Based on tomorrow nightly build, we may have to tweak the packaging of designer on Windows and macOS. After this is tested, we will initiate the 4.10.1 release process.

Just an FYI to all, I have recently stumbled upon this issue.

I will work on a fix, but until then, the slicer.util.loadUI() approach can’t load re-usable widgets from extensions.

1 Like

Looking at someone else’s code and noticed that they use ScriptedLoadableModuleWidget.setup(self). If one starts from the python generated module template this function is not called and the template instead has code to produce a reload button reload and test button and connections and a method to reload modules.

The older templates included the developer section, but now they use the superclass:

Is that not working?