Hi all,
The script repository recommends, if you want to respond to a volume being loaded, to respond to the Node-Added event, but then call the responding method using a timer:
# Call showVolumeRendering using a timer instead of calling it directly
# to allow the volume loading to fully complete.
qt.QTimer.singleShot(0, lambda: showVolumeRendering(node))
In my experience (Slicer 5.6.2), this doesn’t work well when the volume loading is not immediate (e.g. loading a 300M Minc2 file typically takes a few seconds on my machine) – the listener is called before loading finishes.
I found an alternative – listen, instead, for changes in the scene’s Selection Node:
(in a module widget’s setup()
: )
selectionNode = slicer.app.applicationLogic().GetSelectionNode()
self.addObserver(selectionNode, vtk.vtkCommand.ModifiedEvent, self.onSelectionModified)
The Selection Node is changed only when the volume loading ends, so the responding code can handle it without waiting further.
I’ve seen some posts and comments objecting to the idea of a single selected volume; but the functionality is still there, and using it is still recommended in a similar context.
Is there some non-obvious disadvantage to this method?
Thanks!