Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code

This commit is contained in:
Yorik van Havre 2013-06-30 13:55:26 -03:00
commit 8ca6d56bf1
5 changed files with 51 additions and 20 deletions

View File

@ -212,7 +212,7 @@ MARK_AS_ADVANCED(FORCE FREECAD_LIBPACK_CHECKFILE6X FREECAD_LIBPACK_CHECKFILE7X)
if(NOT DEFINED OCE_DIR) if(NOT DEFINED OCE_DIR)
if(UNIX) if(UNIX)
set(OCE_DIR "/usr/local/share/cmake/") set(OCE_DIR "/usr/local/share/cmake/")
elif(WIN32) elseif(WIN32)
set(OCE_DIR "c:/OCE-0.4.0/share/cmake") set(OCE_DIR "c:/OCE-0.4.0/share/cmake")
endif() endif()
endif() endif()

View File

@ -75,6 +75,8 @@ if(PYSIDE_INCLUDE_DIR)
add_definitions(-DHAVE_PYSIDE) add_definitions(-DHAVE_PYSIDE)
include_directories( include_directories(
${PYSIDE_INCLUDE_DIR} ${PYSIDE_INCLUDE_DIR}
${PYSIDE_INCLUDE_DIR}/QtCore
${PYSIDE_INCLUDE_DIR}/QtGui
) )
set(FreeCADGui_LIBS set(FreeCADGui_LIBS
${FreeCADGui_LIBS} ${FreeCADGui_LIBS}

View File

@ -195,7 +195,7 @@ TaskWatcherPython::TaskWatcherPython(const Py::Object& o)
Py::List list(watcher.getAttr(std::string("widgets"))); Py::List list(watcher.getAttr(std::string("widgets")));
Gui::PythonWrapper wrap; Gui::PythonWrapper wrap;
if (wrap.loadModule()) { if (wrap.loadCoreModule()) {
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
QObject* object = wrap.toQObject(*it); QObject* object = wrap.toQObject(*it);
if (object) { if (object) {
@ -293,7 +293,7 @@ TaskDialogPython::TaskDialogPython(const Py::Object& o) : dlg(o)
} }
Gui::PythonWrapper wrap; Gui::PythonWrapper wrap;
if (wrap.loadModule()) { if (wrap.loadCoreModule()) {
for (Py::List::iterator it = widgets.begin(); it != widgets.end(); ++it) { for (Py::List::iterator it = widgets.begin(); it != widgets.end(); ++it) {
QObject* object = wrap.toQObject(*it); QObject* object = wrap.toQObject(*it);
if (object) { if (object) {

View File

@ -23,7 +23,10 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#if 0 // disable for now // Remove this block when activating PySide support!
#undef HAVE_SHIBOKEN
#undef HAVE_PYSIDE
#ifdef HAVE_SHIBOKEN #ifdef HAVE_SHIBOKEN
# undef _POSIX_C_SOURCE # undef _POSIX_C_SOURCE
# undef _XOPEN_SOURCE # undef _XOPEN_SOURCE
@ -31,11 +34,12 @@
# include <sbkmodule.h> # include <sbkmodule.h>
# include <typeresolver.h> # include <typeresolver.h>
# ifdef HAVE_PYSIDE # 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_QtCoreTypes=NULL;
PyTypeObject** SbkPySide_QtGuiTypes=NULL;
# endif # endif
#endif #endif
#endif
#include <CXX/Objects.hxx> #include <CXX/Objects.hxx>
#include <App/Application.h> #include <App/Application.h>
@ -57,9 +61,8 @@ PythonWrapper::PythonWrapper()
QObject* PythonWrapper::toQObject(const Py::Object& pyobject) QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
{ {
#if 0
// http://pastebin.com/JByDAF5Z // http://pastebin.com/JByDAF5Z
//#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) #if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
PyTypeObject * type = Shiboken::SbkType<QObject>(); PyTypeObject * type = Shiboken::SbkType<QObject>();
if (type) { if (type) {
if (Shiboken::Object::checkType(pyobject.ptr())) { if (Shiboken::Object::checkType(pyobject.ptr())) {
@ -83,7 +86,16 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
Py::Object PythonWrapper::toPython(QWidget* widget) 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::Module sipmod(PyImport_AddModule((char*)"sip"));
Py::Callable func = sipmod.getDict().getItem("wrapinstance"); Py::Callable func = sipmod.getDict().getItem("wrapinstance");
Py::Tuple arguments(2); Py::Tuple arguments(2);
@ -91,18 +103,33 @@ Py::Object PythonWrapper::toPython(QWidget* widget)
Py::Module qtmod(PyImport_ImportModule((char*)"PyQt4.Qt")); Py::Module qtmod(PyImport_ImportModule((char*)"PyQt4.Qt"));
arguments[1] = qtmod.getDict().getItem("QWidget"); arguments[1] = qtmod.getDict().getItem("QWidget");
return func.apply(arguments); return func.apply(arguments);
#endif
} }
bool PythonWrapper::loadModule() bool PythonWrapper::loadCoreModule()
{ {
#if 0 #if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
//#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) // QtCore
if (SbkPySide_QtCoreTypes) if (!SbkPySide_QtCoreTypes) {
return true; // already loaded
Shiboken::AutoDecRef requiredModule(Shiboken::Module::import("PySide.QtCore")); Shiboken::AutoDecRef requiredModule(Shiboken::Module::import("PySide.QtCore"));
if (requiredModule.isNull()) if (requiredModule.isNull())
return false; return false;
SbkPySide_QtCoreTypes = Shiboken::Module::getTypes(requiredModule); 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 #endif
return true; return true;
} }
@ -311,7 +338,7 @@ Py::Object UiLoaderPy::createWidget(const Py::Tuple& args)
// 2nd argument // 2nd argument
QWidget* parent = 0; QWidget* parent = 0;
if (wrap.loadModule() && args.size() > 1) { if (wrap.loadCoreModule() && args.size() > 1) {
QObject* object = wrap.toQObject(args[1]); QObject* object = wrap.toQObject(args[1]);
if (object) if (object)
parent = qobject_cast<QWidget*>(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, QWidget* widget = loader.createWidget(QString::fromAscii(className.c_str()), parent,
QString::fromAscii(objectName.c_str())); QString::fromAscii(objectName.c_str()));
wrap.loadGuiModule();
return wrap.toPython(widget); return wrap.toPython(widget);
} }

View File

@ -43,7 +43,8 @@ class GuiExport PythonWrapper
{ {
public: public:
PythonWrapper(); PythonWrapper();
bool loadModule(); bool loadCoreModule();
bool loadGuiModule();
QObject* toQObject(const Py::Object&); QObject* toQObject(const Py::Object&);
Py::Object toPython(QWidget*); Py::Object toPython(QWidget*);