How to run python based CLI modules?

(saima safdar) #1

I have gone through this
https://www.slicer.org/wiki/Documentation/Nightly/Developers/SlicerExecutionModel/Python

So, what I understand about python based CLI is:
there is an xml file which will produce GUI for application and the same xml is used by the .py file to parse elements.
the execute function is in the xml file that will be run by slicer and the name of the script .py file is within this function.

how to run and test the python based cli module?

Thank you

Regards,
Saima Safdar

0 Likes

Can I use multiprocessing in a Python module
(Steve Pieper) #2

Hi Saima -

For a new style python scripted cli, you can run like you would any other cli.

https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#Running_a_CLI_from_Python

E.g.

node = slicer.cli.runSync(slicer.modules.slicerradiomicscli)
print(node)

HTH,
Steve

0 Likes

(saima safdar) #3

How to run and test newly created cli modules?
and how do you get the GUI for newly created CLI module?

I am new in this and I want to create a python based CLI module. The module will take input image send it to external python file for execution (as python 3 external libraries are required) and return the resultant image.

Please help me as I could not understand how to do this?

I have found this script
https://www.slicer.org/wiki/Documentation/Nightly/Developers/SlicerExecutionModel/Python

I need to do this but I do not know how I can do this in slicer?

Do I need to build with cmake. then create a scripted module for the cli and then run thought the scripted module?

Please guide how can I create python based CLI modules

0 Likes

(Steve Pieper) #4

Hi @Saima -

As it says at the top of the page you linked that older style was only supported in Slicer 3.x. There is a new style for Slicer 4.x that you can follow like in this repository.

The description of the parameters goes in the .xml file, and the script to run is the .py file.

You can also look at the PyCLIModule tests here.

I haven’t tried running python3 - you will probably run into environment variable issues. @ihnorton did you have any suggestions for that?

0 Likes

(saima safdar) #5

Thank you so much for replying.

I will look into the things you suggested and will come back again.

0 Likes

(saima safdar) #6

Hi,
How can you put a newly written python based cli into slicer?

Thank you

Regards,
Saima Safdar

0 Likes

(Steve Pieper) #7

You should be able to just add the directory to the module path like you would with a scripted module (module path selector in the preferences dialog)

0 Likes

(saima safdar) #8

I added the folder “newfuzzypython” containing the example .py and .xml. Like below in the screen shot.
Is it correct? How can I see this in slicer. I dont see any new module added to module section.
Sorry, if i am asking general questions. I am new to this environment. Trying to understand.

0 Likes

(Andras Lasso) #9

Could you upload your source code to GitHub and post the link here so that we can have a look?

0 Likes

(saima safdar) #10

Sorry I was away. the issue to load the cli module is resolved. will come back again if I have problems.

Please would you tell me one thing. if I made changes in cli module I have to restart slicer to see those changes. is it the only way to test the new module again and again.

0 Likes

(Andras Lasso) #11

There is no need to restart Slicer to test changes. You can reload your module by clicking “Reload” button at the top of your scripted module user interface. Make sure you use a module template generated by a recent version of Extension Wizard module, and enable “Developer mode” in application settings.

0 Likes

(saima safdar) #12

Dear Andras,
when I create scripted python module I do find restore and the changes reflect but when I am working with cli based python module I could not see a reload button. the template produces this as below:
image

0 Likes

(Andras Lasso) #13

For Python CLIs you don’t even need to click Reload, as when you click Apply then always the current version of the code is used.

If you update the GUI (the XML description) then you need to restart Slicer to see the changes, but since it is just a descriptive text, it should not require frequent modifications or debugging.

0 Likes