Skip to content

Commit

Permalink
BUG: Fix incorrect enter/exit called after scripted module reload
Browse files Browse the repository at this point in the history
When a scripted loadable module was reloaded using slicer.util.reloadScriptedModule, pythonSource was not changed in qSlicerScriptedLoadableModuleWidget. As a result, the previous enter/exit methods continued to be used by the scripted module.

Fixed by making setPythonSource accessible in Python, and using it to instantiate the new widget object.

Fix #7211
  • Loading branch information
Sunderlandkyl committed Nov 14, 2023
1 parent c2e136f commit d7b3534
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Base/Python/slicer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,10 +1372,12 @@ def reloadScriptedModule(moduleName):
for item in items:
parent.layout().removeItem(item)

# create new widget inside existing parent
widget = eval("reloaded_module.%s(parent)" % widgetName)
# Creates new widget at slicer.modules.{widgetName}.
# Also ensures that qSlicerScriptedLoadableModuleWidget has references to updated enter/exit/setup methods.
parent.setPythonSource(filePath)
# get new widget
widget = getattr(slicer.modules, widgetName)
widget.setup()
setattr(slicer.modules, widgetName, widget)

return reloaded_module

Expand Down
4 changes: 2 additions & 2 deletions Base/QTGUI/qSlicerScriptedLoadableModuleWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Q_SLICER_BASE_QTGUI_EXPORT qSlicerScriptedLoadableModuleWidget
qSlicerScriptedLoadableModuleWidget(QWidget * parentWidget=nullptr);
~qSlicerScriptedLoadableModuleWidget() override;

QString pythonSource()const;
bool setPythonSource(const QString& filePath, const QString& className = QLatin1String(""));
Q_INVOKABLE QString pythonSource()const;
Q_INVOKABLE bool setPythonSource(const QString& filePath, const QString& className = QLatin1String(""));

/// Convenience method allowing to retrieve the associated scripted instance
Q_INVOKABLE PyObject* self() const;
Expand Down

0 comments on commit d7b3534

Please sign in to comment.