Documentation/Nightly/Developers/ModuleWizard
Contents
Background
Slicer modules typically consist of several files of various types, such as CMake files, source files, and binary files.
In many cases, the names of the files and the names of text strings inside the files are related and need to be in sync in order for things to compile.
Also, it is not uncommon to want to use one module as the starting point for implementing similar functionality.
Terminology
- The template is a directory containing a slicer module
- The templateKey is a text string, typically the name of the module, that is used in both filename and identifiers inside the module.
- The target is a directory where you want the new module to be placed
- The moduleName is the string that you want to use in place of the templateKey
Usage
ModuleWizard [--template <dir>] [--templateKey <key>] [--target <dir>] <moduleName> --template default ./Extensions/Testing/LoadableExtensionTemplate --templateKey default is dirname of template --target default ./Modules/Loadable/<moduleName>
Concepts
The idea of the wizard is to create a new self-contained directory that is a working module from the slicer perspective. This means that for C++ extensions, you only need to compile the extension and it will work with slicer. For scripted (python) extensions, you don't even need to compile.
Running this wizard will create the module in the specified target directory and will give it the name you specify on the command line.
For example, running this command:
./Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/ScriptedLoadableExtensionTemplate --target ../MyBorExtension MyBorExtension
should be done from within the slicer source directory, so that the ModuleWizard.py script is found, and so that the template path points to the correct spot. This command relies on your machine having an installed python interpreter to run the wizard (any version of python should work, you don't need to use the one that gets built with slicer).
This command will create a new directory parallel to the Slicer source directory, in this case called MyBorExtension.
Since we used the ScriptedLoadableExtensionTemplate, the only thing we need to do is set the additional module path to point to the full path to MyBorExtension in the Application Settings dialog.
Then when you restart slicer, you should select your module using in the Module Navigation interface.
Examples
These can be run from the Slicer4 source directory.
To create a CLI Extension:
./Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/CLIExtensionTemplate --target ../MyFooExtension MyFooExtension
where MyFooExtension
is the name of your extension
To create a Loadable Extension:
./Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/LoadableExtensionTemplate --target ../MyBarExtension MyBarExtension
where MyBarExtension
is the name of your extension
To create a Scripted Loadable Extension:
./Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/ScriptedLoadableExtensionTemplate --target ../MyBorExtension MyBorExtension
where MyBorExtension
is the name of your extension
To create an EditorEffect Extension
./Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/EditorExtensionTemplate --target ../MyEditorEffect MyEditorEffect
where MyEditorEffect
is the name of your extension
Creating and Testing a Loadable Module
The following code can be run from the SuperBuild directory (mac and linux):
NEWMODULE=NewModule SLICERSUPERBUILD=`pwd` ../Slicer/Utilities/Scripts/ModuleWizard.py --template ../Slicer/Extensions/Testing/LoadableExtensionTemplate --target /tmp/${NEWMODULE} ${NEWMODULE} mkdir /tmp/${NEWMODULE}-build (cd /tmp/${NEWMODULE}-build; cmake /tmp/${NEWMODULE} -DSlicer_DIR:PATH=${SLICERSUPERBUILD}/Slicer-build; make) ./Slicer-build/Slicer --additional-module-paths /tmp/${NEWMODULE}-build/lib/Slicer-4.2/qt-loadable-modules
Slicer will start, and you will find NewModule in the modules menu under Examples. In the python interpreter, you can access the wrapped logic with:
logic = slicer.modules.newmodule.logic()
From here, you can add additional methods to the logic and develop the GUI.
Note: use the latest version of CMake (2.8.11) on mac