New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Fix incorrect enter/exit called after scripted module reload #7351
BUG: Fix incorrect enter/exit called after scripted module reload #7351
Conversation
7f4fe30
to
7f922e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment is just an idea. If you need this feature I'm okay with merging as-is.
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove the use of the reloaded_module
ivar, we should also revisit
Slicer/Base/Python/slicer/util.py
Lines 1346 to 1356 in 14a4056
with open(filePath, encoding="utf8") as fp: | |
reloaded_module = imp.load_module( | |
moduleName, fp, filePath, (".py", "r", imp.PY_SOURCE)) | |
# find and hide the existing widget | |
parent = eval("slicer.modules.%s.widgetRepresentation()" % moduleName.lower()) | |
for child in parent.children(): | |
try: | |
child.hide() | |
except AttributeError: | |
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @jcfr - this code never seemed like a clean implementation but as I recall it was the best I could figure out at the time. If there's a cleaner and more maintainable implementation it would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the imp.load_module call still seems to be required. Without it, the module is not actually reloaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before moving forward we should revisit code setting the reloaded_module
internal variable as this is likely not needed anymore.
The root cause of this issue is that each C++ instance of a scripted module maintains a reference to a To comprehensively resolve this, we should implement a systematic solution by introducing a "reload()" function at the C++ level. This function will ensure that the underlying I will propose a fix for this issue. |
@Sunderlandkyl this looks good to me overall. Could you rebase on latest main and resolve the conflicts? Thank you! |
7f922e4
to
d7b3534
Compare
Should I keep this PR open. or close it in favor of a more comprehensive solution? |
d7b3534
to
6e976e7
Compare
I will follow-up this afternoon by either:
In the meantime, I just rebased and force-pushed the topic against the current |
6e976e7
to
c8e07fe
Compare
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 adding "reload()" function accessible from Python Fix Slicer#7211 Co-authored-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
c8e07fe
to
34f6ed0
Compare
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