Updating the display while we in a for loop


I created an extension using the Extension Wizard, which allows to place fiducials on positions where the moving machine is tracked.

for implementing this feature, I used the ‘for’ loop.
when the loop is executing, however, Slicer program is put on standby, and the fiducials are displayed at once after the loop are completed.

I would like to see the fiducials every time the loop runs one cycle.
What should I do?? I would appreciate it if I could get your help.


If you want to update the screen while you are processing data you need the give the application a chance to process events, by calling slicer.app.processEvents(). However, blocking the event queue by a for loop should be avoided in general (it is OK if you do some long processing, but not for collecting data), because GUI updates will not be smooth.

Instead, you can can add an observer to the transform that you want to collect data from and add the point in the callback function. If you want to do time-based sampling (record a point at regular time intervals) then use a qt.QTimer and add the point in its callback function.

Note that there are several modules for collecting fiducials in SlicerIGT extension, TrackingErrorInspector, etc. If to describe what you would like to achieve then we can recommend similar modules that you can use or extend to fit your needs.

I really appreciate your help!:slight_smile: