Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TD]add Python QGraphicsObject to Page
- Loading branch information
1 parent
ad64c57
commit ccad0fa
Showing
1 changed file
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,9 @@ class Module : public Py::ExtensionModule<Module> | |
add_varargs_method("addQGIToView",&Module::addQGIToView, | ||
"addQGIToView(View, QGraphicsItem) -- insert graphics item into view's graphic." | ||
); | ||
add_varargs_method("addQGObjToView", &Module::addQGObjToView, | ||
"addQGObjToView(View, QGraphicsObject) -- insert graphics object into view's graphic. Use for QGraphicsItems that have QGraphicsObject as base class." | ||
); | ||
initialize("This is a module for displaying drawings"); // register with Python | ||
} | ||
virtual ~Module() {} | ||
|
@@ -362,7 +365,55 @@ class Module : public Py::ExtensionModule<Module> | |
|
||
return Py::None(); | ||
} | ||
}; | ||
|
||
|
||
//!use addQGObjToView for QGraphics items like QGraphicsSvgItem or QGraphicsTextItem that are | ||
//! derived from QGraphicsObject | ||
Py::Object addQGObjToView(const Py::Tuple& args) | ||
{ | ||
PyObject *viewPy = nullptr; | ||
PyObject *qgiPy = nullptr; | ||
if (!PyArg_ParseTuple(args.ptr(), "OO", &viewPy, &qgiPy)) { | ||
throw Py::TypeError("expected (view, item)"); | ||
} | ||
|
||
try { | ||
App::DocumentObject* obj = nullptr; | ||
Gui::ViewProvider* vp = nullptr; | ||
QGIView* qgiv = nullptr; | ||
if (PyObject_TypeCheck(viewPy, &(TechDraw::DrawViewPy::Type))) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
WandererFan
via email
Author
Contributor
|
||
obj = static_cast<App::DocumentObjectPy*>(viewPy)->getDocumentObjectPtr(); | ||
vp = Gui::Application::Instance->getViewProvider(obj); | ||
if (vp) { | ||
TechDrawGui::ViewProviderDrawingView* vpdv = | ||
dynamic_cast<TechDrawGui::ViewProviderDrawingView*>(vp); | ||
if (vpdv) { | ||
qgiv = vpdv->getQView(); | ||
if (qgiv != nullptr) { | ||
Gui::PythonWrapper wrap; | ||
if (!wrap.loadCoreModule() || | ||
!wrap.loadGuiModule() || | ||
!wrap.loadWidgetsModule()) { | ||
PyErr_SetString(PyExc_RuntimeError, "Failed to load Python wrapper for Qt"); | ||
This comment has been minimized.
Sorry, something went wrong.
marioalexis84
Member
|
||
return Py::None(); | ||
} | ||
QGraphicsObject* item = wrap.toQGraphicsObject(qgiPy); | ||
if (item != nullptr) { | ||
qgiv->addArbitraryItem(item); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
catch (Base::Exception &e) { | ||
e.setPyException(); | ||
throw Py::Exception(); | ||
} | ||
|
||
return Py::None(); | ||
} | ||
}; | ||
|
||
PyObject* initModule() | ||
{ | ||
|
Why not check the type directly in PyArg_ParseTuple?