I was wondering how can I call correctly a function that is in the ModuleNameLogic inherited by ScriptedLoadableModuleLogic in python?
Currently, I try the following with no success:
slicer.modules.moduleName.logic().Test()
My current code seems like the following and I want to call from Python Interactor the Test() method:
> class ModuleName(ScriptedLoadableModule):
> def __init__(self, parent):
> ScriptedLoadableModule.__init__(self, parent)
>
>
> class ModuleNameWidget(ScriptedLoadableModuleWidget):
>
> def setup(self):
> ScriptedLoadableModuleWidget.setup(self)
>
>
> class ModuleNameLogic(ScriptedLoadableModuleLogic):
>
> def Test(self):
> print("Test is called")
> pass
if you are in a different module file or in the python interactor you might need to call import ModuleName first.
(As an aside, the other ‘logic’ class slicer.modules.moduleName.logic is actually the C++ loadable module instance corresponding to the scripted module, but it’s really just an internal structure and doesn’t have any particular utility here).
Should we update updating the scripted module template to create a logic instance in the widget’s constructor instead of creating a new logic instance each time? This would make the Python and C++ modules a bit more consistent.