Difference between revisions of "Documentation/4.0/Developers/Tutorials/ModuleWriting"

From Slicer Wiki
Jump to: navigation, search
Line 4: Line 4:
 
* Create the Module directory
 
* Create the Module directory
 
  cd Slicer4
 
  cd Slicer4
  python Scripts/ModuleWizard.py MY_MODULE_NAME
+
  python Utilities/Scripts/ModuleWizard.py MY_MODULE_NAME
 +
Where you replace MY_MODULE_NAME with the name of the module you want (e.g. HelloWorld)
 
Note: on Windows
 
Note: on Windows
  ..\Slicer4-Superbuild\python-build\PCBuild\python.exe Scripts\ModuleWizard.py MY_MODULE_NAME
+
  ..\Slicer4-Superbuild\python-build\PCBuild\python.exe UtilitiesScripts\ModuleWizard.py MY_MODULE_NAME
* Add the newly created module into Slicer4/QTModules/CMakeLists.txt
+
* Edit the file Slicer4/Modules/Loadable/CMakeLists.txt
 +
Add  the name of your module at the end of the qtmodules variable assignment:
 +
...
 +
set(qtmodules
 +
  ...
 +
  MY_MODULE_NAME
 +
  )
 +
...
 
* Compile
 
* Compile
* Start Slicer and verify the module is present
+
cd ../Slicer4-Superbuild/Slicer-build;
* Open the designer via the launcher ([[Slicer4:Developers:Projects:QtSlicer/Tutorials/QtDesigner|more info]])
+
make -j4
  cd Slicer4-Superbuild/Slicer-build
+
* Start Slicer and verify the module is present (listed under "Module Template")
  slicer4 --designer
+
./Slicer
*Open the module UI file (QTModules/MY_MODULE_NAME/Resources/UI/qSlicerMY_MODULE_NAMEModule.ui)
+
* Open the designer via the launcher
 +
./Slicer --designer
 +
*Edit the module UI file: QTModules/MY_MODULE_NAME/Resources/UI/qSlicerMY_MODULE_NAMEModule.ui
 +
[[Slicer4:Developers:Projects:QtSlicer/Tutorials/QtDesigner|More info to use the designer]]
 +
*Edit the module files
 +
  Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAME.[h|cxx]
 +
  Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAMEWidget.[h|cxx]
 +
Slicer4/Modules/Loadable/MY_MODULE_NAME/Logic/vtkSlicerMY_MODULE_NAMELogic.[h|cxx]
 +
...
  
 
= Qt Designer =
 
= Qt Designer =

Revision as of 05:23, 21 December 2011

Home < Documentation < 4.0 < Developers < Tutorials < ModuleWriting

Back to Developers Information

Initialization

  • Create the Module directory
cd Slicer4
python Utilities/Scripts/ModuleWizard.py MY_MODULE_NAME

Where you replace MY_MODULE_NAME with the name of the module you want (e.g. HelloWorld) Note: on Windows

..\Slicer4-Superbuild\python-build\PCBuild\python.exe UtilitiesScripts\ModuleWizard.py MY_MODULE_NAME
  • Edit the file Slicer4/Modules/Loadable/CMakeLists.txt

Add the name of your module at the end of the qtmodules variable assignment:

...
set(qtmodules
  ...
  MY_MODULE_NAME
  )
...
  • Compile
cd ../Slicer4-Superbuild/Slicer-build;
make -j4
  • Start Slicer and verify the module is present (listed under "Module Template")
./Slicer
  • Open the designer via the launcher
./Slicer --designer
  • Edit the module UI file: QTModules/MY_MODULE_NAME/Resources/UI/qSlicerMY_MODULE_NAMEModule.ui

More info to use the designer

  • Edit the module files
Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAME.[h|cxx]
Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAMEWidget.[h|cxx]
Slicer4/Modules/Loadable/MY_MODULE_NAME/Logic/vtkSlicerMY_MODULE_NAMELogic.[h|cxx]
...

Qt Designer

  • How to set icons to widgets
    • In the icon property entry of the widget (Property Editor), select a resource file
      • Slicer4\QTModules\MY_MODULE_NAME\Resources\qSlicerMY_MODULE_NAMEModule.qrc
      • Slicer4\Libs\qMRMLWidgets\Resources\qMRMLWidget.qrc
      • Slicer4\Base\QTGUI\Resources\qSlicerBaseQTGUI.qrc
  • How to add an icon in a resource file
    • Add the icon in Slicer4/QTModules/MY_MODULE_NAME/Resources/Icon
    • Edit the resource file by adding the line
      • "<file>Icons/MyIcon.png</file>"