Trigger event when CLI run has completed

As in the title I would like to be able to trigger some code after a CLI run has completed.

I know I can use the parameter wait_for_completion=True to pause the code execution, however if I do this the GUI does not update and the qCLIProgressBar does not run making it look as though the program has hung.

I have tried setting a connect condition to be triggered by the progress bar…

self.bar3.connect(‘valueChanged(int)’, self.onBar3)

but the qSlicerCLIProgressBar does not seem to give out the same signals as the qProgressBar.

I also tried using a While / Sleep loop to check the status of the cliNode (cliNode.GetStatus()) but this freezes the GUI just like the wait_for_completion parameter.

Is there any way to wait for the CLI to complete without freezing the GUI or (which would seem neater to me) to trigger a new routine once it has completed.


Yes, you can put an observer on the command line module node and get events when the state changes. See “Running CLI in the background” here:

1 Like