Import 2017-06-07 23:51:09: master 1a55da6c

Author Committer Branch Timestamp Parent
msmolens msmolens master 2015-09-22 09:58:25 master 6cf055d8
Changeset

ENH: Support writing scripted modules and widgets as new-style Python classes

This commit adds support for writing scripted module and widget classes as
new-style Python classes [1].

The motivation for this change is to allow widget classes to take advantage of
convenience classes such as VTKObservationMixin.

While old-style classes are used with PyClass_XXX and PyInstance_XXX functions
[2], new-style classes are used with PyType_XXX functions [3]. A new-style class
can be identified programatically by checking whether PyType_Check() returns
true. In C, like in Python code, calling the type creates an object; the
PyObject_CallXXX functions accomplish this [4].

The Python error that occurred when attempting to instanciate a new-style Python
module or widget class before this change was:

SystemError: ../Objects/classobject.c:521: bad argument to internal function

Fixes the following issues:

http://www.na-mic.org/Bug/view.php?id=1890:
("Python doesn't support new-style classes")

http://www.na-mic.org/Bug/view.php?id=2994:
("Old style python classes in "Programming in Slicer4"? What's the superclass?")

[1] https://docs.python.org/2/reference/datamodel.html#newstyle
[2] https://docs.python.org/2/c-api/class.html
[3] https://docs.python.org/2/c-api/type.html
[4] https://docs.python.org/2/c-api/object.html

From: Max Smolens <max.smolens@kitware.com>

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

mod - Base/QTCore/qSlicerScriptedUtils.cxx Diff File
mod - Base/QTGUI/Testing/Cxx/Resources/qSlicerBaseQTGUITesting.qrc Diff File
mod - Base/QTGUI/Testing/Cxx/qSlicerScriptedLoadableModuleTest.cxx Diff File
mod - Base/QTGUI/Testing/Cxx/qSlicerScriptedLoadableModuleWidgetTest.cxx Diff File
add - Base/QTGUI/Testing/Data/Input/qSlicerScriptedLoadableModuleNewStyleTest.py Diff File
add - Base/QTGUI/Testing/Data/Input/qSlicerScriptedLoadableModuleNewStyleTestWidget.py Diff File