Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code
This commit is contained in:
commit
8ca6d56bf1
|
@ -212,7 +212,7 @@ MARK_AS_ADVANCED(FORCE FREECAD_LIBPACK_CHECKFILE6X FREECAD_LIBPACK_CHECKFILE7X)
|
|||
if(NOT DEFINED OCE_DIR)
|
||||
if(UNIX)
|
||||
set(OCE_DIR "/usr/local/share/cmake/")
|
||||
elif(WIN32)
|
||||
elseif(WIN32)
|
||||
set(OCE_DIR "c:/OCE-0.4.0/share/cmake")
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -75,6 +75,8 @@ if(PYSIDE_INCLUDE_DIR)
|
|||
add_definitions(-DHAVE_PYSIDE)
|
||||
include_directories(
|
||||
${PYSIDE_INCLUDE_DIR}
|
||||
${PYSIDE_INCLUDE_DIR}/QtCore
|
||||
${PYSIDE_INCLUDE_DIR}/QtGui
|
||||
)
|
||||
set(FreeCADGui_LIBS
|
||||
${FreeCADGui_LIBS}
|
||||
|
|
|
@ -195,7 +195,7 @@ TaskWatcherPython::TaskWatcherPython(const Py::Object& o)
|
|||
Py::List list(watcher.getAttr(std::string("widgets")));
|
||||
|
||||
Gui::PythonWrapper wrap;
|
||||
if (wrap.loadModule()) {
|
||||
if (wrap.loadCoreModule()) {
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
QObject* object = wrap.toQObject(*it);
|
||||
if (object) {
|
||||
|
@ -293,7 +293,7 @@ TaskDialogPython::TaskDialogPython(const Py::Object& o) : dlg(o)
|
|||
}
|
||||
|
||||
Gui::PythonWrapper wrap;
|
||||
if (wrap.loadModule()) {
|
||||
if (wrap.loadCoreModule()) {
|
||||
for (Py::List::iterator it = widgets.begin(); it != widgets.end(); ++it) {
|
||||
QObject* object = wrap.toQObject(*it);
|
||||
if (object) {
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#if 0 // disable for now
|
||||
// Remove this block when activating PySide support!
|
||||
#undef HAVE_SHIBOKEN
|
||||
#undef HAVE_PYSIDE
|
||||
|
||||
#ifdef HAVE_SHIBOKEN
|
||||
# undef _POSIX_C_SOURCE
|
||||
# undef _XOPEN_SOURCE
|
||||
|
@ -31,11 +34,12 @@
|
|||
# include <sbkmodule.h>
|
||||
# include <typeresolver.h>
|
||||
# ifdef HAVE_PYSIDE
|
||||
# include <QtCore/pyside_qtcore_python.h>
|
||||
# include <pyside_qtcore_python.h>
|
||||
# include <pyside_qtgui_python.h>
|
||||
PyTypeObject** SbkPySide_QtCoreTypes=NULL;
|
||||
PyTypeObject** SbkPySide_QtGuiTypes=NULL;
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <CXX/Objects.hxx>
|
||||
#include <App/Application.h>
|
||||
|
@ -57,9 +61,8 @@ PythonWrapper::PythonWrapper()
|
|||
|
||||
QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
|
||||
{
|
||||
#if 0
|
||||
// http://pastebin.com/JByDAF5Z
|
||||
//#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
PyTypeObject * type = Shiboken::SbkType<QObject>();
|
||||
if (type) {
|
||||
if (Shiboken::Object::checkType(pyobject.ptr())) {
|
||||
|
@ -83,7 +86,16 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
|
|||
|
||||
Py::Object PythonWrapper::toPython(QWidget* widget)
|
||||
{
|
||||
// todo: Port to PySide
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
PyTypeObject * type = Shiboken::SbkType<QWidget>();
|
||||
if (type) {
|
||||
SbkObjectType* sbk_type = reinterpret_cast<SbkObjectType*>(type);
|
||||
std::string typeName = widget->metaObject()->className();
|
||||
PyObject* pyobj = Shiboken::Object::newObject(sbk_type, widget, false, false, typeName.c_str());
|
||||
return Py::Object(pyobj);
|
||||
}
|
||||
throw Py::RuntimeError("Failed to wrap widget");
|
||||
#else
|
||||
Py::Module sipmod(PyImport_AddModule((char*)"sip"));
|
||||
Py::Callable func = sipmod.getDict().getItem("wrapinstance");
|
||||
Py::Tuple arguments(2);
|
||||
|
@ -91,18 +103,33 @@ Py::Object PythonWrapper::toPython(QWidget* widget)
|
|||
Py::Module qtmod(PyImport_ImportModule((char*)"PyQt4.Qt"));
|
||||
arguments[1] = qtmod.getDict().getItem("QWidget");
|
||||
return func.apply(arguments);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PythonWrapper::loadModule()
|
||||
bool PythonWrapper::loadCoreModule()
|
||||
{
|
||||
#if 0
|
||||
//#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
if (SbkPySide_QtCoreTypes)
|
||||
return true; // already loaded
|
||||
Shiboken::AutoDecRef requiredModule(Shiboken::Module::import("PySide.QtCore"));
|
||||
if (requiredModule.isNull())
|
||||
return false;
|
||||
SbkPySide_QtCoreTypes = Shiboken::Module::getTypes(requiredModule);
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
// QtCore
|
||||
if (!SbkPySide_QtCoreTypes) {
|
||||
Shiboken::AutoDecRef requiredModule(Shiboken::Module::import("PySide.QtCore"));
|
||||
if (requiredModule.isNull())
|
||||
return false;
|
||||
SbkPySide_QtCoreTypes = Shiboken::Module::getTypes(requiredModule);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonWrapper::loadGuiModule()
|
||||
{
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
// QtGui
|
||||
if (!SbkPySide_QtGuiTypes) {
|
||||
Shiboken::AutoDecRef requiredModule(Shiboken::Module::import("PySide.QtGui"));
|
||||
if (requiredModule.isNull())
|
||||
return false;
|
||||
SbkPySide_QtGuiTypes = Shiboken::Module::getTypes(requiredModule);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -311,7 +338,7 @@ Py::Object UiLoaderPy::createWidget(const Py::Tuple& args)
|
|||
|
||||
// 2nd argument
|
||||
QWidget* parent = 0;
|
||||
if (wrap.loadModule() && args.size() > 1) {
|
||||
if (wrap.loadCoreModule() && args.size() > 1) {
|
||||
QObject* object = wrap.toQObject(args[1]);
|
||||
if (object)
|
||||
parent = qobject_cast<QWidget*>(object);
|
||||
|
@ -325,6 +352,7 @@ Py::Object UiLoaderPy::createWidget(const Py::Tuple& args)
|
|||
|
||||
QWidget* widget = loader.createWidget(QString::fromAscii(className.c_str()), parent,
|
||||
QString::fromAscii(objectName.c_str()));
|
||||
wrap.loadGuiModule();
|
||||
return wrap.toPython(widget);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ class GuiExport PythonWrapper
|
|||
{
|
||||
public:
|
||||
PythonWrapper();
|
||||
bool loadModule();
|
||||
bool loadCoreModule();
|
||||
bool loadGuiModule();
|
||||
|
||||
QObject* toQObject(const Py::Object&);
|
||||
Py::Object toPython(QWidget*);
|
||||
|
|
Loading…
Reference in New Issue
Block a user