<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.4%2FDevelopers%2FSlicelets</id>
	<title>Documentation/4.4/Developers/Slicelets - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.4%2FDevelopers%2FSlicelets"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.4/Developers/Slicelets&amp;action=history"/>
	<updated>2026-05-16T10:24:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.4/Developers/Slicelets&amp;diff=40439&amp;oldid=prev</id>
		<title>UpdateBot: Nightly -&gt; 4.4</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.4/Developers/Slicelets&amp;diff=40439&amp;oldid=prev"/>
		<updated>2014-12-25T06:52:22Z</updated>

		<summary type="html">&lt;p&gt;Nightly -&amp;gt; 4.4&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;{{documentation/versioncheck}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Slicelets=&lt;br /&gt;
&lt;br /&gt;
Slicer application user interface is very rich and complex, to allow free experimentation with all available tools. However, if Slicer is used for implementing a well-defined workflow, it is more efficient to develop a custom user interface, that only shows the required user interfaced, in a streamlined, simplified fashion.&lt;br /&gt;
&lt;br /&gt;
Slicelets are special Slicer modules that can provide full user interface, which can be used instead of Slicer's main application user interface.&lt;br /&gt;
&lt;br /&gt;
==Runnning a slicelet==&lt;br /&gt;
&lt;br /&gt;
There are not too many differences between slicelets and regular module. In fact, any regular module can be run standalone, without the main application user interface. The ''--no-main-window'' command-line argument has to be specified to prevent showing the main application user interface and ''--python-code'' has to be provided to start the module.&lt;br /&gt;
&lt;br /&gt;
For example, to show the Command line module &amp;quot;Add&amp;quot;, you could use (note: on Windows replace ''./Slicer'' by ''Slicer.exe''):&lt;br /&gt;
&lt;br /&gt;
  ./Slicer --no-main-window --python-code &amp;quot;slicer.modules.add.widgetRepresentation().show()&amp;quot;&lt;br /&gt;
&lt;br /&gt;
.... to show a Loadable module, you could use:&lt;br /&gt;
&lt;br /&gt;
  ./Slicer --no-main-window --python-code &amp;quot;slicer.modules.models.widgetRepresentation().show()&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In general, additional user interface elements need to be added if a module is used without the main application user interface, for example for loading data and saving the results. A simple example is the Label Statistics module, which can run as a regular module in Slicer but also can be started as a Slicelet. When it is started as a slicelet, it has buttons for loading input data:&lt;br /&gt;
&lt;br /&gt;
  ./Slicer --no-main-window --python-code &amp;quot;slicer.modules.labelstatistics.widgetRepresentation().show()&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A slicelet implemented in python can be started from a custom location (the advantage is that the module does not have to be added to the Slicer module paths, but a disadvantage is that the module location has to be known):&lt;br /&gt;
&lt;br /&gt;
  ./Slicer --no-main-window --python-script lib/Slicer-4.3/qt-scripted-modules/LabelStatistics.py  &lt;br /&gt;
&lt;br /&gt;
The line may be too complex to enter each time to start a slicelet. Either a shortcut or batch file can be created that runs the command or the command-line arguments can be hardcoded in the Slicer application settings:&lt;br /&gt;
&lt;br /&gt;
Edit SlicerLauncherSettings.ini. &lt;br /&gt;
&lt;br /&gt;
Before:&lt;br /&gt;
  ...&lt;br /&gt;
  [Application]&lt;br /&gt;
  path=&amp;lt;APPLAUNCHER_DIR&amp;gt;/bin/./SlicerQT-real&lt;br /&gt;
  arguments=&lt;br /&gt;
  ...&lt;br /&gt;
&lt;br /&gt;
After:&lt;br /&gt;
  ...&lt;br /&gt;
  [Application]&lt;br /&gt;
  path=&amp;lt;APPLAUNCHER_DIR&amp;gt;/bin/./SlicerQT-real&lt;br /&gt;
  arguments=--no-main-window&lt;br /&gt;
  ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Doing so, you wouldn't have to type the argument --no-main-window each time.&lt;br /&gt;
&lt;br /&gt;
Similarly, you could also include the --python-code &amp;quot;...&amp;quot; arguments into the launcher settings file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, instead of adding the &amp;quot;--python-code&amp;quot; argument into the launcher settings, you could create a file named .slicerrc.py inside your home folder with the following content:&lt;br /&gt;
&lt;br /&gt;
  modules = [&amp;quot;add&amp;quot;, &amp;quot;models&amp;quot;, &amp;quot;labelstatistics&amp;quot;]&lt;br /&gt;
  for module in modules:&lt;br /&gt;
    getattr(slicer.modules, module).widgetRepresentation().show()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Slicelet examples==&lt;br /&gt;
[[image:SliceletSampleScreenshot.png|thumb|200px|SliceletTest example (slicelet with a single image viewer)]]&lt;br /&gt;
&lt;br /&gt;
Simple example: [https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/LabelStatistics/LabelStatistics.py Label Statistics module], see [[media:LabelStatisticsSlicelet.png|screenshot]]&lt;br /&gt;
&lt;br /&gt;
Simple example with image viewer (see screenshot on the right): [https://www.assembla.com/code/slicerrt/subversion/nodes/1931/trunk/SlicerRt/sandbox/SliceletTest SliceletTest]&lt;br /&gt;
&lt;br /&gt;
More complex example: [https://www.assembla.com/code/Scoliosis/subversion/nodes/52/trunk/Scoliosis/src/ScoliosisMonitoring/ScoliosisMonitoring.py ScoliosisMonitoring]&lt;br /&gt;
&lt;br /&gt;
==User interface examples==&lt;br /&gt;
&lt;br /&gt;
Three modules are within a tab widget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import qt&lt;br /&gt;
import __main__&lt;br /&gt;
&lt;br /&gt;
tabWidget = qt.QTabWidget()&lt;br /&gt;
&lt;br /&gt;
modules = [&amp;quot;add&amp;quot;, &amp;quot;models&amp;quot;, &amp;quot;labelstatistics&amp;quot;]&lt;br /&gt;
for module in modules:&lt;br /&gt;
  tabWidget.addTab(getattr(slicer.modules, module).widgetRepresentation(), module)&lt;br /&gt;
&lt;br /&gt;
tabWidget.show()&lt;br /&gt;
&lt;br /&gt;
__main__.tabWidget = tabWidget # Keep track of the widget to avoid its premature destruction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, to create a small UI including:&lt;br /&gt;
- a 3D view&lt;br /&gt;
- a button to load data&lt;br /&gt;
- a tab widget&lt;br /&gt;
- a module selector allowing to add any module to the tab widget&lt;br /&gt;
... the following could be done:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def onModuleSelected(modulename):&lt;br /&gt;
  global tabWidget&lt;br /&gt;
  tabWidget.addTab(getattr(slicer.modules, modulename.lower()).widgetRepresentation(), modulename)&lt;br /&gt;
&lt;br /&gt;
import qt&lt;br /&gt;
import __main__&lt;br /&gt;
&lt;br /&gt;
mainWidget = qt.QWidget()&lt;br /&gt;
vlayout = qt.QVBoxLayout()&lt;br /&gt;
mainWidget.setLayout(vlayout)&lt;br /&gt;
&lt;br /&gt;
layoutManager = slicer.qMRMLLayoutWidget()&lt;br /&gt;
layoutManager.setMRMLScene(slicer.mrmlScene)&lt;br /&gt;
 layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView)&lt;br /&gt;
vlayout.addWidget(layoutManager)&lt;br /&gt;
&lt;br /&gt;
hlayout = qt.QHBoxLayout()&lt;br /&gt;
vlayout.addLayout(hlayout)&lt;br /&gt;
&lt;br /&gt;
loadDataButton = qt.QPushButton(&amp;quot;Load Data&amp;quot;)&lt;br /&gt;
 hlayout.addWidget(loadDataButton)&lt;br /&gt;
loadDataButton.connect('clicked()', slicer.util.openAddVolumeDialog)&lt;br /&gt;
&lt;br /&gt;
saveDataButton = qt.QPushButton(&amp;quot;Save Data&amp;quot;)&lt;br /&gt;
hlayout.addWidget(saveDataButton)&lt;br /&gt;
saveDataButton.connect('clicked()', slicer.util.openSaveDataDialog)&lt;br /&gt;
&lt;br /&gt;
moduleSelector = slicer.qSlicerModuleSelectorToolBar()&lt;br /&gt;
moduleSelector.setModuleManager(slicer.app.moduleManager())&lt;br /&gt;
hlayout.addWidget(moduleSelector)&lt;br /&gt;
moduleSelector.connect('moduleSelected(QString)', onModuleSelected)&lt;br /&gt;
&lt;br /&gt;
tabWidget = qt.QTabWidget()&lt;br /&gt;
vlayout.addWidget(tabWidget)&lt;br /&gt;
&lt;br /&gt;
modules = [&amp;quot;add&amp;quot;, &amp;quot;models&amp;quot;, &amp;quot;labelstatistics&amp;quot;]&lt;br /&gt;
for module in modules:&lt;br /&gt;
  onModuleSelected(module)&lt;br /&gt;
&lt;br /&gt;
mainWidget.show()&lt;br /&gt;
&lt;br /&gt;
__main__.mainWidget = mainWidget # Keep track of the widget to avoid its premature destruction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
</feed>