Extensions: Fix ViewProvider python interface
This commit is contained in:
parent
3565d4ef18
commit
19e708879f
|
@ -33,6 +33,7 @@
|
|||
#include "Base/Exception.h"
|
||||
#include <Base/Console.h>
|
||||
#include <Base/PyObjectBase.h>
|
||||
#include <ExtensionPy.h>
|
||||
|
||||
/* We do not use a standard property macro for type initiation. The reason is that we have the first
|
||||
* PropertyData in the extension chain, there is no parent property data.
|
||||
|
@ -96,7 +97,12 @@ void Extension::initExtension(ExtensionContainer* obj) {
|
|||
|
||||
PyObject* Extension::getExtensionPyObject(void) {
|
||||
|
||||
return nullptr;
|
||||
if (ExtensionPythonObject.is(Py::_None())){
|
||||
// ref counter is set to 1
|
||||
auto grp = new ExtensionPy(this);
|
||||
ExtensionPythonObject = Py::Object(grp,true);
|
||||
}
|
||||
return Py::new_reference_to(ExtensionPythonObject);
|
||||
}
|
||||
|
||||
const char* Extension::name() {
|
||||
|
|
|
@ -97,13 +97,14 @@ public:
|
|||
|
||||
ViewProviderExtensionPythonT() {
|
||||
ExtensionT::m_isPythonExtension = true;
|
||||
ExtensionT::initExtension(ViewProviderExtensionPythonT::getExtensionClassTypeId());
|
||||
|
||||
EXTENSION_ADD_PROPERTY(Proxy,(Py::Object()));
|
||||
EXTENSION_ADD_PROPERTY(ExtensionProxy,(Py::Object()));
|
||||
}
|
||||
virtual ~ViewProviderExtensionPythonT() {
|
||||
}
|
||||
|
||||
App::PropertyPythonObject Proxy;
|
||||
App::PropertyPythonObject ExtensionProxy;
|
||||
};
|
||||
|
||||
typedef ViewProviderExtensionPythonT<Gui::ViewProviderExtension> ViewProviderExtensionPython;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="PropertyContainerPy"
|
||||
Father="ExtensionContainerPy"
|
||||
Name="ViewProviderPy"
|
||||
Twin="ViewProvider"
|
||||
TwinPointer="ViewProvider"
|
||||
Include="Gui/ViewProvider.h"
|
||||
Namespace="Gui"
|
||||
FatherInclude="App/PropertyContainerPy.h"
|
||||
FatherInclude="App/ExtensionContainerPy.h"
|
||||
FatherNamespace="App">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
|
|
|
@ -234,7 +234,26 @@ class DocumentBasicCases(unittest.TestCase):
|
|||
self.Doc.removeObject(obj.Name)
|
||||
del obj
|
||||
|
||||
def testExtensionBugViewProvider(self):
|
||||
|
||||
class Layer():
|
||||
def __init__(self, obj):
|
||||
''' Add the properties '''
|
||||
obj.addExtension("App::GroupExtensionPython", self)
|
||||
|
||||
class LayerViewProvider():
|
||||
def __init__(self, obj):
|
||||
''' Add the properties '''
|
||||
obj.addExtension("Gui::ViewProviderGroupExtensionPython", self)
|
||||
obj.Proxy = self
|
||||
|
||||
obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","Layer")
|
||||
Layer(obj)
|
||||
LayerViewProvider(obj.ViewObject)
|
||||
self.failUnless(obj.hasExtension("App::GroupExtension"))
|
||||
self.failUnless(obj.ViewObject.hasExtension("Gui::ViewProviderGroupExtension"))
|
||||
self.failUnless(obj.ViewObject.hasExtension("Gui::ViewProviderGroupExtensionPython"))
|
||||
|
||||
def tearDown(self):
|
||||
#closing doc
|
||||
FreeCAD.closeDocument("CreateTest")
|
||||
|
|
Loading…
Reference in New Issue
Block a user