0000877: Move from PyQt to PySide

This commit is contained in:
wmayer
2013-06-22 01:56:58 +02:00
parent 367a8f9aee
commit 1dc122dc9a
5 changed files with 159 additions and 56 deletions

View File

@@ -23,6 +23,20 @@
#include "PreCompiled.h"
#if 0 // disable for now
#ifdef HAVE_SHIBOKEN
# undef _POSIX_C_SOURCE
# undef _XOPEN_SOURCE
# include <basewrapper.h>
# include <sbkmodule.h>
# include <typeresolver.h>
# ifdef HAVE_PYSIDE
# include <QtCore/pyside_qtcore_python.h>
PyTypeObject** SbkPySide_QtCoreTypes=NULL;
# endif
#endif
#endif
#include <CXX/Objects.hxx>
#include <App/Application.h>
#include <Base/Console.h>
@@ -37,6 +51,64 @@
using namespace Gui;
PythonWrapper::PythonWrapper()
{
}
QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
{
#if 0
// http://pastebin.com/JByDAF5Z
//#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
PyTypeObject * type = Shiboken::SbkType<QObject>();
if (type) {
if (Shiboken::Object::checkType(pyobject.ptr())) {
SbkObject* sbkobject = reinterpret_cast<SbkObject *>(pyobject.ptr());
void* cppobject = Shiboken::Object::cppPointer(sbkobject, type);
return reinterpret_cast<QObject*>(cppobject);
}
}
#else
Py::Module mainmod(PyImport_AddModule((char*)"sip"));
Py::Callable func = mainmod.getDict().getItem("unwrapinstance");
Py::Tuple arguments(1);
arguments[0] = pyobject; //PyQt pointer
Py::Object result = func.apply(arguments);
void* ptr = PyLong_AsVoidPtr(result.ptr());
return reinterpret_cast<QObject*>(ptr);
#endif
return 0;
}
Py::Object PythonWrapper::toPython(QWidget* widget)
{
// todo: Port to PySide
Py::Module sipmod(PyImport_AddModule((char*)"sip"));
Py::Callable func = sipmod.getDict().getItem("wrapinstance");
Py::Tuple arguments(2);
arguments[0] = Py::asObject(PyLong_FromVoidPtr(widget));
Py::Module qtmod(PyImport_ImportModule((char*)"PyQt4.Qt"));
arguments[1] = qtmod.getDict().getItem("QWidget");
return func.apply(arguments);
}
bool PythonWrapper::loadModule()
{
#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);
#endif
return true;
}
// ----------------------------------------------------
Gui::WidgetFactoryInst* Gui::WidgetFactoryInst::_pcSingleton = NULL;
WidgetFactoryInst& WidgetFactoryInst::instance()
@@ -232,23 +304,17 @@ Py::Object UiLoaderPy::repr()
Py::Object UiLoaderPy::createWidget(const Py::Tuple& args)
{
Py::Module sipmod(PyImport_AddModule((char*)"sip"));
Py::Module qtmod(PyImport_ImportModule((char*)"PyQt4.Qt"));
Gui::PythonWrapper wrap;
// 1st argument
std::string className = (std::string)Py::String(args[0]);
// 2nd argument
QWidget* parent = 0;
if (args.size() > 1) {
Py::Callable func = sipmod.getDict().getItem("unwrapinstance");
Py::Tuple arguments(1);
arguments[0] = args[1]; //PyQt pointer
Py::Object result = func.apply(arguments);
void* ptr = PyLong_AsVoidPtr(result.ptr());
QObject* object = reinterpret_cast<QObject*>(ptr);
if (object)
parent = qobject_cast<QWidget*>(object);
if (wrap.loadModule() && args.size() > 1) {
QObject* object = wrap.toQObject(args[1]);
if (object)
parent = qobject_cast<QWidget*>(object);
}
// 3rd argument
@@ -259,11 +325,7 @@ Py::Object UiLoaderPy::createWidget(const Py::Tuple& args)
QWidget* widget = loader.createWidget(QString::fromAscii(className.c_str()), parent,
QString::fromAscii(objectName.c_str()));
Py::Callable func = sipmod.getDict().getItem("wrapinstance");
Py::Tuple arguments(2);
arguments[0] = Py::asObject(PyLong_FromVoidPtr(widget));
arguments[1] = qtmod.getDict().getItem("QWidget");
return func.apply(arguments);
return wrap.toPython(widget);
}
// ----------------------------------------------------