Hello,
I have two questions regarding ‘private extension’.
Q1. Is it correct that the extension created through the extension wizard works locally by default and becomes public only when it is submitted to Slicer’s index(?)
Create an extension file through ‘create extension’ of the extension wizard. ( I got it )
Add Module to Extention
Q2) What is ‘Add Module to Extension’ ?
Since a Python code file (.py) is usually called a module, I thought it was to add the function file I created in this part. However, I think I am wrong. Where should I add the source code files that I have implemented and other files necessary for source code operation?
Q1. Is it correct that the extension created through the extension wizard works locally by default and becomes public only when it is submitted to Slicer’s index(?)
That is correct. The Extension Wizard module will create the local files that make up an extension. Once you have developed your extension, you need to make a PR to the ExtensionsIndex (GitHub - Slicer/ExtensionsIndex: Slicer extensions index).
Q2) What is ‘Add Module to Extension’ ?
Since a Python code file (.py) is usually called a module, I thought it was to add the function file I created in this part. However, I think I am wrong. Where should I add the source code files that I have implemented and other files necessary for source code operation?
An extension is made up of one or more modules (there are also different types of modules). You need to add at least one module for your extension to work, so in your case, you would probably want to add a Python module. This will generate the structure of a basic module, including a .py file where you can move your code.
It is worth mentioning that 3D slicer will ask you whether the path to your module should be added to the list of modules that Slicer will load. Doing it so, will have your module loaded in your current installation/build of 3D Slicer.
I tried the method you told me before asking the question.
But I have qt module problems (I have included a key board shortcut custom function in my code.)
In my opinion, it seems to be a problem that occurs because the act of loading my custom module precedes the loading of the qt module. Should I do add Pyqt5 in my codes?
===============
I thought adding the module in step 2) was adding the code file I created.
However, when I click ‘add module to extension’, the screen that appears is as follows.
I think my understanding of this part is wrong, but since the Python code file itself is called a module, shouldn’t I be able to add the code I created in step 2?
Unfortunately, since the slicer version has been unified( in my company), it cannot be changed.
There is no problem with this configuration in my version either.
The current problem situation is that the problem occurs from the moment the custom code is added.
I temporarily solved the problem by replacing it with a method of adding code through the ‘Ctrl+r’ short cut key, but I’m still curious about the sure method for the extension.
The above structure is automatically formed after the ‘Create Extension’ and ‘Add module to entension’ processes.
If so, where is your custom code included in the structure above?
In my slicer, I included my custom code directly in the directory after the above structure was created automatically.
The part I found odd in the previous question is the ‘TestModule’ part.
This part is the output of the ‘Add module to extension’ process, I thought I was adding my custom code here, but it actually seemed to create a dummy folder.
Is it correct way to add custom code additions directly under these dummy modules?
Place your custom code in the template/example Slicer scripted loadable module that is TestModule.py. You must maintain the template structure contained in TestModule.py. It will not work to copy all code in my_custom_code.py and replace everything in TestModule.py.
@jamesobutler
What you mean is not to add custom code inside TestModule, but to copy and add my CustomCode inside the TestModule.py code while keeping the contents of the existing TestModule.py?
TestModule.py is an example/template of a Slicer scripted loadable module that does some example functionality. You will replace that with your custom code, however you need to keep the framework of the classes in place (ScriptedLoadableModule/ScriptedLoadableModuleWidget/ScriptedLoadableModuleLogic). The framework makes sure the Slicer scripted loadable module is setup correctly upon starting Slicer.
As you said, I think I can just copy-paste my custom code into the generated code file, but it’s frustrating because there are so many unknown errors. you’re driving me crazy 3D slicer~~~
edit :
I often use argparser in code, but I don’t know why it doesn’t work, so I just changed it to a global variable and solved it. but it doesn’t seem clean
The error you show looks like pure python issues rather than Slicer. Does your code take command line input arguments or is it built with GUI input/selection in mind? Are you creating a Slicer scripted module or a Slicer scripted CLI module? See module types at Module Overview — 3D Slicer documentation. A scripted CLI is an option in the extension wizard of the latest stable Slicer.
The problem didn’t occur in all cases except when pasting the custom code into the extension module file. I don’t think it’s a code problem. I’ll have to keep thinking about why argparser only gives an error in this case.