Import order in a scripted loadable module

When a module class is instantiated, it is still the module discovery phase (the application scans what modules are available, builds a dependency tree, determines in which order the modules will be initialized). Slicer application or other modules are not available yet. If you want to do something at application startup then you can connect a method to the application’s startupCompleted() signal:

Create logic object on startupCompleted() signal and store it in the module class. This is only necessary if only one logic instance is allowed in the application. For example, this is the case when the logic observes the scene and reacts to changes, modifies nodes automatically

(source: PerkLab bootcamp, Slicer programming tutorial, slide 11)

See the scripted module template for an example of using this signal:

1 Like