Import 2017-06-07 23:51:09: master e5cf5fec

Author Committer Branch Timestamp Parent
jcfr jcfr master 2015-04-03 20:42:28 master 941fad8e
Affected Issues 0003549: Import scripted module as python module
Changeset

ENH: Fixes 0003549. Import scripted module as python module

This will allow each scripted module to defined top-level variables that
will not clobber each other.

For example, if we consider these two modules:

8<----8<----8<----8<----8<----8<----8<----8<----
File: ModuleA.py

FOO = 1

class ModuleA(ScriptedLoadableModule):
def init(self, parent):
ModuleA.init(self, parent)
[...]
def doSomething(self):
if FOO == 1:
[...]
else:
[...]
8<----8<----8<----8<----8<----8<----8<----8<----

8<----8<----8<----8<----8<----8<----8<----8<----
File: ModuleB.py

FOO = 2

class ModuleB(ScriptedLoadableModule):
def init(self, parent):
ModuleB.init(self, parent)
[...]
def doSomething(self):
if FOO == 1:
[...]
else:
[...]
8<----8<----8<----8<----8<----8<----8<----8<----

Assuming ModuleA, and then ModuleB are imported. Before this commit,
both scripts were executed in the main scope and FOO variable would
have the value associated with the last imported module.

After this commit, both module will see their own copy of the FOO
variable with the expected value.

It also avoid the hack when we explicitly save/set/restore
both "name" and "file" variable.

Changes to "DICOMScalarVolumePlugin" fixes the test failing test
"py_RSNAVisTutorial" and "py_SubjectHierarchyGenericSelfTest". It basically
fixes the following error by ensuring all object are imported:

//--------------
test_SubjectHierarchyGenericSelfTest_FullTest1 (SubjectHierarchyGenericSelfTest.SubjectHierarchyGenericSelfTestTest) ... Traceback (most recent call last):
File "/path/to/Slicer-build/lib/Slicer-4.4/qt-scripted-modules/DICOMLib/DICOMWidgets.py", line 615, in getLoadablesFromFileLists
loadablesByPlugin[plugin] = plugin.examineForImport(fileLists)
File "/path/to/Slicer-build/lib/Slicer-4.4/qt-scripted-modules/DICOMScalarVolumePlugin.py", line 47, in examineForImport
loadablesForFiles = self.examineFiles(files)
File "/path/to/Slicer-build/lib/Slicer-4.4/qt-scripted-modules/DICOMScalarVolumePlugin.py", line 71, in examineFiles
loadable = DICOMLib.DICOMLoadable()
NameError: global name 'DICOMLib' is not defined
//--------------

git-svn-id: http://svn.slicer.org/Slicer4/trunk@24155 3bd1e089-480b-0410-8dfb-8563597acbee

mod - Applications/SlicerApp/Testing/Python/ScriptedModuleDiscoveryTest.py Diff File
add - Applications/SlicerApp/Testing/Python/ScriptedModuleDiscoveryTest/ModuleC_WithoutWidget.py Diff File
add - Applications/SlicerApp/Testing/Python/ScriptedModuleDiscoveryTest/ModuleD_WithFileDialog_WithoutWidget.py Diff File
add - Applications/SlicerApp/Testing/Python/ScriptedModuleDiscoveryTest/ModuleE_WithFileWriter_WithoutWidget.py Diff File
mod - Base/QTCore/qSlicerScriptedFileWriter.cxx Diff File
mod - Base/QTCore/qSlicerScriptedUtils.cxx Diff File
mod - Base/QTCore/qSlicerScriptedUtils_p.h Diff File
mod - Base/QTGUI/qSlicerScriptedFileDialog.cxx Diff File
mod - Base/QTGUI/qSlicerScriptedLoadableModule.cxx Diff File
mod - Base/QTGUI/qSlicerScriptedLoadableModuleWidget.cxx Diff File
mod - Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py Diff File