diff --git a/CMakeLists.txt b/CMakeLists.txt index 71aee4f..a7ffbd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,11 @@ include(cmake/Macros/icecc.cmake) # this must be the first line! project(pysidebindings) cmake_minimum_required(VERSION 2.6) -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules/ - ${CMAKE_SOURCE_DIR}/cmake/Macros/ +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Macros/ ${CMAKE_MODULE_PATH}) -find_package(PythonLibs REQUIRED) -find_package(PythonInterpWithDebug REQUIRED) -find_package(GeneratorRunner 0.6 REQUIRED) -find_package(Shiboken 0.5 REQUIRED) +find_package(Shiboken 1.1.1 REQUIRED) find_package(Qt4 4.5.0 REQUIRED) +find_file(GL_H "gl.h" PATH_SUFFIXES "GL") include(FindQt4Extra) set(XVFB_EXEC "") @@ -18,11 +15,12 @@ option(USE_XVFB "Uses xvfb-run with the unit tests to avoid QtGui tests popping if(USE_XVFB) find_program(XVFB_RUN NAMES xvfb-run) if (NOT ${XVFB_RUN} MATCHES "XVFB_RUN-NOTFOUND") - set(XVFB_EXEC ${XVFB_RUN}) - message("Using xvfb-run to perform QtGui tests.") + set(XVFB_EXEC ${XVFB_RUN} -a) + message(STATUS "Using xvfb-run to perform QtGui tests.") endif() endif() +option(BUILD_TESTS "Build tests." TRUE) option(ENABLE_VERSION_SUFFIX "Used to use current version in suffix to generated files. This is used to allow multiples versions installed simultaneous." FALSE) set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) @@ -33,7 +31,7 @@ endif() if(MSVC) set(CMAKE_CXX_FLAGS "/Zc:wchar_t- /GR /EHsc /DNOCOLOR /DWIN32 /D_WINDOWS /D_SCL_SECURE_NO_WARNINGS") else() - if(CMAKE_HOST_UNIX) + if(CMAKE_HOST_UNIX AND NOT CYGWIN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fvisibility=hidden -Wno-strict-aliasing") endif() set(CMAKE_CXX_FLAGS_DEBUG "-g") @@ -58,20 +56,23 @@ else() endif() if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() - -option(AVOID_PROTECTED_HACK "Avoid protected hack on generated bindings." FALSE) -if(AVOID_PROTECTED_HACK OR WIN32) - add_definitions(-DAVOID_PROTECTED_HACK) - message(STATUS "Avoiding protected hack!") + set(CMAKE_BUILD_TYPE ${SHIBOKEN_BUILD_TYPE}) endif() set(BINDING_NAME PySide) -set(BINDING_API_MAJOR_VERSION "0") -set(BINDING_API_MINOR_VERSION "4") -set(BINDING_API_MICRO_VERSION "2") +set(BINDING_API_MAJOR_VERSION "1") +set(BINDING_API_MINOR_VERSION "1") +set(BINDING_API_MICRO_VERSION "1") +set(BINDING_API_RELEASE_LEVEL "final") # alpha, beta, rc, or final +set(BINDING_API_SERIAL 1) # leave as 0 when release level is final set(BINDING_API_VERSION "${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}.${BINDING_API_MICRO_VERSION}" CACHE STRING "PySide version" FORCE) +if (BINDING_API_RELEASE_LEVEL STREQUAL "final") + set(BINDING_API_VERSION_FULL "${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}.${BINDING_API_MICRO_VERSION}" + CACHE STRING "PySide version [full]" FORCE) +else() + set(BINDING_API_VERSION_FULL "${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}.${BINDING_API_MICRO_VERSION}~${BINDING_API_RELEASE_LEVEL}${BINDING_API_SERIAL}" + CACHE STRING "PySide version [full]" FORCE) +endif() set(PYSIDE_QT_VERSION "${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" CACHE STRING "Qt version used to compile PySide" FORCE) if(ENABLE_VERSION_SUFFIX) set(pyside_SUFFIX "-${BINDING_API_MAJOR_VERSION}.${BINDING_API_MINOR_VERSION}") @@ -115,11 +116,7 @@ else() endif() # Define supported Qt Version -if(${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} GREATER 6) - set(SUPPORTED_QT_VERSION 4.7) -else() - set(SUPPORTED_QT_VERSION 4.6) -endif() +set(SUPPORTED_QT_VERSION "${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}") set(BINDING_VERSION ${BINDING_API_VERSION}.${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}) @@ -131,7 +128,7 @@ add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") -set(ARCHIVE_NAME pyside-qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}+${BINDING_API_VERSION}) +set(ARCHIVE_NAME pyside-qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}+${BINDING_API_VERSION_FULL}) add_custom_target(dist COMMAND mkdir -p "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}" && git log > "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}/ChangeLog" && @@ -143,8 +140,8 @@ add_custom_target(dist if (NOT SITE_PACKAGE) execute_process( - COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; \\ - print sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}')" + COMMAND ${SHIBOKEN_PYTHON_INTERPRETER} -c "from distutils import sysconfig; \\ + print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE SITE_PACKAGE OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT SITE_PACKAGE) @@ -154,41 +151,25 @@ if (NOT SITE_PACKAGE) endif() endif() -# Detect if the python libs were compiled in debug mode -execute_process( - COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; \\ - print sysconfig.get_config_var('Py_DEBUG')" - OUTPUT_VARIABLE PY_DEBUG - OUTPUT_STRIP_TRAILING_WHITESPACE) - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - if(NOT PYTHON_DEBUG_LIBRARIES) - message(FATAL_ERROR "Python debug library not found. Try compile PySide with -DCMAKE_BUILD_TYPE=Release") - endif() - if(NOT PY_DEBUG) - message(WARNING "Compiling PySide with debug enabled, but the python executable was not compiled with debug support.") - else() - add_definitions("-DPy_DEBUG") - endif() - set(PYSIDE_PYTHON_LIBRARIES ${PYTHON_DEBUG_LIBRARIES}) +set(GENERATOR_EXTRA_FLAGS --generator-set=shiboken --enable-parent-ctor-heuristic --enable-pyside-extensions --enable-return-value-heuristic --use-isnull-as-nb_nonzero) +if(WIN32 OR DEFINED AVOID_PROTECTED_HACK) + message(STATUS "PySide will be generated avoiding the protected hack!") + set(GENERATOR_EXTRA_FLAGS ${GENERATOR_EXTRA_FLAGS} --avoid-protected-hack) + add_definitions(-DAVOID_PROTECTED_HACK) else() - set(PYSIDE_PYTHON_LIBRARIES ${PYTHON_LIBRARIES}) + message(STATUS "PySide will be generated using the protected hack!") endif() -if(APPLE) - set(PYSIDE_PYTHON_LIBRARIES "-undefined dynamic_lookup") -endif() - -set(GENERATOR_EXTRA_FLAGS --generatorSet=shiboken --enable-parent-ctor-heuristic --enable-pyside-extensions --enable-return-value-heuristic) - -enable_testing() add_subdirectory(libpyside) -if(QT_QTDESIGNER_FOUND) +if(QT_QTUITOOLS_FOUND AND QT_QTDESIGNER_FOUND) add_subdirectory(plugins) endif() # project directories add_subdirectory(PySide) -add_subdirectory(tests) +if (BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif () find_program(DOT_EXEC dot) if (QT_SRC_DIR AND DOT_EXEC) diff --git a/PySide/CMakeLists.txt b/PySide/CMakeLists.txt index c4aaf64..d8371c0 100644 --- a/PySide/CMakeLists.txt +++ b/PySide/CMakeLists.txt @@ -1,18 +1,13 @@ project(pyside) -install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" "${CMAKE_CURRENT_SOURCE_DIR}/private.py" - DESTINATION "${SITE_PACKAGE}/${BINDING_NAME}${pyside_SUFFIX}") include(PySideModules) # Configure include based on platform configure_file("${CMAKE_CURRENT_SOURCE_DIR}/global.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/global.h" @ONLY) + "${CMAKE_CURRENT_BINARY_DIR}/pyside_global.h" @ONLY) -execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" - "${CMAKE_BINARY_DIR}/PySide/__init__.py") - -execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/private.py" - "${CMAKE_BINARY_DIR}/PySide/private.py") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" + "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY) HAS_QT_MODULE(QT_QTCORE_FOUND QtCore) HAS_QT_MODULE(QT_QTGUI_FOUND QtGui) @@ -23,7 +18,9 @@ HAS_QT_MODULE(QT_QTXML_FOUND QtXml) HAS_QT_MODULE(QT_QTTEST_FOUND QtTest) HAS_QT_MODULE(QT_QTOPENGL_FOUND QtOpenGL) HAS_QT_MODULE(QT_QTSQL_FOUND QtSql) -HAS_QT_MODULE(QT_QTUITOOLS_FOUND QtUiTools) +if(QT_QTDESIGNER_FOUND) + HAS_QT_MODULE(QT_QTUITOOLS_FOUND QtUiTools) +endif() HAS_QT_MODULE(QT_QTHELP_FOUND QtHelp) HAS_QT_MODULE(QT_QTXMLPATTERNS_FOUND QtXmlPatterns) HAS_QT_MODULE(QT_QTMAEMO5_FOUND QtMaemo5) @@ -34,6 +31,10 @@ HAS_QT_MODULE(QT_PHONON_FOUND phonon) HAS_QT_MODULE(QT_QTDECLARATIVE_FOUND QtDeclarative) # install +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" + DESTINATION "${SITE_PACKAGE}/${BINDING_NAME}${pyside_SUFFIX}") install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_templates.xml DESTINATION share/PySide${pyside_SUFFIX}/typesystems) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pyside_global.h + DESTINATION include/${BINDING_NAME}${pyside_SUFFIX}) diff --git a/PySide/QtCore/CMakeLists.txt b/PySide/QtCore/CMakeLists.txt index 554cefb..a2337c0 100644 --- a/PySide/QtCore/CMakeLists.txt +++ b/PySide/QtCore/CMakeLists.txt @@ -1,5 +1,7 @@ project(QtCore) +set(QtCore_gluecode "${CMAKE_CURRENT_SOURCE_DIR}/glue/qeasingcurve_glue.cpp") + if (${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} LESS 6) set (QtCore_46_SRC ) else() @@ -34,7 +36,14 @@ else() ) endif() - +if(ENABLE_WIN) + set(SPECIFIC_OS_FILES + ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/msg_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/point_wrapper.cpp + ) +else() + set(SPECIFIC_OS_FILES "") +endif() set(QtCore_SRC ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qabstracteventdispatcher_wrapper.cpp @@ -60,7 +69,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qdiriterator_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qdynamicpropertychangeevent_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qevent_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qeventloop_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/${BINDING_NAME}/QtCore/qfactoryinterface_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfactoryinterface_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfile_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfileinfo_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qfilesystemwatcher_wrapper.cpp @@ -135,17 +144,22 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qxmlstreamreader_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtCore/qxmlstreamwriter_wrapper.cpp ${QtCore_46_SRC} ${QtCore_47_SRC} +${SPECIFIC_OS_FILES} ) -set(QtCore_typesystem_path "") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/typesystem_core.xml.in" + "${CMAKE_CURRENT_BINARY_DIR}/typesystem_core.xml" @ONLY) + +set(QtCore_typesystem_path "${QtCore_SOURCE_DIR}") + set(QtCore_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${BINDING_NAME}/QtCore/ ${QT_INCLUDE_DIR} ${SHIBOKEN_INCLUDE_DIR} ${libpyside_SOURCE_DIR} - ${PYTHON_INCLUDE_PATH}) + ${SHIBOKEN_PYTHON_INCLUDE_DIR}) set(QtCore_libraries pyside - ${PYSIDE_PYTHON_LIBRARIES} + ${SHIBOKEN_PYTHON_LIBRARIES} ${SHIBOKEN_LIBRARY} ${QT_QTCORE_LIBRARY}) @@ -155,4 +169,5 @@ create_pyside_module(QtCore "" QtCore_typesystem_path QtCore_SRC - "") + QtCore_gluecode + ${CMAKE_CURRENT_BINARY_DIR}/typesystem_core.xml) diff --git a/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp b/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp index 4fd1587..acc7bb9 100644 --- a/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp +++ b/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp @@ -15,10 +15,10 @@ static Py_ssize_t SbkQByteArray_segcountproc(PyObject* self, Py_ssize_t* lenp) static Py_ssize_t SbkQByteArray_readbufferproc(PyObject* self, Py_ssize_t segment, void** ptrptr) { - if (segment || Shiboken::cppObjectIsInvalid(self)) + if (segment || !Shiboken::Object::isValid(self)) return -1; - QByteArray* cppSelf = Converter::toCpp(self); + QByteArray* cppSelf = %CONVERTTOCPP[QByteArray*](self); *ptrptr = reinterpret_cast(cppSelf->data()); return cppSelf->size(); } diff --git a/PySide/QtCore/glue/qcoreapplication_init.cpp b/PySide/QtCore/glue/qcoreapplication_init.cpp index 461757c..c92f03e 100644 --- a/PySide/QtCore/glue/qcoreapplication_init.cpp +++ b/PySide/QtCore/glue/qcoreapplication_init.cpp @@ -2,57 +2,23 @@ static int QCoreApplicationArgCount; static char** QCoreApplicationArgValues; -/** - * Called at QtCore module exit - */ -void DeleteQCoreApplicationAtExit() +void QCoreApplication_constructor(PyObject* self, PyObject* args, QCoreApplicationWrapper** cptr) { - QCoreApplication *cpp = QCoreApplication::instance(); - if (cpp) { - Shiboken::BindingManager &bmngr = Shiboken::BindingManager::instance(); - cpp->flush(); - QCoreApplication::processEvents(); - bmngr.destroyWrapper(cpp); - delete cpp; - } -} - -int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*) -{ - if (Shiboken::isUserType(self) && !Shiboken::canCallConstructor(self->ob_type, Shiboken::SbkType())) - return -1; - - if (QCoreApplication::instance()) { PyErr_SetString(PyExc_RuntimeError, "A QCoreApplication instance already exists."); - return -1; + return; } int numArgs = PyTuple_GET_SIZE(args); - if (numArgs != 1) { + if (numArgs != 1 + || !Shiboken::sequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) { PyErr_BadArgument(); - return -1; + return; } - if (!PySequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) { - PyErr_BadArgument(); - return -1; - } + *cptr = new QCoreApplicationWrapper(QCoreApplicationArgCount, QCoreApplicationArgValues); - QCoreApplicationWrapper* cptr = new QCoreApplicationWrapper(QCoreApplicationArgCount, QCoreApplicationArgValues); - Shiboken::setCppPointer(reinterpret_cast(self), - Shiboken::SbkType(), - cptr); - - SbkBaseWrapper_setValidCppObject(self, 1); - SbkBaseWrapper *sbkSelf = reinterpret_cast(self); - sbkSelf->containsCppWrapper = 1; - sbkSelf->hasOwnership = 0; - Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr); - PySide::signalUpdateSource(self); - cptr->metaObject(); - - PySide::registerCleanupFunction(DeleteQCoreApplicationAtExit); + Shiboken::Object::releaseOwnership(reinterpret_cast(self)); + PySide::registerCleanupFunction(&PySide::destroyQCoreApplication); Py_INCREF(self); - return 1; } diff --git a/PySide/QtCore/glue/qeasingcurve_glue.cpp b/PySide/QtCore/glue/qeasingcurve_glue.cpp new file mode 100644 index 0000000..7f56315 --- /dev/null +++ b/PySide/QtCore/glue/qeasingcurve_glue.cpp @@ -0,0 +1,120 @@ +#include +#include +#include +#include + +#include "glue/qeasingcurve_glue.h" + +#define __ECF_ATT_NAME__ "__ecf__" +#define MAX_CUSTOM_FUNCTIONS 10 + +static void deleteData(void* data); + +struct CustomFunctionsData +{ + static CustomFunctionsData m_list[MAX_CUSTOM_FUNCTIONS]; + + PySideEasingCurveFunctor* m_obj; + QEasingCurve::EasingFunction m_func; +}; + +CustomFunctionsData CustomFunctionsData::m_list[MAX_CUSTOM_FUNCTIONS]; + +template +struct CustomFunctions +{ + static void init() + { + CustomFunctionsData data; + data.m_obj = 0; + data.m_func = &CustomFunctions::callback; + CustomFunctionsData::m_list[N] = data; + + CustomFunctions::init(); + } + + static qreal callback(qreal v) + { + return (*CustomFunctionsData::m_list[N].m_obj)(v); + } +}; + +template<> +struct CustomFunctions<0> +{ + static void init() + { + CustomFunctionsData data; + data.m_obj = 0; + data.m_func = &CustomFunctions<0>::callback; + CustomFunctionsData::m_list[0] = data; + } + + static qreal callback(qreal v) + { + return (*CustomFunctionsData::m_list[0].m_obj)(v); + } +}; + +void deleteData(void* data) +{ + delete (PySideEasingCurveFunctor*)(data); +} + +void PySideEasingCurveFunctor::init() +{ + CustomFunctions::init(); +} + +QEasingCurve::EasingFunction PySideEasingCurveFunctor::createCustomFuntion(PyObject* parent, PyObject* pyFunc) +{ + for(int i=0; i < MAX_CUSTOM_FUNCTIONS; i++) { + CustomFunctionsData& data = CustomFunctionsData::m_list[i]; + if (data.m_obj == 0) { + data.m_obj = new PySideEasingCurveFunctor(i, parent, pyFunc); + return data.m_func; + } + } + //PyErr_Format(PyExc_RuntimeError, "PySide only supports %d custom functions simultaneously.", MAX_CUSTOM_FUNCTIONS); + return 0; +} + +PySideEasingCurveFunctor::~PySideEasingCurveFunctor() +{ + + CustomFunctionsData::m_list[m_index].m_obj = 0; + PyObject_SetAttrString(m_parent, __ECF_ATT_NAME__, Py_None); +} + +qreal PySideEasingCurveFunctor::operator()(qreal progress) +{ + Shiboken::GilState state; + PyObject* args = Py_BuildValue("(f)", progress); + PyObject* result = PyObject_CallObject(m_func, args); + qreal cppResult = 0.0; + if (result) { + Shiboken::Conversions::pythonToCppCopy(Shiboken::Conversions::PrimitiveTypeConverter(), result, &cppResult); + Py_DECREF(result); + } + Py_DECREF(args); + return cppResult; +} + +PyObject* PySideEasingCurveFunctor::callable() +{ + Py_INCREF(m_func); + return m_func; +} + +PyObject* PySideEasingCurveFunctor::callable(PyObject* parent) +{ + return PyObject_GetAttrString(parent, __ECF_ATT_NAME__); +} + +PySideEasingCurveFunctor::PySideEasingCurveFunctor(int index, PyObject* parent, PyObject* pyFunc) + : m_parent(parent), m_func(pyFunc), m_index(index) +{ + PyObject_SetAttrString(m_parent, __ECF_ATT_NAME__, m_func); + PySide::WeakRef::create(m_parent, deleteData, this); +} + diff --git a/PySide/QtCore/glue/qeasingcurve_glue.h b/PySide/QtCore/glue/qeasingcurve_glue.h new file mode 100644 index 0000000..282e439 --- /dev/null +++ b/PySide/QtCore/glue/qeasingcurve_glue.h @@ -0,0 +1,27 @@ +#ifndef __QEASINGCURVE_GLUE__ +#define __QEASINGCURVE_GLUE__ + +#include +#include + +class PySideEasingCurveFunctor +{ + public: + static void init(); + static QEasingCurve::EasingFunction createCustomFuntion(PyObject* parent, PyObject* pyFunc); + + qreal operator()(qreal progress); + + PyObject* callable(); //Return New reference + static PyObject* callable(PyObject* parent); //Return New reference + + ~PySideEasingCurveFunctor(); + private: + PyObject* m_parent; + PyObject* m_func; + int m_index; + + PySideEasingCurveFunctor(int index, PyObject* parent, PyObject *pyFunc); +}; + +#endif diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp index cf78779..96bcfb2 100644 --- a/PySide/QtCore/glue/qobject_connect.cpp +++ b/PySide/QtCore/glue/qobject_connect.cpp @@ -1,23 +1,46 @@ -static bool getReceiver(PyObject *callback, QObject **receiver, PyObject **self) +static bool isDecorator(PyObject* method, PyObject* self) { + Shiboken::AutoDecRef methodName(PyObject_GetAttrString(method, "__name__")); + if (!PyObject_HasAttr(self, methodName)) + return true; + Shiboken::AutoDecRef otherMethod(PyObject_GetAttr(self, methodName)); + return reinterpret_cast(otherMethod.object())->im_func != \ + reinterpret_cast(method)->im_func; +} + +static bool getReceiver(QObject *source, const char* signal, PyObject* callback, QObject** receiver, PyObject** self, QByteArray* callbackSig) +{ + bool forceGlobalReceiver = false; if (PyMethod_Check(callback)) { *self = PyMethod_GET_SELF(callback); - if (Shiboken::Converter::checkType(*self)) - *receiver = Converter::toCpp(*self); + if (%CHECKTYPE[QObject*](*self)) + *receiver = %CONVERTTOCPP[QObject*](*self); + forceGlobalReceiver = isDecorator(callback, *self); } else if (PyCFunction_Check(callback)) { *self = PyCFunction_GET_SELF(callback); - if (*self && Shiboken::Converter::checkType(*self)) - *receiver = Converter::toCpp(*self); + if (*self && %CHECKTYPE[QObject*](*self)) + *receiver = %CONVERTTOCPP[QObject*](*self); } else if (PyCallable_Check(callback)) { // Ok, just a callable object *receiver = 0; *self = 0; } - bool usingGlobalReceiver = !*receiver; + bool usingGlobalReceiver = !*receiver || forceGlobalReceiver; + + // Check if this callback is a overwrite of a non-virtual Qt slot. + if (!usingGlobalReceiver && receiver && self) { + *callbackSig = PySide::Signal::getCallbackSignature(signal, *receiver, callback, usingGlobalReceiver).toAscii(); + const QMetaObject* metaObject = (*receiver)->metaObject(); + int slotIndex = metaObject->indexOfSlot(callbackSig->constData()); + if (slotIndex != -1 && slotIndex < metaObject->methodOffset() && PyMethod_Check(callback)) + usingGlobalReceiver = true; + } + if (usingGlobalReceiver) { PySide::SignalManager& signalManager = PySide::SignalManager::instance(); - *receiver = signalManager.globalReceiver(); + *receiver = signalManager.globalReceiver(source, callback); + *callbackSig = PySide::Signal::getCallbackSignature(signal, *receiver, callback, usingGlobalReceiver).toAscii(); } return usingGlobalReceiver; @@ -28,13 +51,14 @@ static bool qobjectConnect(QObject* source, const char* signal, QObject* receive if (!signal || !slot) return false; - if (!PySide::checkSignal(signal)) + if (!PySide::Signal::checkQtSignal(signal)) return false; signal++; - PySide::SignalManager::registerMetaMethod(source, signal, QMetaMethod::Signal); + if (!PySide::SignalManager::registerMetaMethod(source, signal, QMetaMethod::Signal)) + return false; - bool isSignal = PySide::isSignal(slot); + bool isSignal = PySide::Signal::isQtSignal(slot); slot++; PySide::SignalManager::registerMetaMethod(receiver, slot, isSignal ? QMetaMethod::Signal : QMetaMethod::Slot); return QObject::connect(source, signal - 1, receiver, slot - 1, type); @@ -42,41 +66,52 @@ static bool qobjectConnect(QObject* source, const char* signal, QObject* receive static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject* callback, Qt::ConnectionType type) { - if (!signal || !PySide::checkSignal(signal)) + if (!signal || !PySide::Signal::checkQtSignal(signal)) return false; signal++; - PySide::SignalManager::registerMetaMethod(source, signal, QMetaMethod::Signal); - int signalIndex = source->metaObject()->indexOfMethod(signal); + int signalIndex = PySide::SignalManager::registerMetaMethodGetIndex(source, signal, QMetaMethod::Signal); + if (signalIndex == -1) + return false; PySide::SignalManager& signalManager = PySide::SignalManager::instance(); // Extract receiver from callback QObject* receiver = 0; PyObject* self = 0; - bool usingGlobalReceiver = getReceiver(callback, &receiver, &self); + QByteArray callbackSig; + bool usingGlobalReceiver = getReceiver(source, signal, callback, &receiver, &self, &callbackSig); if (receiver == 0 && self == 0) return false; const QMetaObject* metaObject = receiver->metaObject(); - const QByteArray callbackSig = PySide::getCallbackSignature(signal, receiver, callback, usingGlobalReceiver).toAscii(); const char* slot = callbackSig.constData(); int slotIndex = metaObject->indexOfSlot(slot); + if (slotIndex == -1) { - if (!usingGlobalReceiver && self && !((SbkBaseWrapper*)self)->containsCppWrapper) { + if (!usingGlobalReceiver && self && !Shiboken::Object::hasCppWrapper((SbkObject*)self)) { qWarning() << "You can't add dynamic slots on an object originated from C++."; + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); + return false; } - if (usingGlobalReceiver) { - signalManager.addGlobalSlot(slot, callback); - } else { - PySide::SignalManager::registerMetaMethod(receiver, slot, QMetaMethod::Slot); + + if (usingGlobalReceiver) + slotIndex = signalManager.globalReceiverSlotIndex(receiver, slot); + else + slotIndex = PySide::SignalManager::registerMetaMethodGetIndex(receiver, slot, QMetaMethod::Slot); + + if (slotIndex == -1) { + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); + + return false; } - slotIndex = metaObject->indexOfSlot(slot); } if (QMetaObject::connect(source, signalIndex, receiver, slotIndex, type)) { if (usingGlobalReceiver) - signalManager.globalReceiverConnectNotify(source, slotIndex); + signalManager.notifyGlobalReceiver(receiver); #ifndef AVOID_PROTECTED_HACK source->connectNotify(signal - 1); #else @@ -87,13 +122,17 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject return true; } + + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); + return false; } static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObject* callback) { - if (!PySide::checkSignal(signal)) + if (!PySide::Signal::checkQtSignal(signal)) return false; PySide::SignalManager& signalManager = PySide::SignalManager::instance(); @@ -101,27 +140,28 @@ static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObj // Extract receiver from callback QObject* receiver = 0; PyObject* self = 0; - bool usingGlobalReceiver = getReceiver(callback, &receiver, &self); + QByteArray callbackSig; + bool usingGlobalReceiver = getReceiver(NULL, signal, callback, &receiver, &self, &callbackSig); if (receiver == 0 && self == 0) return false; const QMetaObject* metaObject = receiver->metaObject(); - const QByteArray callbackSig = PySide::getCallbackSignature(signal, receiver, callback, usingGlobalReceiver).toAscii(); - QByteArray qtSlotName(callbackSig); - qtSlotName = qtSlotName.prepend('1'); + int signalIndex = source->metaObject()->indexOfSignal(++signal); + int slotIndex = -1; + + slotIndex = metaObject->indexOfSlot(callbackSig); + + if (QMetaObject::disconnectOne(source, signalIndex, receiver, slotIndex)) { + if (usingGlobalReceiver) + signalManager.releaseGlobalReceiver(source, receiver); - if (QObject::disconnect(source, signal, receiver, qtSlotName.constData())) { - if (usingGlobalReceiver) { - int slotIndex = metaObject->indexOfSlot(callbackSig.constData()); - signalManager.globalReceiverDisconnectNotify(source, slotIndex); #ifndef AVOID_PROTECTED_HACK - source->disconnectNotify(signal - 1); + source->disconnectNotify(callbackSig); #else // Need to cast to QObjectWrapper* and call the public version of // connectNotify when avoiding the protected hack. - reinterpret_cast(source)->disconnectNotify(signal - 1); + reinterpret_cast(source)->disconnectNotify(callbackSig); #endif - } return true; } return false; diff --git a/PySide/QtCore/glue/qobject_findchild.cpp b/PySide/QtCore/glue/qobject_findchild.cpp index 351aa69..669beac 100644 --- a/PySide/QtCore/glue/qobject_findchild.cpp +++ b/PySide/QtCore/glue/qobject_findchild.cpp @@ -17,14 +17,23 @@ static QObject* _findChildHelper(const QObject* parent, const QString& name, PyT return 0; } -static void _findChildrenHelper(const QObject* parent, const QString& name, PyTypeObject* desiredType, PyObject* result) +static inline bool _findChildrenComparator(const QObject*& child, const QRegExp& name) { - foreach(QObject* child, parent->children()) { + return name.indexIn(child->objectName()) != -1; +} + +static inline bool _findChildrenComparator(const QObject*& child, const QString& name) +{ + return name.isNull() || name == child->objectName(); +} + +template +static void _findChildrenHelper(const QObject* parent, const T& name, PyTypeObject* desiredType, PyObject* result) +{ + foreach(const QObject* child, parent->children()) { Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject*](child)); - if (PyType_IsSubtype(pyChild->ob_type, desiredType) - && (name.isNull() || name == child->objectName())) { + if (PyType_IsSubtype(pyChild->ob_type, desiredType) && _findChildrenComparator(child, name)) PyList_Append(result, pyChild); - } _findChildrenHelper(child, name, desiredType, result); } -} \ No newline at end of file +} diff --git a/PySide/QtCore/qbool_conversions.h b/PySide/QtCore/qbool_conversions.h deleted file mode 100644 index f4fb43f..0000000 --- a/PySide/QtCore/qbool_conversions.h +++ /dev/null @@ -1,16 +0,0 @@ -namespace Shiboken { -template <> -struct Converter : public ValueTypeConverter -{ - using ValueTypeConverter::toPython; - - static PyObject* toPython(const QBool& cppobj) - { - return PyBool_FromLong((bool) cppobj); - } - static QBool toCpp(PyObject* pyobj) - { - return QBool(pyobj == Py_True); - } -}; -} diff --git a/PySide/QtCore/qchar_conversions.h b/PySide/QtCore/qchar_conversions.h deleted file mode 100644 index 1ebcb64..0000000 --- a/PySide/QtCore/qchar_conversions.h +++ /dev/null @@ -1,35 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return PyString_Check(pyObj) && (PyString_Size(pyObj) == 1); - } - - static bool isConvertible(PyObject* pyObj) - { - return (PyString_Check(pyObj) && (PyString_Size(pyObj) == 1)) - || pyObj == Py_None - || PyInt_Check(pyObj); - } - - static QChar toCpp(PyObject* pyObj) - { - if (PyString_Check(pyObj) && PyString_Size(pyObj) == 1) - return QChar(Shiboken::Converter::toCpp(pyObj)); - else if (PyInt_Check(pyObj)) - return QChar(Shiboken::Converter::toCpp(pyObj)); - return QChar(); - } - - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - static PyObject* toPython(const QChar& cppObj) - { - wchar_t c = (wchar_t)cppObj.unicode(); - PyObject* pyObj = PyUnicode_FromWideChar(&c, 1); - return pyObj; - } -}; -} diff --git a/PySide/QtCore/qdate_conversions.h b/PySide/QtCore/qdate_conversions.h deleted file mode 100644 index e0f1dd9..0000000 --- a/PySide/QtCore/qdate_conversions.h +++ /dev/null @@ -1,35 +0,0 @@ -namespace Shiboken { -template <> -struct PythonConverter -{ - static bool isPythonConvertible(PyObject* pyObj) - { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return pyObj && PyDate_Check(pyObj); - } - - static QDate* transformFromPython(PyObject* obj) - { - if (isPythonConvertible(obj)) { - int day = PyDateTime_GET_DAY(obj); - int month = PyDateTime_GET_MONTH(obj); - int year = PyDateTime_GET_YEAR(obj); - return new QDate(year, month, day); - } - return 0; - } - - static PyObject* transformToPython(QDate* d) - { - if (d) { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return PyDate_FromDate(d->year(), d->month(), d->day()); - } - return 0; - } -}; -} diff --git a/PySide/QtCore/qdatetime_conversions.h b/PySide/QtCore/qdatetime_conversions.h deleted file mode 100644 index a3cdf09..0000000 --- a/PySide/QtCore/qdatetime_conversions.h +++ /dev/null @@ -1,41 +0,0 @@ -namespace Shiboken { -template <> -struct PythonConverter -{ - static bool isPythonConvertible(PyObject* pyObj) - { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return pyObj && PyDateTime_Check(pyObj); - } - - static QDateTime* transformFromPython(PyObject* obj) - { - if (isPythonConvertible(obj)) { - int day = PyDateTime_GET_DAY(obj); - int month = PyDateTime_GET_MONTH(obj); - int year = PyDateTime_GET_YEAR(obj); - int hour = PyDateTime_DATE_GET_HOUR(obj); - int min = PyDateTime_DATE_GET_MINUTE(obj); - int sec = PyDateTime_DATE_GET_SECOND(obj); - int msec = PyDateTime_DATE_GET_MICROSECOND(obj); - return new QDateTime(QDate(year, month, day), QTime(hour, min, sec, msec)); - } - return 0; - } - - static PyObject* transformToPython(QDateTime* d) - { - if (d) { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - QDate date = d->date(); - QTime time = d->time(); - return PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec()); - } - return 0; - } -}; -} diff --git a/PySide/QtCore/qhash_conversions.h b/PySide/QtCore/qhash_conversions.h deleted file mode 100644 index f9e2e42..0000000 --- a/PySide/QtCore/qhash_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QtDictConverter > {}; -} diff --git a/PySide/QtCore/qlist_conversions.h b/PySide/QtCore/qlist_conversions.h deleted file mode 100644 index cb1d26b..0000000 --- a/PySide/QtCore/qlist_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdListConverter > {}; -} diff --git a/PySide/QtCore/qmap_conversions.h b/PySide/QtCore/qmap_conversions.h deleted file mode 100644 index 3153fae..0000000 --- a/PySide/QtCore/qmap_conversions.h +++ /dev/null @@ -1,5 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QtDictConverter > { -}; -} diff --git a/PySide/QtCore/qmultimap_conversions.h b/PySide/QtCore/qmultimap_conversions.h deleted file mode 100644 index 43abd84..0000000 --- a/PySide/QtCore/qmultimap_conversions.h +++ /dev/null @@ -1,5 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QtMultiMapConverter > { -}; -} diff --git a/PySide/QtCore/qpair_conversions.h b/PySide/QtCore/qpair_conversions.h deleted file mode 100644 index 99e9cd8..0000000 --- a/PySide/QtCore/qpair_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdPairConverter > {}; -} diff --git a/PySide/QtCore/qset_conversions.h b/PySide/QtCore/qset_conversions.h deleted file mode 100644 index c46fef0..0000000 --- a/PySide/QtCore/qset_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : QSequenceConverter > {}; -} diff --git a/PySide/QtCore/qstack_conversion.h b/PySide/QtCore/qstack_conversion.h deleted file mode 100644 index 709a918..0000000 --- a/PySide/QtCore/qstack_conversion.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdListConverter > {}; -} diff --git a/PySide/QtCore/qstring_conversions.h b/PySide/QtCore/qstring_conversions.h deleted file mode 100644 index 670c01f..0000000 --- a/PySide/QtCore/qstring_conversions.h +++ /dev/null @@ -1,80 +0,0 @@ -namespace Shiboken { - -template<> -inline PyTypeObject* SbkType() -{ - return &PyUnicode_Type; -} - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return PyString_Check(pyObj) || PyUnicode_Check(pyObj); - } - - static bool isConvertible(PyObject* pyObj) - { - return PyString_Check(pyObj) - || PyUnicode_Check(pyObj) - || Converter::checkType(pyObj) - || pyObj == Py_None - #if PY_VERSION_HEX < 0x03000000 - || (pyObj->ob_type->tp_as_buffer - && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER) - && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) - #endif - ; - } - - static QString toCpp(PyObject* pyObj) - { - if (PyUnicode_Check(pyObj)) { - Py_UNICODE* unicode = PyUnicode_AS_UNICODE(pyObj); - #if defined(Py_UNICODE_WIDE) - // cast as Py_UNICODE can be a different type - return QString::fromUcs4(reinterpret_cast(unicode)); - #else - return QString::fromUtf16(unicode, PyUnicode_GET_SIZE(pyObj)); - #endif - } else if (PyString_Check(pyObj)) { - return QString(Converter< char * >::toCpp(pyObj)); - } else if (pyObj == Py_None) { - return QString(); - } else if (Converter::checkType(pyObj)) { - return QString(Converter< QByteArray >::toCpp(pyObj)); - } -#if PY_VERSION_HEX < 0x03000000 - // Support for buffer objects on QString constructor - else if (pyObj->ob_type->tp_as_buffer - && PyType_HasFeature(pyObj->ob_type, Py_TPFLAGS_HAVE_GETCHARBUFFER) - && pyObj->ob_type->tp_as_buffer->bf_getcharbuffer) { - QByteArray data; - PyBufferProcs* bufferProcs = pyObj->ob_type->tp_as_buffer; - int segments = bufferProcs->bf_getsegcount(pyObj, 0); - for (int i = 0; i < segments; ++i) { - char* segmentData; - int length = bufferProcs->bf_getcharbuffer(pyObj, i, &segmentData); - if (length == -1) - break; - data.append(segmentData, length); - } - return QString(data); - } - #endif - return QString(); - } - - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - static PyObject* toPython(const QString& cppObj) - { - const int N = cppObj.length(); - wchar_t* str = new wchar_t[N]; - cppObj.toWCharArray(str); - PyObject* pyObj = PyUnicode_FromWideChar(str, N); - delete[] str; - return pyObj; - } -}; -} diff --git a/PySide/QtCore/qstringlist_conversions.h b/PySide/QtCore/qstringlist_conversions.h deleted file mode 100644 index 6075c16..0000000 --- a/PySide/QtCore/qstringlist_conversions.h +++ /dev/null @@ -1,5 +0,0 @@ -namespace Shiboken -{ -template<> -struct Converter : StdListConverter {}; -} diff --git a/PySide/QtCore/qstringref_conversions.h b/PySide/QtCore/qstringref_conversions.h deleted file mode 100644 index db3eefc..0000000 --- a/PySide/QtCore/qstringref_conversions.h +++ /dev/null @@ -1,18 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter : public Converter -{ - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - - static PyObject* toPython(const QStringRef& cppObj) - { - return Converter::toPython(cppObj.toString()); - } - - static QStringRef toCpp(PyObject* pyObj) - { - return QStringRef(); - } -}; -} diff --git a/PySide/QtCore/qtime_conversions.h b/PySide/QtCore/qtime_conversions.h deleted file mode 100644 index 5e172fa..0000000 --- a/PySide/QtCore/qtime_conversions.h +++ /dev/null @@ -1,36 +0,0 @@ -namespace Shiboken { -template <> -struct PythonConverter -{ - static bool isPythonConvertible(PyObject* pyObj) - { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return pyObj && PyTime_Check(pyObj); - } - - static QTime* transformFromPython(PyObject* obj) - { - if (isPythonConvertible(obj)) { - int hour = PyDateTime_TIME_GET_HOUR(obj); - int min = PyDateTime_TIME_GET_MINUTE(obj); - int sec = PyDateTime_TIME_GET_SECOND(obj); - int msec = PyDateTime_TIME_GET_MICROSECOND(obj); - return new QTime(hour, min, sec, msec); - } - return 0; - } - - static PyObject* transformToPython(QTime* d) - { - if (d) { - if (!PyDateTimeAPI) - PyDateTime_IMPORT; - - return PyTime_FromTime(d->hour(), d->minute(), d->second(), d->msec()); - } - return 0; - } -}; -} diff --git a/PySide/QtCore/qvariant_conversions.h b/PySide/QtCore/qvariant_conversions.h deleted file mode 100644 index fc2dca5..0000000 --- a/PySide/QtCore/qvariant_conversions.h +++ /dev/null @@ -1,143 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return false; // lets avoid the chaos - } - - // all types are convertible to QVariant - static bool isConvertible(PyObject* pyObj) - { - return true; - } - - static QVariant toCpp(PyObject* pyObj) - { - using namespace Shiboken; - - // Primitive types - if (Converter::checkType(pyObj)) { - // QVariant(bool) - return QVariant(Converter::toCpp(pyObj)); - } else if (pyObj == Py_None) { - // QVariant() - return QVariant(); - } else if (Converter::checkType(pyObj)) { - // QVariant(const char*) - return QVariant(Converter::toCpp(pyObj)); - } else if (Converter::checkType(pyObj)) { - // QVariant(QByteArray) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyFloat_CheckExact(pyObj)) { - // QVariant(double) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyInt_Check(pyObj)) { - // QVariant(int) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyLong_CheckExact(pyObj)) { - // QVariant(qlonglong) - return QVariant(Converter::toCpp(pyObj)); - } else if (Shiboken::isShibokenEnum(pyObj)) { - // QVariant(enum) - return QVariant(Converter::toCpp(pyObj)); - } else if (PyDict_Check(pyObj)) { - return convertToVariantMap(pyObj); - } else if (PySequence_Check(pyObj)) { - return convertToVariantList(pyObj); - } else { - // a class supported by QVariant? - if (Shiboken::isShibokenType(pyObj)) { - Shiboken::SbkBaseWrapperType *objType = reinterpret_cast(pyObj->ob_type); - const char* typeName = objType->original_name; - uint typeCode = QMetaType::type(typeName); - if (typeCode) { - void** data = reinterpret_cast(pyObj)->cptr; - if (typeName[strlen(typeName)-1] == '*') - return QVariant(typeCode, data); - else if (!isUserType(pyObj)) // User types inherited from Value types *should* not be converted. - return QVariant(typeCode, data[0]); - } - } - // Is a shiboken type not known by Qt - return QVariant::fromValue(pyObj); - } - } - - static PyObject* toPython(void* cppObj) - { - return toPython(*reinterpret_cast(cppObj)); - } - - static PyObject* toPython(const QVariant& cppObj) - { - if (cppObj.isValid()) { - if (qstrcmp(cppObj.typeName(), "QVariantList") == 0) - return Converter >::toPython(cppObj.value()); - - if (qstrcmp(cppObj.typeName(), "QStringList") == 0) - return Converter >::toPython(cppObj.value()); - - if (qstrcmp(cppObj.typeName(), "QVariantMap") == 0) - return Converter >::toPython(cppObj.value()); - - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(cppObj.typeName()); - if (tr) - return tr->toPython(const_cast(cppObj.data())); - } - Py_RETURN_NONE; - } - - static QVariant convertToVariantMap(PyObject* map) - { - PyObject *key, *value; - Py_ssize_t pos = 0; - AutoDecRef keys(PyDict_Keys(map)); - bool keysIsString = isStringList(keys); - if (keysIsString) { - QMap ret; - while (PyDict_Next(map, &pos, &key, &value)) - ret.insert(Converter::toCpp(key), toCpp(value)); - return QVariant(ret); - } else { - return toCpp(map); - } - } - - static bool isStringList(PyObject *list) - { - bool allString = true; - AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); - Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); - for(int i=0; i < size; i++) { - PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); - if (!Converter::checkType(item)) { - allString = false; - break; - } - } - return allString; - } - - static QVariant convertToVariantList(PyObject* list) - { - bool allString = isStringList(list); - if (allString) { - QStringList lst = Converter >::toCpp(list); - return QVariant(lst); - } else { - QList lst; - AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); - Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); - for(int i=0; i < size; i++) { - PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); - lst.append(toCpp(item)); - } - return QVariant(lst); - } - Q_ASSERT(false); - } -}; -} diff --git a/PySide/QtCore/qvariant_type_conversions.h b/PySide/QtCore/qvariant_type_conversions.h deleted file mode 100644 index e5384cd..0000000 --- a/PySide/QtCore/qvariant_type_conversions.h +++ /dev/null @@ -1,87 +0,0 @@ -namespace Shiboken { - -template<> -struct Converter -{ - static bool checkType(PyObject* pyObj) - { - return pyObj == Py_None || PyType_Check(pyObj) || Converter::checkType(pyObj); - } - - static bool isConvertible(PyObject* pyObj) - { - return checkType(pyObj); - } - - static QVariant::Type toCpp(PyObject* pyObj) - { - const char* typeName = 0; - if (pyObj == Py_None) - return QVariant::Invalid; - - if (pyObj == reinterpret_cast(&PyString_Type) || pyObj == reinterpret_cast(&PyUnicode_Type)) - typeName = "QString"; - else if (pyObj == reinterpret_cast(&PyFloat_Type)) - typeName = "double"; // float is a UserType in QVariant. - else if (pyObj == reinterpret_cast(&PyLong_Type)) - typeName = "int"; // long is a UserType in QVariant. - else if (PyType_Check(pyObj)) { - if (pyObj->ob_type == &Shiboken::SbkBaseWrapperType_Type) - typeName = reinterpret_cast(pyObj)->original_name; - else - typeName = reinterpret_cast(pyObj)->tp_name; - } - else if (PyString_Check(pyObj)) - typeName = PyString_AS_STRING(pyObj); - else if (PyUnicode_Check(pyObj)) - typeName = PyString_AsString(pyObj); - else if (PyDict_Check(pyObj) && checkAllStringKeys(pyObj)) - typeName = "QVariantMap"; - else if (PySequence_Check(pyObj)) - if (isStringList(pyObj)) - typeName = "QStringList"; - else - typeName = "QVariantList"; - else - Q_ASSERT(false); - - return QVariant::nameToType(typeName); - } - - static PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast(cppObj)); } - static PyObject* toPython(const QVariant::Type& cppObj) - { - const char* typeName = QVariant::typeToName(cppObj); - PyObject* pyObj; - if (!typeName) { - pyObj = Py_None; - } else { - Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(typeName); - pyObj = tr ? reinterpret_cast(tr->pythonType()) : Py_None; - } - Py_INCREF(pyObj); - return pyObj; - } - - static bool isStringList(PyObject* list) - { - bool allString = true; - AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); - Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); - for(int i=0; i < size; i++) { - PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); - if (!Converter::checkType(item)) { - allString = false; - break; - } - } - return allString; - } - - static bool checkAllStringKeys(PyObject* dict) - { - AutoDecRef keys(PyDict_Keys(dict)); - return isStringList(keys); - } -}; -} diff --git a/PySide/QtCore/qvector_conversions.h b/PySide/QtCore/qvector_conversions.h deleted file mode 100644 index 0857036..0000000 --- a/PySide/QtCore/qvector_conversions.h +++ /dev/null @@ -1,4 +0,0 @@ -namespace Shiboken { -template -struct Converter > : StdListConverter > {}; -} diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml deleted file mode 100644 index db7777e..0000000 --- a/PySide/QtCore/typesystem_core.xml +++ /dev/null @@ -1,2656 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %PYARG_0 = %CONVERTTOPYTHON[double](qAbs(%1)); - - - - - PyModule_AddIntConstant(module, "QT_VERSION", QT_VERSION); - PyModule_AddStringConstant(module, "QT_VERSION_STR", QT_VERSION_STR); - - - - - PySide::runCleanupFunctions(); - - - - - - Shiboken::TypeResolver::createValueTypeResolver<QString>("unicode"); - Shiboken::TypeResolver::createValueTypeResolver<QString>("str"); - PySide::init(module); - Py_AtExit(QtCoreModuleExit); - - - #include <pyside.h> - - - - // Define a global variable to handle qInstallMsgHandler callback - static PyObject* qtmsghandler = 0; - - void - msghandlercallback(QtMsgType type, const char* msg) - { - Shiboken::AutoDecRef arglist(Shiboken::makeTuple(type, msg)); - Shiboken::AutoDecRef ret(PyObject_CallObject(qtmsghandler, arglist)); - } - void QtCoreModuleExit() - { - PySide::SignalManager::instance().clear(); - } - - - - if (%PYARG_1 == Py_None) { - qInstallMsgHandler(0); - %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None; - qtmsghandler = 0; - } else if (!PyCallable_Check(%PYARG_1)) { - PyErr_SetString(PyExc_TypeError, "parameter must be callable"); - } else { - %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None; - Py_INCREF(%PYARG_1); - qtmsghandler = %PYARG_1; - qInstallMsgHandler(msghandlercallback); - } - - if (%PYARG_0 == Py_None) - Py_INCREF(%PYARG_0); - - - - - - - - - - - - - - - - - namespace PySide { - template<> inline uint hash(const QLine& v) { - return qHash(qMakePair(qMakePair(v.x1(), v.y1()), qMakePair(v.x2(), v.y2()))); - } - }; - - - - - - - - - - - - - QPointF p; - %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, &p); - %PYARG_0 = Shiboken::makeTuple(retval, p); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int year, month, day; - %CPPSELF.%FUNCTION_NAME(&year, &month, &day); - %PYARG_0 = Shiboken::makeTuple(year, month, day); - - - - - - - - - - - int yearNumber; - int week = %CPPSELF.%FUNCTION_NAME(&yearNumber); - %PYARG_0 = Shiboken::makeTuple(week, yearNumber); - - - - - - - - - - - - - - - - - - - - namespace PySide { - template<> inline uint hash(const QPoint& v) { - return qHash(qMakePair(v.x(), v.y())); - } - }; - - - - - - - - - - - namespace PySide { - template<> inline uint hash(const QRect& v) { - return qHash(qMakePair(qMakePair(v.x(), v.y()), qMakePair(v.width(), v.height()))); - } - }; - - - - - - - - - - - - - - - - - - - - namespace PySide { - template<> inline uint hash(const QSize& v) { - return qHash(qMakePair(v.width(), v.height())); - } - }; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - return %CPPSELF.size(); - - - - - if (_i < 0 || _i >= %CPPSELF.size()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - return 0; - } - return %CONVERTTOPYTHON[bool](%CPPSELF.at(_i)); - - - - - PyObject* args = Py_BuildValue("(iiO)", _i, 1, _value); - PyObject* result = SbkQBitArrayFunc_setBit(self, args); - Py_DECREF(args); - Py_XDECREF(result); - return !result ? -1 : 0; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.%FUNCTION_NAME(%1, %2, %PYARG_3)); - - - - - - - - - - - - - - - - - - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.%FUNCTION_NAME()); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnect(%1, %2, %CPPSELF, %3, %4)); - - - - - - - - // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnect(%1, %2, %3, %4, %5)); - - - - - - - - - - // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnectCallback(%1, %2, %PYARG_3, %4)); - - - - - - - - - - // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnectCallback(%CPPSELF, %1, %PYARG_2, %3)); - - - - - - - - - // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectConnect(%CPPSELF, %1, %2, %3, %4)); - - - - - %PYARG_0 = %CONVERTTOPYTHON[bool](PySide::SignalManager::instance().emitSignal(%CPPSELF, %1, %PYARG_2)); - - - - - // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectDisconnectCallback(%CPPSELF, %1, %2)); - - - - - // %FUNCTION_NAME() - disable generation of function call. - %PYARG_0 = %CONVERTTOPYTHON[bool](qobjectDisconnectCallback(%1, %2, %3)); - - - - static bool - qobjectInheritsInternal(PyTypeObject *objType, const char *class_name) - { - if (strcmp(objType->tp_name, class_name) == 0) - return true; - - PyTypeObject* base = (objType)->tp_base; - if (base == 0) - return false; - return qobjectInheritsInternal(base, class_name); - } - - - - bool retval = qobjectInheritsInternal(self->ob_type, %1) ? true : %CPPSELF.%FUNCTION_NAME(%1); - %PYARG_0 = %CONVERTTOPYTHON[bool](retval); - - - - - - - - - - %PYARG_0 = %CONVERTTOPYTHON[QObject*](_findChildHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1)); - - - - - - - - - - - %PYARG_0 = PyList_New(0); - _findChildrenHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1, %PYARG_0); - - - - - - - - - - - - - - - - QString result; - if (QCoreApplication::instance()) { - PyObject *klass = PyObject_GetAttrString(%PYSELF, "__class__"); - PyObject *cname = PyObject_GetAttrString(klass, "__name__"); - result = QString(QCoreApplication::instance()->translate(PyString_AsString(cname), %1, %2, QCoreApplication::CodecForTr, %3)); - - Py_DECREF(klass); - Py_DECREF(cname); - } else { - result = QString(QString::fromLatin1(%1)); - } - %PYARG_0 = %CONVERTTOPYTHON[QString](result); - - - - - - - - - - - - QString result; - if (QCoreApplication::instance()) { - PyObject *klass = PyObject_GetAttrString(%PYSELF, "__class__"); - PyObject *cname = PyObject_GetAttrString(klass, "__name__"); - result = QString(QCoreApplication::instance()->translate(PyString_AsString(cname), %1, %2, QCoreApplication::UnicodeUTF8, %3)); - - Py_DECREF(klass); - Py_DECREF(cname); - } else { - result = QString(QString::fromLatin1(%1)); - } - %PYARG_0 = %CONVERTTOPYTHON[QString](result); - - - - - - // Avoid return +1 because SignalManager connect to "destroyed()" signal to control object timelife - int ret = %CPPSELF.%FUNCTION_NAME(%1); - if (ret > 0 && ((strcmp(%1, SIGNAL(destroyed())) == 0) || (strcmp(%1, SIGNAL(destroyed(QObject*))) == 0))) { - if (PySide::SignalManager::instance().hasConnectionWith(%CPPSELF)) - ret--; - } - %PYARG_0 = %CONVERTTOPYTHON[int](ret); - - - - - - - - - - - - - - - - - - - - - - - - - - <para>URLs can be represented in two forms: encoded or unencoded. The unencoded representation is suitable for showing to users, but the encoded representation is typically what you would send to a web server. For example, the unencoded URL "http://bühler.example.com" would be sent to the server as "http://xn--bhler-kva.example.com/List%20of%20applicants.xml".</para> - - - - - - - - - - - - - - - - - - - - - - - - - - int size = PyString_Size(pyargs[0]); - %0 = new QByteArray(cpp_arg0, size); - - - - - - #if PY_VERSION_HEX < 0x03000000 - Shiboken::SbkType<QByteArray>()->tp_as_buffer = &SbkQByteArrayBufferProc; - Shiboken::SbkType<QByteArray>()->tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER; - #endif - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - char c = PyString_AS_STRING(%PYARG_1)[0]; - if (c) { - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.%FUNCTION_NAME(c)); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %PYARG_0 = PyString_FromString(%CPPSELF.data()); - - - - - return %CPPSELF.count(); - - - - - if (_i < 0 || _i >= %CPPSELF.size()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - return 0; - } else { - char res[2]; - res[0] = %CPPSELF.at(_i); - res[1] = 0; - return PyString_FromString(res); - } - - - - - %CPPSELF.remove(_i, 1); - PyObject* args = Py_BuildValue("(nO)", _i, _value); - PyObject* result = SbkQByteArrayFunc_insert(self, args); - Py_DECREF(args); - Py_XDECREF(result); - return !result ? -1 : 0; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // %FUNCTION_NAME() - disable generation of c++ function call - (void) %2; // remove warning about unused variable - Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); - PyObject* pyTimer = Shiboken::SbkType<QTimer>()->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); - Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); - - QTimer* timer = Converter<QTimer*>::toCpp(pyTimer); - Shiboken::AutoDecRef result( - PyObject_CallMethod(pyTimer, - const_cast<char*>("connect"), - const_cast<char*>("OsOs"), - pyTimer, - SIGNAL(timeout()), - %PYARG_2, - %3) - ); - // invalidate to avoid use of python object - Shiboken::BindingManager::instance().destroyWrapper((Shiboken::SbkBaseWrapper *)pyTimer); - timer->setSingleShot(true); - timer->connect(timer, SIGNAL("timeout()"), timer, SLOT("deleteLater()")); - timer->start(%1); - - - - - // %FUNCTION_NAME() - disable generation of c++ function call - Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); - PyObject* pyTimer = Shiboken::SbkType<QTimer>()->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); - Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); - QTimer* timer = Converter<QTimer*>::toCpp(pyTimer); - timer->setSingleShot(true); - timer->connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); - - Shiboken::AutoDecRef result( - PyObject_CallMethod(pyTimer, - const_cast<char*>("connect"), - const_cast<char*>("OsO"), - pyTimer, - SIGNAL(timeout()), - pyargs[1]) - ); - Shiboken::BindingManager::instance().destroyWrapper((Shiboken::SbkBaseWrapper *)pyTimer); - timer->start(%1); - - - - - - if (!PyObject_TypeCheck(%2, &PySide::SignalInstance_Type)) - goto Sbk%TYPEFunc_%FUNCTION_NAME_TypeError; - - // %FUNCTION_NAME() - disable generation of c++ function call - Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); - PyObject* pyTimer = Shiboken::SbkType<QTimer>()->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); - Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); - QTimer* timer = Converter<QTimer*>::toCpp(pyTimer); - timer->setSingleShot(true); - timer->connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); - PySide::SignalInstanceData* signalInstance = reinterpret_cast<PySide::SignalInstanceData*>(%2); - Shiboken::AutoDecRef signalSignature(PyString_FromFormat("2%s", signalInstance->signature)); - Shiboken::AutoDecRef result( - PyObject_CallMethod(pyTimer, - const_cast<char*>("connect"), - const_cast<char*>("OsOO"), - pyTimer, - SIGNAL(timeout()), - signalInstance->source, - signalSignature.object()) - ); - Shiboken::BindingManager::instance().destroyWrapper((Shiboken::SbkBaseWrapper *)pyTimer); - timer->start(%1); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - qint64 pid; - %RETURN_TYPE retval = %TYPE::%FUNCTION_NAME(%1, %2, %3, &pid); - %PYARG_0 = Shiboken::makeTuple(retval, pid); - - - - - - - - - - - - - -.. class:: QCoreApplication(args) - - Constructs a Qt kernel application. Kernel applications are applications - without a graphical user interface. These type of applications are used - at the console or as server processes. - - The *args* argument is processed by the application, and made available - in a more convenient form by the :meth:`~QCoreApplication.arguments()` - method. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *(%CPPSELF) << %1; - - - - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); - - - - - *(%CPPSELF) << %1; - - - - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); - - - - - *(%CPPSELF) << %1; - - - - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); - - - - - *(%CPPSELF) << %1; - - - - - %RETURN_TYPE val; - *(%CPPSELF) >> val; - %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](val); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %PYARG_0 = (PyObject*)%CPPSELF.%FUNCTION_NAME(); - if (!%PYARG_0) - %PYARG_0 = Py_None; - Py_XINCREF(%PYARG_0); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - for(int counter = 0; counter < %CPPSELF.animationCount(); ++counter ) { - PyObject* obj = %CONVERTTOPYTHON[QAbstractAnimation*](%CPPSELF.animationAt(counter)); - Shiboken::setParent(NULL, obj); - Py_DECREF(obj); - } - %CPPSELF.clear(); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - QString signalName(%2); - if (PySide::SignalManager::registerMetaMethod(%1, signalName.mid(1).toAscii().data(), QMetaMethod::Signal)) { - %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%CPPSELF->addTransition(%1, %2, %3)); - } else { - %PYARG_0 = Py_None; - } - - - - - - - - - - - - - - - - // Obviously the label used by the following goto is a very awkward solution, - // since it refers to a name very tied to the generator implementation. - // Check bug #362 for more information on this - // http://bugs.openbossa.org/show_bug.cgi?id=362 - if (!PyObject_TypeCheck(%1, &PySide::SignalInstance_Type)) - goto Sbk%TYPEFunc_%FUNCTION_NAME_TypeError; - PySide::SignalInstanceData* signalInstance = reinterpret_cast<PySide::SignalInstanceData*>(%1); - QObject* sender = %CONVERTTOCPP[QObject*](signalInstance->source); - %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%CPPSELF->%FUNCTION_NAME(sender, signalInstance->signature, %2)); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %PYARG_0 = PySet_New(0); - foreach(QAbstractState* abs_state, %CPPSELF.configuration()) { - Shiboken::AutoDecRef obj(%CONVERTTOPYTHON[QAbstractState*](abs_state)); - Shiboken::setParent(self, obj); - PySet_Add(%PYARG_0, obj); - } - - - - - - %PYARG_0 = PyList_New(0); - foreach(QAbstractAnimation* abs_anim, %CPPSELF.defaultAnimations()) { - Shiboken::AutoDecRef obj(%CONVERTTOPYTHON[QAbstractAnimation*](abs_anim)); - Shiboken::setParent(self, obj); - PyList_Append(%PYARG_0, obj); - } - - - - - - - - - - - %PYARG_0 = PyString_FromFormat("2%s", QMetaObject::normalizedSignature(%1).constData()); - - - - - - %PYARG_0 = PyString_FromFormat("1%s", QMetaObject::normalizedSignature(%1).constData()); - - - - - (void)%1;%PYARG_0 = %PYARG_1; - - - (void)%1;%PYARG_0 = %PYARG_1; - - - (void)%1;(void)%2;%PYARG_0 = %PYARG_2; - - - (void)%1;(void)%2;(void)%3;%PYARG_0 = %PYARG_2; - - - (void)%1;%PYARG_0 = %PYARG_1; - - - - extern bool - qRegisterResourceData(int, - const unsigned char *, - const unsigned char *, - const unsigned char *); - - extern bool - qUnregisterResourceData(int, - const unsigned char *, - const unsigned char *, - const unsigned char *); - - - - %PYARG_0 = %CONVERTTOPYTHON[bool](%FUNCTION_NAME(%1, (uchar*)%2, (uchar*)%3, (uchar*)%4)); - - - - - %PYARG_0 = %CONVERTTOPYTHON[bool](%FUNCTION_NAME(%1, (uchar*)%2, (uchar*)%3, (uchar*)%4)); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PySide/QtCore/typesystem_core.xml.in b/PySide/QtCore/typesystem_core.xml.in new file mode 100644 index 0000000..9de2082 --- /dev/null +++ b/PySide/QtCore/typesystem_core.xml.in @@ -0,0 +1,24 @@ + + + + + + diff --git a/PySide/QtCore/typesystem_core_common.xml b/PySide/QtCore/typesystem_core_common.xml new file mode 100644 index 0000000..2e83131 --- /dev/null +++ b/PySide/QtCore/typesystem_core_common.xml @@ -0,0 +1,4097 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // qFatal doesn't have a stream version, so we do a + // qWarning call followed by a qFatal() call using a + // literal. + qWarning() << %1; + qFatal("[A qFatal() call was made from Python code]"); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + return PyBool_FromLong((bool)%in); + + + + %out = %OUTTYPE(%in == Py_True); + + + + + + + + + bool py2kStrCheck(PyObject* obj) + { + #ifdef IS_PY3K + return false; + #else + return PyString_Check(obj); + #endif + } + + + + + + + const int N = %in.length(); + wchar_t* str = new wchar_t[N]; + %in.toWCharArray(str); + PyObject* %out = PyUnicode_FromWideChar(str, N); + delete[] str; + return %out; + + + + Py_UNICODE* unicode = PyUnicode_AS_UNICODE(%in); + #if defined(Py_UNICODE_WIDE) + // cast as Py_UNICODE can be a different type + %out = QString::fromUcs4((const uint*)unicode); + #else + %out = QString::fromUtf16(unicode, PyUnicode_GET_SIZE(%in)); + #endif + + + #ifndef IS_PY3K + const char* str = %CONVERTTOCPP[const char*](%in); + %out = %OUTTYPE(str); + #endif + + + %out = %OUTTYPE(); + + + + + + + + + const int N = %in.toString().length(); + wchar_t* str = new wchar_t[N]; + %in.toString().toWCharArray(str); + PyObject* %out = PyUnicode_FromWideChar(str, N); + delete[] str; + return %out; + + + + %out = %OUTTYPE(); + + + + + + + + wchar_t c = (wchar_t)%in.unicode(); + return PyUnicode_FromWideChar(&c, 1); + + + + char c = %CONVERTTOCPP[char](%in); + %out = %OUTTYPE(c); + + + int i = %CONVERTTOCPP[int](%in); + %out = %OUTTYPE(i); + + + %out = %OUTTYPE(); + + + + + + + + + + if (!%in.isValid()) + Py_RETURN_NONE; + + if (qstrcmp(%in.typeName(), "QVariantList") == 0) { + QList<QVariant> var = %in.value<QVariantList>(); + return %CONVERTTOPYTHON[QList<QVariant>](var); + } + + if (qstrcmp(%in.typeName(), "QStringList") == 0) { + QStringList var = %in.value<QStringList>(); + return %CONVERTTOPYTHON[QList<QString>](var); + } + + if (qstrcmp(%in.typeName(), "QVariantMap") == 0) { + QMap<QString, QVariant> var = %in.value<QVariantMap>(); + return %CONVERTTOPYTHON[QMap<QString, QVariant>](var); + } + + Shiboken::Conversions::SpecificConverter converter(cppInRef.typeName()); + if (converter) { + void* ptr = cppInRef.data(); + return converter.toPython(ptr); + } + PyErr_Format(PyExc_RuntimeError, "Can't find converter for '%s'.", %in.typeName()); + return 0; + + + + %out = %OUTTYPE(%in == Py_True); + + + %out = %OUTTYPE(); + + + QString in = %CONVERTTOCPP[QString](%in); + %out = %OUTTYPE(in); + + + QByteArray in = %CONVERTTOCPP[QByteArray](%in); + %out = %OUTTYPE(in); + + + double in = %CONVERTTOCPP[double](%in); + %out = %OUTTYPE(in); + + + int in = %CONVERTTOCPP[int](%in); + %out = %OUTTYPE(in); + + + qlonglong in = %CONVERTTOCPP[qlonglong](%in); + %out = %OUTTYPE(in); + + + int in = %CONVERTTOCPP[int](%in); + %out = %OUTTYPE(in); + + + // a class supported by QVariant? + int typeCode; + const char* typeName = QVariant_resolveMetaType(%in->ob_type, &typeCode); + if (!typeCode || !typeName) + return; + QVariant var(typeCode, (void*)0); + Shiboken::Conversions::SpecificConverter converter(typeName); + converter.toCpp(pyIn, var.data()); + %out = var; + + + QVariant ret = QVariant_convertToVariantMap(%in); + %out = ret.isValid() ? ret : QVariant::fromValue<PySide::PyObjectWrapper>(%in); + + + %out = QVariant_convertToVariantList(%in); + + + // Is a shiboken type not known by Qt + %out = QVariant::fromValue<PySide::PyObjectWrapper>(%in); + + + + + + static const char* QVariant_resolveMetaType(PyTypeObject* type, int* typeId) + { + if (PyObject_TypeCheck(type, &SbkObjectType_Type)) { + SbkObjectType* sbkType = (SbkObjectType*)type; + const char* typeName = Shiboken::ObjectType::getOriginalName(sbkType); + if (!typeName) + return 0; + bool valueType = '*' != typeName[qstrlen(typeName) - 1]; + // Do not convert user type of value + if (valueType &∓ Shiboken::ObjectType::isUserType(type)) + return 0; + int obTypeId = QMetaType::type(typeName); + if (obTypeId) { + *typeId = obTypeId; + return typeName; + } + // Do not resolve types to value type + if (valueType) + return 0; + // find in base types + if (type->tp_base) { + return QVariant_resolveMetaType(type->tp_base, typeId); + } else if (type->tp_bases) { + for(int i = 0; i < PyTuple_GET_SIZE(type->tp_bases); ++i) { + const char* derivedName = QVariant_resolveMetaType((PyTypeObject*)PyTuple_GET_ITEM(type->tp_bases, i), typeId); + if (derivedName) + return derivedName; + } + } + } + *typeId = 0; + return 0; + } + static QVariant QVariant_convertToValueList(PyObject* list) + { + if (PySequence_Size(list) < 1) + return QVariant(); + Shiboken::AutoDecRef element(PySequence_GetItem(list, 0)); + int typeId; + const char* typeName = QVariant_resolveMetaType(element.cast<PyTypeObject*>(), &typeId); + if (typeName) { + QByteArray listTypeName("QList<"); + listTypeName += typeName; + listTypeName += '>'; + typeId = QMetaType::type(listTypeName); + if (typeId > 0) { + Shiboken::Conversions::SpecificConverter converter(listTypeName); + if (converter) { + QVariant var(typeId, (void*)0); + converter.toCpp(list, &var); + return var; + } + qWarning() << "Type converter for :" << listTypeName << "not registered."; + } + } + return QVariant(); + } + static bool QVariant_isStringList(PyObject *list) + { + bool allString = true; + Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); + Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); + for(int i = 0; i < size; ++i) { + PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); + if (!%CHECKTYPE[QString](item)) { + allString = false; + break; + } + } + return allString; + } + static QVariant QVariant_convertToVariantMap(PyObject* map) + { + Py_ssize_t pos = 0; + Shiboken::AutoDecRef keys(PyDict_Keys(map)); + if (!QVariant_isStringList(keys)) + return QVariant(); + PyObject* key; + PyObject* value; + QMap<QString,QVariant> ret; + while (PyDict_Next(map, &pos, &key, &value)) { + QString cppKey = %CONVERTTOCPP[QString](key); + QVariant cppValue = %CONVERTTOCPP[QVariant](value); + ret.insert(cppKey, cppValue); + } + return QVariant(ret); + } + static QVariant QVariant_convertToVariantList(PyObject* list) + { + if (QVariant_isStringList(list)) { + QList<QString > lst = %CONVERTTOCPP[QList<QString>](list); + return QVariant(QStringList(lst)); + } + QVariant valueList = QVariant_convertToValueList(list); + if (valueList.isValid()) + return valueList; + QList<QVariant> lst; + Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); + Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); + for (int i = 0; i < size; ++i) { + PyObject* pyItem = PySequence_Fast_GET_ITEM(fast.object(), i); + QVariant item = %CONVERTTOCPP[QVariant](pyItem); + lst.append(item); + } + return QVariant(lst); + } + + + + + + const char* typeName = QVariant::typeToName(%in); + PyObject* %out; + PyTypeObject* pyType = 0; + if (typeName) + pyType = Shiboken::Conversions::getPythonTypeObject(typeName); + %out = pyType ? ((PyObject*)pyType) : Py_None; + Py_INCREF(%out); + return %out; + + + + %out = QVariant::Invalid; + + + const char* typeName; + if (Shiboken::String::checkType((PyTypeObject*)%in)) + typeName = "QString"; + else if (%in == (PyObject*)&PyFloat_Type) + typeName = "double"; // float is a UserType in QVariant. + else if (%in == (PyObject*)&PyLong_Type) + typeName = "int"; // long is a UserType in QVariant. + else if (%in->ob_type == &SbkObjectType_Type) + typeName = Shiboken::ObjectType::getOriginalName((SbkObjectType*)%in); + else + typeName = ((PyTypeObject*)%in)->tp_name; + %out = QVariant::nameToType(typeName); + + + %out = QVariant::nameToType(Shiboken::String::toCString(%in)); + + + %out = QVariant::nameToType("QVariantMap"); + + + const char* typeName; + if (QVariantType_isStringList(%in)) + typeName = "QStringList"; + else + typeName = "QVariantList"; + %out = QVariant::nameToType(typeName); + + + + + + + + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QTCORE_QMAP_QSTRING_QVARIANT_IDX], "QVariantMap"); + + + + static bool QVariantType_isStringList(PyObject* list) + { + bool allString = true; + Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); + Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); + for(int i=0; i < size; i++) { + PyObject* item = PySequence_Fast_GET_ITEM(fast.object(), i); + if (!%CHECKTYPE[QString](item)) { + allString = false; + break; + } + } + return allString; + } + static bool QVariantType_checkAllStringKeys(PyObject* dict) + { + Shiboken::AutoDecRef keys(PyDict_Keys(dict)); + return QVariantType_isStringList(keys); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PyObject* %out = PyTuple_New(2); + PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first)); + PyTuple_SET_ITEM(%out, 1, %CONVERTTOPYTHON[%INTYPE_1](%in.second)); + return %out; + + + + %out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0)); + %out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1)); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + double _abs = qAbs(%1); + %PYARG_0 = %CONVERTTOPYTHON[double](_abs); + + + + + namespace PySide { + static QStack<PyObject*> globalPostRoutineFunctions; + void globalPostRoutineCallback() + { + foreach(PyObject* callback, globalPostRoutineFunctions) { + Shiboken::AutoDecRef result(PyObject_CallObject(callback, NULL)); + Py_DECREF(callback); + } + globalPostRoutineFunctions.clear(); + } + void addPostRoutine(PyObject* callback) + { + if (PyCallable_Check(callback)) { + globalPostRoutineFunctions << callback; + Py_INCREF(callback); + } else { + PyErr_SetString(PyExc_TypeError, "qAddPostRoutine: The argument must be a callable object."); + } + } + } // namespace + + + + PySide::addPostRoutine(%1); + + + + qAddPostRoutine(PySide::globalPostRoutineCallback); + + + + QList<QByteArray> version = QByteArray(qVersion()).split('.'); + PyObject* pyQtVersion = PyTuple_New(3); + for (int i = 0; i < 3; ++i) + PyTuple_SET_ITEM(pyQtVersion, i, PyInt_FromLong(version[i].toInt())); + PyModule_AddObject(module, "__version_info__", pyQtVersion); + PyModule_AddStringConstant(module, "__version__", qVersion()); + + + + { // Avoid name clash + Shiboken::AutoDecRef atexit(Shiboken::Module::import("atexit")); + Shiboken::AutoDecRef regFunc(PyObject_GetAttrString(atexit, "register")); + PyObject* shutDownFunc = PyObject_GetAttrString(module, "__moduleShutdown"); + Shiboken::AutoDecRef args(PyTuple_New(1)); + PyTuple_SET_ITEM(args, 0, shutDownFunc); + Shiboken::AutoDecRef retval(PyObject_Call(regFunc, args, 0)); + Q_ASSERT(!retval.isNull()); + } + + + + + PySide::runCleanupFunctions(); + + + + + + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QSTRING_IDX], "unicode"); + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QSTRING_IDX], "str"); + Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QTCORE_QLIST_QVARIANT_IDX], "QVariantList"); + + PySide::init(module); + Py_AtExit(QtCoreModuleExit); + + + #include <pyside.h> + + + + // Define a global variable to handle qInstallMsgHandler callback + static PyObject* qtmsghandler = 0; + + static void msgHandlerCallback(QtMsgType type, const char* msg) + { + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(2)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QtMsgType](type)); + PyTuple_SET_ITEM(arglist, 1, %CONVERTTOPYTHON[const char*](msg)); + Shiboken::AutoDecRef ret(PyObject_CallObject(qtmsghandler, arglist)); + } + static void QtCoreModuleExit() + { + PySide::SignalManager::instance().clear(); + } + + + + if (%PYARG_1 == Py_None) { + qInstallMsgHandler(0); + %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None; + qtmsghandler = 0; + } else if (!PyCallable_Check(%PYARG_1)) { + PyErr_SetString(PyExc_TypeError, "parameter must be callable"); + } else { + %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None; + Py_INCREF(%PYARG_1); + qtmsghandler = %PYARG_1; + qInstallMsgHandler(msgHandlerCallback); + } + + if (%PYARG_0 == Py_None) + Py_INCREF(%PYARG_0); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + namespace PySide { + template<> inline uint hash(const QLine& v) { + return qHash(qMakePair(qMakePair(v.x1(), v.y1()), qMakePair(v.x2(), v.y2()))); + } + }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + QPointF p; + %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, &p); + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QPointF](p)); + + + + + + + Returns a read only buffer object pointing to the segment of data that this resource represents. If the resource is compressed the data returns is compressed and qUncompress() must be used to access the data. If the resource is a directory None is returned. + + + + + + const void* d = %CPPSELF.%FUNCTION_NAME(); + if (d) { + %PYARG_0 = Shiboken::Buffer::newObject(d, %CPPSELF.size()); + } else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %out = %OUTTYPE(); + + + int day = PyDateTime_GET_DAY(%in); + int month = PyDateTime_GET_MONTH(%in); + int year = PyDateTime_GET_YEAR(%in); + %out = %OUTTYPE(year, month, day); + + + + + + + + + + + + + + + + + + + + + + + + + + + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyDate_FromDate(%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()); + + + + + + + + + + + + + + + + + int year, month, day; + %BEGIN_ALLOW_THREADS + %CPPSELF.%FUNCTION_NAME(&year, &month, &day); + %END_ALLOW_THREADS + %PYARG_0 = PyTuple_New(3); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](year)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[int](month)); + PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[int](day)); + + + + + + + + + + + int yearNumber; + %BEGIN_ALLOW_THREADS + int week = %CPPSELF.%FUNCTION_NAME(&yearNumber); + %END_ALLOW_THREADS + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](week)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[int](yearNumber)); + + + + + + + + + + + + + + + %out = %OUTTYPE(); + + + int day = PyDateTime_GET_DAY(%in); + int month = PyDateTime_GET_MONTH(%in); + int year = PyDateTime_GET_YEAR(%in); + int hour = PyDateTime_DATE_GET_HOUR(%in); + int min = PyDateTime_DATE_GET_MINUTE(%in); + int sec = PyDateTime_DATE_GET_SECOND(%in); + int usec = PyDateTime_DATE_GET_MICROSECOND(%in); + %out = %OUTTYPE(QDate(year, month, day), QTime(hour, min, sec, usec/1000)); + + + + + + + + + + + + + QDate date(%1, %2, %3); + QTime time(%4, %5, %6, %7); + %0 = new %TYPE(date, time, Qt::TimeSpec(%8)); + + + + + QDate date(%1, %2, %3); + QTime time(%4, %5, %6); + %0 = new %TYPE(date, time); + + + + + + + + + + + + + + + + + + + + + QDate date = %CPPSELF.date(); + QTime time = %CPPSELF.time(); + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec()*1000); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + namespace PySide { + template<> inline uint hash(const QPoint& v) { + return qHash(qMakePair(v.x(), v.y())); + } + }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + namespace PySide { + template<> inline uint hash(const QRect& v) { + return qHash(qMakePair(qMakePair(v.x(), v.y()), qMakePair(v.width(), v.height()))); + } + }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + namespace PySide { + template<> inline uint hash(const QSize& v) { + return qHash(qMakePair(v.width(), v.height())); + } + }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %out = %OUTTYPE(); + + + int hour = PyDateTime_TIME_GET_HOUR(%in); + int min = PyDateTime_TIME_GET_MINUTE(%in); + int sec = PyDateTime_TIME_GET_SECOND(%in); + int usec = PyDateTime_TIME_GET_MICROSECOND(%in); + %out = %OUTTYPE(hour, min, sec, usec/1000); + + + + + + + + + + + + + + + + + + + + + + + + + + + if (!PyDateTimeAPI) PySideDateTime_IMPORT; + %PYARG_0 = PyTime_FromTime(%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()*1000); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + return %CPPSELF.size(); + + + + + if (_i < 0 || _i >= %CPPSELF.size()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return 0; + } + bool ret = %CPPSELF.at(_i); + return %CONVERTTOPYTHON[bool](ret); + + + + + PyObject* args = Py_BuildValue("(iiO)", _i, 1, _value); + PyObject* result = Sbk_QBitArrayFunc_setBit(self, args); + Py_DECREF(args); + Py_XDECREF(result); + return !result ? -1 : 0; + + + + + + + + + + + + + + + + + + + + + + %CPPSELF.unlock(); + + + + + + + + + + + + + + %CPPSELF.unlock(); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(%1, %2, %PYARG_3); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + Creates a model index for the given row and column with the internal pointer ptr. + When using a QSortFilterProxyModel, its indexes have their own internal pointer. It is not advisable to access this internal pointer outside of the model. Use the data() function instead. + This function provides a consistent interface that model subclasses must use to create model indexes. + + .. warning:: Because of some Qt/Python itegration rules, the ptr argument do not get the reference incremented during the QModelIndex life time. So it is necessary to keep the object used on ptr argument alive during the whole process. Do not destroy the object if you are not sure about that. + + + + + + + + + + + + + + + + + + + + + + + + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // %FUNCTION_NAME() - disable generation of function call. + %RETURN_TYPE %0 = qobjectConnect(%1, %2, %CPPSELF, %3, %4); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + // %FUNCTION_NAME() - disable generation of function call. + %RETURN_TYPE %0 = qobjectConnect(%1, %2, %3, %4, %5); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + + + // %FUNCTION_NAME() - disable generation of function call. + %RETURN_TYPE %0 = qobjectConnectCallback(%1, %2, %PYARG_3, %4); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + + + // %FUNCTION_NAME() - disable generation of function call. + %RETURN_TYPE %0 = qobjectConnectCallback(%CPPSELF, %1, %PYARG_2, %3); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + + // %FUNCTION_NAME() - disable generation of function call. + %RETURN_TYPE %0 = qobjectConnect(%CPPSELF, %1, %2, %3, %4); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + %RETURN_TYPE %0 = PySide::SignalManager::instance().emitSignal(%CPPSELF, %1, %PYARG_2); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + // %FUNCTION_NAME() - disable generation of function call. + %RETURN_TYPE %0 = qobjectDisconnectCallback(%CPPSELF, %1, %2); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + // %FUNCTION_NAME() - disable generation of function call. + %RETURN_TYPE %0 = qobjectDisconnectCallback(%1, %2, %3); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + QObject* child = _findChildHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1); + %PYARG_0 = %CONVERTTOPYTHON[QObject*](child); + + + + + + + + + + + %PYARG_0 = PyList_New(0); + _findChildrenHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1, %PYARG_0); + + + + + + + + + + + %PYARG_0 = PyList_New(0); + _findChildrenHelper(%CPPSELF, %2, (PyTypeObject*)%PYARG_1, %PYARG_0); + + + + + + + + + + + + + + + + QString result; + if (QCoreApplication::instance()) { + PyObject *klass = PyObject_GetAttrString(%PYSELF, "__class__"); + PyObject *cname = PyObject_GetAttrString(klass, "__name__"); + result = QString(QCoreApplication::instance()->translate(Shiboken::String::toCString(cname), %1, %2, QCoreApplication::CodecForTr, %3)); + + Py_DECREF(klass); + Py_DECREF(cname); + } else { + result = QString(QString::fromLatin1(%1)); + } + %PYARG_0 = %CONVERTTOPYTHON[QString](result); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // Avoid return +1 because SignalManager connect to "destroyed()" signal to control object timelife + int ret = %CPPSELF.%FUNCTION_NAME(%1); + if (ret > 0 && ((strcmp(%1, SIGNAL(destroyed())) == 0) || (strcmp(%1, SIGNAL(destroyed(QObject*))) == 0))) + ret -= PySide::SignalManager::instance().countConnectionsWith(%CPPSELF); + + %PYARG_0 = %CONVERTTOPYTHON[int](ret); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <para>URLs can be represented in two forms: encoded or unencoded. The unencoded representation is suitable for showing to users, but the encoded representation is typically what you would send to a web server. For example, the unencoded URL "http://bühler.example.com" would be sent to the server as "http://xn--bhler-kva.example.com/List%20of%20applicants.xml".</para> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Replaces every occurrence of the regular expression in *sourceString* with *after*. + Returns a new Python string with the modified contents. For example: + + :: + + s = "Banana" + re = QRegExp("a[mn]") + s = re.replace(s, "ox") + # s == "Boxoxa" + + + For regular expressions containing capturing parentheses, occurrences of \1, \2, ..., in *after* + are replaced with rx.cap(1), cap(2), ... + + :: + + t = "A <i>bon mot</i>." + re = QRegExp("<i>([^<]*)</i>") + t = re.replace(t, "\\emph{\\1}") + # t == "A \\emph{bon mot}." + + + + %1.replace(*%CPPSELF, %2); + %PYARG_0 = %CONVERTTOPYTHON[QString](%1); + + + + + + + + + + + + + + + + + + + + + + %out = %OUTTYPE(); + + + %out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); + + + #ifdef IS_PY3K + %out = %OUTTYPE(PyBytes_AS_STRING(%in), PyBytes_GET_SIZE(%in)); + #endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Shiboken::AutoDecRef str(PyUnicode_AsASCIIString(%PYARG_1)); + if (!str.isNull()) { + QByteArray b(PyBytes_AS_STRING(str.object()), PyBytes_GET_SIZE (str.object())); + b.prepend(*%CPPSELF); + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](b); + } + + + + + Shiboken::AutoDecRef str(PyUnicode_AsASCIIString(%PYARG_1)); + if (!str.isNull()) { + QByteArray b(PyBytes_AS_STRING(str.object()), PyBytes_GET_SIZE(str.object())); + b.append(*%CPPSELF); + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](b); + } + + + + + QByteArray ba = QByteArray(PyBytes_AS_STRING(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)) + *%CPPSELF; + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); + + + + + + + QByteArray b(((PyObject*)%PYSELF)->ob_type->tp_name); + PyObject* aux = Shiboken::String::fromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); + if (PyUnicode_CheckExact(aux)) { + PyObject* tmp = PyUnicode_AsASCIIString(aux); + Py_DECREF(aux); + aux = tmp; + } + b += "('"; + b += QByteArray(PyBytes_AS_STRING(aux), PyBytes_GET_SIZE(aux)); + b += "')"; + %PYARG_0 = Shiboken::String::fromStringAndSize(b.constData(), b.size()); + + + + + + + + + + + + + + + if (PyBytes_Check(%PYARG_1)) { + %0 = new QByteArray(PyBytes_AsString(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)); + } if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + %0 = new QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + } else if (Shiboken::String::check(%PYARG_1)) { + %0 = new QByteArray(Shiboken::String::toCString(%PYARG_1), Shiboken::String::len(%PYARG_1)); + } + + + + + + #if PY_VERSION_HEX < 0x03000000 + Shiboken::SbkType<QByteArray>()->tp_as_buffer = &SbkQByteArrayBufferProc; + Shiboken::SbkType<QByteArray>()->tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER; + #endif + + + + + %PYARG_0 = PyBytes_FromStringAndSize(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.size()); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(PyBytes_AsString(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + + + + + + + + + + + + + + %PYARG_0 = Shiboken::String::fromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); + + + + + return %CPPSELF.count(); + + + + + if (_i < 0 || _i >= %CPPSELF.size()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return 0; + } else { + char res[2]; + res[0] = %CPPSELF.at(_i); + res[1] = 0; + return PyBytes_FromStringAndSize(res, 1); + } + + + + + %CPPSELF.remove(_i, 1); + PyObject* args = Py_BuildValue("(nO)", _i, _value); + PyObject* result = Sbk_QByteArrayFunc_insert(self, args); + Py_DECREF(args); + Py_XDECREF(result); + return !result ? -1 : 0; + + + + + Py_ssize_t max = %CPPSELF.count(); + _i1 = qBound(Py_ssize_t(0), _i1, max); + _i2 = qBound(Py_ssize_t(0), _i2, max); + QByteArray ba; + if (_i1 < _i2) + ba = %CPPSELF.mid(_i1, _i2 - _i1); + return %CONVERTTOPYTHON[QByteArray](ba); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(ptr); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2, Shiboken::Buffer::ReadWrite); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); + + + + + + + + %RETURN_TYPE %out; + if (PyBytes_Check(%PYARG_0)) { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } else if (Shiboken::String::check(%PYARG_0)) { + %out = Shiboken::String::len((PyObject*)%PYARG_0); + memcpy(%1, Shiboken::String::toCString((PyObject*)%PYARG_0), %out); + } + + + + + + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); + + + + + + + + %RETURN_TYPE %out; + if (!PyBytes_Check(%PYARG_0)) { + %out = -1; + } else { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } + + + + + + + + + + + + %CPPSELF.%FUNCTION_NAME(Shiboken::String::toCString(%PYARG_1), Shiboken::String::len(%PYARG_1)); + + + + + + + + + + + + + + + + + + + + + + %CPPSELF.unlock(); + + + + + + + + + + + + + + + + + + + + + + + Shiboken::AutoDecRef fileNo(PyObject_GetAttrString(%PYARG_1, "fileno")); + if (!fileNo.isNull()) { + Shiboken::AutoDecRef fileNoValue(PyObject_CallObject(fileNo, 0)); + if (%CHECKTYPE[int](fileNoValue)) { + int cppFileNoValue = %CONVERTTOCPP[int](fileNoValue); + %0 = new %TYPE(cppFileNoValue, %2, %3); + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Py_ssize_t size; + uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1, &size); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(const_cast<const uchar*>(ptr), size); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + + + + + + + + + + + + + // %FUNCTION_NAME() - disable generation of c++ function call + (void) %2; // remove warning about unused variable + Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); + PyObject* pyTimer = Shiboken::SbkType<QTimer>()->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); + Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); + + QTimer* timer = %CONVERTTOCPP[QTimer*](pyTimer); + Shiboken::AutoDecRef result( + PyObject_CallMethod(pyTimer, + const_cast<char*>("connect"), + const_cast<char*>("OsOs"), + pyTimer, + SIGNAL(timeout()), + %PYARG_2, + %3) + ); + Shiboken::Object::releaseOwnership((SbkObject*)pyTimer); + Py_XDECREF(pyTimer); + timer->setSingleShot(true); + timer->connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); + timer->start(%1); + + + + + // %FUNCTION_NAME() - disable generation of c++ function call + Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); + PyObject *pyTimer = Shiboken::SbkType<QTimer>()->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); + Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); + QTimer* timer = %CONVERTTOCPP[QTimer*](pyTimer); + timer->setSingleShot(true); + + if (PyObject_TypeCheck(%2, &PySideSignalInstanceType)) { + PySideSignalInstance* signalInstance = reinterpret_cast<PySideSignalInstance*>(%2); + Shiboken::AutoDecRef signalSignature(Shiboken::String::fromFormat("2%s", PySide::Signal::getSignature(signalInstance))); + Shiboken::AutoDecRef result( + PyObject_CallMethod(pyTimer, + const_cast<char*>("connect"), + const_cast<char*>("OsOO"), + pyTimer, + SIGNAL(timeout()), + PySide::Signal::getObject(signalInstance), + signalSignature.object()) + ); + } else { + Shiboken::AutoDecRef result( + PyObject_CallMethod(pyTimer, + const_cast<char*>("connect"), + const_cast<char*>("OsO"), + pyTimer, + SIGNAL(timeout()), + %PYARG_2) + ); + } + + timer->connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater()), Qt::DirectConnection); + Shiboken::Object::releaseOwnership((SbkObject*)pyTimer); + Py_XDECREF(pyTimer); + timer->start(%1); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + uchar* ptr = (uchar*)Shiboken::Buffer::getPointer(%PYARG_1); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(ptr); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2, Shiboken::Buffer::ReadWrite); + + + + + + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = PyBytes_FromStringAndSize(ba.constData(), ba.size()); + + + + + + + + %RETURN_TYPE %out; + if (!Shiboken::String::check(%PYARG_0)) { + %out = -1; + } else { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } + + + + + + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = PyBytes_FromStringAndSize(ba.constData(), ba.size()); + + + + + + + + %RETURN_TYPE %out; + if (!Shiboken::String::check(%PYARG_0)) { + %out = -1; + } else { + %out = PyBytes_GET_SIZE((PyObject*)%PYARG_0); + memcpy(%1, PyBytes_AS_STRING((PyObject*)%PYARG_0), %out); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + qint64 pid; + %RETURN_TYPE retval = %TYPE::%FUNCTION_NAME(%1, %2, %3, &pid); + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[qint64](pid)); + + + + + + + long result; + #ifdef WIN32 + _PROCESS_INFORMATION* procInfo = %CPPSELF.%FUNCTION_NAME(); + result = procInfo ? procInfo->dwProcessId : 0; + #else + result = %CPPSELF.%FUNCTION_NAME(); + #endif + %PYARG_0 = %CONVERTTOPYTHON[long](result); + + + + + + + + + + + + + + + + + + +.. class:: QCoreApplication(args) + + Constructs a Qt kernel application. Kernel applications are applications + without a graphical user interface. These type of applications are used + at the console or as server processes. + + The *args* argument is processed by the application, and made available + in a more convenient form by the :meth:`~QCoreApplication.arguments()` + method. + + + + QCoreApplication_constructor(%PYSELF, args, &%0); + + + + + + + + + + + + QCoreApplication* app = QCoreApplication::instance(); + PyObject* pyApp = Py_None; + if (app) { + pyApp = reinterpret_cast<PyObject*>(Shiboken::BindingManager::instance().retrieveWrapper(app)); + if (!pyApp) + pyApp = %CONVERTTOPYTHON[QCoreApplication*](app); // this will keep app live after python exit (extra ref) + } + %PYARG_0 = pyApp; + Py_XINCREF(%PYARG_0); + + + + + + + + + + + + + + + + + + + + + + + + + + + + long *%out = new long; + %out = 0; + + + + + + %RETURN_TYPE %out = false; + if (PySequence_Check(%PYARG_0) && (PySequence_Size(%PYARG_0) == 2)) { + Shiboken::AutoDecRef pyResult(PySequence_GetItem(%PYARG_0, 0)); + %out = %CONVERTTOCPP[bool](pyResult); + } + + + + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](%0)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[long](*result_out)); + delete result_out; + + + + + + + + + + + + + + + + + + + + + + .. warning:: QSettings.value can return different types (QVariant types) depending on the platform it's running on, so the safest way to use it is always casting the result to the desired type, e.g.: int(settings.value("myKey")) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + QByteArray data; + data.resize(%2); + int result = %CPPSELF.%FUNCTION_NAME(data.data(), data.size()); + if (result == -1) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; + } else { + %PYARG_0 = PyBytes_FromStringAndSize(data.data(), result); + } + + + + + + + + int r = %CPPSELF.%FUNCTION_NAME(%1, Shiboken::String::len(%PYARG_1)); + %PYARG_0 = %CONVERTTOPYTHON[int](r); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + QString& res = *%0; + %PYARG_0 = %CONVERTTOPYTHON[QString](res); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Shiboken::Object::releaseOwnership(%PYARG_0); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + for(int counter = 0; counter < %CPPSELF.animationCount(); ++counter ) { + QAbstractAnimation* animation = %CPPSELF.animationAt(counter); + PyObject* obj = %CONVERTTOPYTHON[QAbstractAnimation*](animation); + Shiboken::Object::setParent(NULL, obj); + Py_DECREF(obj); + } + %CPPSELF.clear(); + + + + + + + + + + + + + + PySideEasingCurveFunctor::init(); + + + + + QEasingCurve::EasingFunction func = PySideEasingCurveFunctor::createCustomFuntion(%PYSELF, %PYARG_1); + if (func) + %CPPSELF.%FUNCTION_NAME(func); + + + + + //%FUNCTION_NAME() + %PYARG_0 = PySideEasingCurveFunctor::callable(%PYSELF); + + + + + + + + + + + + + + + + + + + + + + + + + <code>machine = QStateMachine() + +s1 = new QState() +s11 = new QState(s1) +s12 = new QState(s1) + +s1h = QHistoryState(s1) +s1h.setDefaultState(s11) + +machine.addState(s1) + +s2 = QState() +machine.addState(s2) + +button = QPushButton() +# Clicking the button will cause the state machine to enter the child state +# that s1 was in the last time s1 was exited, or the history state's default +# state if s1 has never been entered. +s1.addTransition(button.clicked, s1h)</code> + + + + + + + + + + + + + + + + + + + + + + if (PyObject_TypeCheck(%1, &PySideSignalInstanceType)) { + PyObject* dataSource = PySide::Signal::getObject((PySideSignalInstance*) %PYARG_1); + Shiboken::AutoDecRef obType(PyObject_Type(dataSource)); + QObject* sender = %CONVERTTOCPP[QObject*](dataSource); + if (sender) { + const char* dataSignature = PySide::Signal::getSignature((PySideSignalInstance*) %PYARG_1); + QByteArray signature(dataSignature); // Append SIGNAL flag (2) + %0 = new QSignalTransitionWrapper(sender, "2" + signature, %2); + } + } + + + + + + + + + + + + + + + + + + QString signalName(%2); + if (PySide::SignalManager::registerMetaMethod(%1, signalName.mid(1).toAscii().data(), QMetaMethod::Signal)) { + QSignalTransition* %0 = %CPPSELF->addTransition(%1, %2, %3); + %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%0); + } else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; + } + + + + + + + + + + + + + + + // Obviously the label used by the following goto is a very awkward solution, + // since it refers to a name very tied to the generator implementation. + // Check bug #362 for more information on this + // http://bugs.openbossa.org/show_bug.cgi?id=362 + if (!PyObject_TypeCheck(%1, &PySideSignalInstanceType)) + goto Sbk_%TYPEFunc_%FUNCTION_NAME_TypeError; + PySideSignalInstance* signalInstance = reinterpret_cast<PySideSignalInstance*>(%1); + QObject* sender = %CONVERTTOCPP[QObject*](PySide::Signal::getObject(signalInstance)); + QSignalTransition* %0 = %CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance), %2); + %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%0); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %PYARG_0 = PySet_New(0); + foreach(QAbstractState* abs_state, %CPPSELF.configuration()) { + Shiboken::AutoDecRef obj(%CONVERTTOPYTHON[QAbstractState*](abs_state)); + Shiboken::Object::setParent(self, obj); + PySet_Add(%PYARG_0, obj); + } + + + + + + + + %PYARG_0 = PyList_New(0); + foreach(QAbstractAnimation* abs_anim, %CPPSELF.defaultAnimations()) { + Shiboken::AutoDecRef obj(%CONVERTTOPYTHON[QAbstractAnimation*](abs_anim)); + Shiboken::Object::setParent(self, obj); + PyList_Append(%PYARG_0, obj); + } + + + + + + + + + + + %PYARG_0 = Shiboken::String::fromFormat("2%s", QMetaObject::normalizedSignature(%1).constData()); + + + + + + %PYARG_0 = Shiboken::String::fromFormat("1%s", QMetaObject::normalizedSignature(%1).constData()); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + extern bool + qRegisterResourceData(int, + const unsigned char *, + const unsigned char *, + const unsigned char *); + + extern bool + qUnregisterResourceData(int, + const unsigned char *, + const unsigned char *, + const unsigned char *); + + + + %RETURN_TYPE %0 = %FUNCTION_NAME(%1, (uchar*)PyBytes_AS_STRING(%PYARG_2), + (uchar*)PyBytes_AS_STRING(%PYARG_3), + (uchar*)PyBytes_AS_STRING(%PYARG_4)); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + %RETURN_TYPE %0 = %FUNCTION_NAME(%1, (uchar*)PyBytes_AS_STRING(%PYARG_2), + (uchar*)PyBytes_AS_STRING(%PYARG_3), + (uchar*)PyBytes_AS_STRING(%PYARG_4)); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PySide/QtCore/typesystem_core_mac.xml b/PySide/QtCore/typesystem_core_mac.xml new file mode 100644 index 0000000..0f9c511 --- /dev/null +++ b/PySide/QtCore/typesystem_core_mac.xml @@ -0,0 +1,23 @@ + + + + + diff --git a/PySide/QtCore/typesystem_core_maemo.xml b/PySide/QtCore/typesystem_core_maemo.xml new file mode 100644 index 0000000..eba223c --- /dev/null +++ b/PySide/QtCore/typesystem_core_maemo.xml @@ -0,0 +1,26 @@ + + + + + + + + diff --git a/PySide/QtCore/typesystem_core_win.xml b/PySide/QtCore/typesystem_core_win.xml new file mode 100644 index 0000000..26c7a82 --- /dev/null +++ b/PySide/QtCore/typesystem_core_win.xml @@ -0,0 +1,57 @@ + + + + + + + + #ifdef IS_PY3K + return PyCapsule_New(%in, 0, 0); + #else + return PyCObject_FromVoidPtr(%in, 0); + #endif + + + + %out = 0; + + + #ifdef IS_PY3K + %out = (%OUTTYPE)PyCapsule_GetPointer(%in, 0); + #else + %out = (%OUTTYPE)PyCObject_AsVoidPtr(%in); + #endif + + + + + + + + + + + + + + + + diff --git a/PySide/QtCore/typesystem_core_x11.xml b/PySide/QtCore/typesystem_core_x11.xml new file mode 100644 index 0000000..eba223c --- /dev/null +++ b/PySide/QtCore/typesystem_core_x11.xml @@ -0,0 +1,26 @@ + + + + + + + + diff --git a/PySide/QtDeclarative/CMakeLists.txt b/PySide/QtDeclarative/CMakeLists.txt index 1966cab..c9ea931 100644 --- a/PySide/QtDeclarative/CMakeLists.txt +++ b/PySide/QtDeclarative/CMakeLists.txt @@ -1,5 +1,7 @@ project(QtDeclarative) +set(QtDeclarative_registerType "${CMAKE_CURRENT_SOURCE_DIR}/pysideqmlregistertype.cpp") + set(QtDeclarative_SRC ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qdeclarativecomponent_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qdeclarativecontext_wrapper.cpp @@ -21,14 +23,14 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qdeclarativeview_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative/qtdeclarative_module_wrapper.cpp ) -set(QtDeclarative_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}${PATH_SEP}${QtNetwork_SOURCE_DIR}${PATH_SEP}${QtDeclarative_SOURCE_DIR}${PATH_SEP}${QtGui_BINARY_DIR}") +set(QtDeclarative_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtCore_BINARY_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}${PATH_SEP}${QtNetwork_SOURCE_DIR}${PATH_SEP}${QtDeclarative_SOURCE_DIR}${PATH_SEP}${QtGui_BINARY_DIR}") set(QtDeclarative_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTNETWORK_INCLUDE_DIR} ${QT_QTDECLARATIVE_INCLUDE_DIR} - ${PYTHON_INCLUDE_PATH} + ${SHIBOKEN_PYTHON_INCLUDE_DIR} ${SHIBOKEN_INCLUDE_DIR} ${libpyside_SOURCE_DIR} ${QtGui_BINARY_DIR}/PySide/QtGui/ @@ -37,7 +39,7 @@ set(QtDeclarative_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtDeclarative) set(QtDeclarative_libraries pyside - ${PYSIDE_PYTHON_LIBRARIES} + ${SHIBOKEN_PYTHON_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTNETWORK_LIBRARY} @@ -56,5 +58,5 @@ create_pyside_module(QtDeclarative QtDeclarative_deps QtDeclarative_typesystem_path QtDeclarative_SRC - "") + QtDeclarative_registerType) diff --git a/PySide/QtDeclarative/pysideqmlregistertype.cpp b/PySide/QtDeclarative/pysideqmlregistertype.cpp new file mode 100644 index 0000000..4efc4bf --- /dev/null +++ b/PySide/QtDeclarative/pysideqmlregistertype.cpp @@ -0,0 +1,366 @@ +/* + * This file is part of the Shiboken Python Bindings Generator project. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "pysideqmlregistertype.h" +// Qt +#include +#include +#include +// shiboken +#include +#include +#include +// pyside +#include +#include +#include + +// auto generated headers +#include "qdeclarativeitem_wrapper.h" +#include "pyside_qtcore_python.h" +#include "pyside_qtdeclarative_python.h" + +#ifndef PYSIDE_MAX_QML_TYPES +// Maximum number of different types the user cna export to QML using qmlRegisterType. +#define PYSIDE_MAX_QML_TYPES 50 +#endif + +// Forward declarations +static void propListMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::Call call, void** args); + + +// All registered python types +static PyObject* pyTypes[PYSIDE_MAX_QML_TYPES]; +static void (*createFuncs[PYSIDE_MAX_QML_TYPES])(void*); + +// Mutex used to avoid race condition on PySide::nextQObjectMemoryAddr +static QMutex nextQmlElementMutex; + +template +struct ElementFactoryBase +{ + static void createInto(void* memory) + { + QMutexLocker locker(&nextQmlElementMutex); + PySide::setNextQObjectMemoryAddr(memory); + Shiboken::GilState state; + PyObject* obj = PyObject_CallObject(pyTypes[N], 0); + if (!obj || PyErr_Occurred()) + PyErr_Print(); + PySide::setNextQObjectMemoryAddr(0); + } +}; + +template +struct ElementFactory : ElementFactoryBase +{ + static void init() + { + createFuncs[N] = &ElementFactoryBase::createInto; + ElementFactory::init(); + } +}; + +template<> +struct ElementFactory<0> : ElementFactoryBase<0> +{ + static void init() + { + createFuncs[0] = &ElementFactoryBase<0>::createInto; + } +}; + +int PySide::qmlRegisterType(PyObject* pyObj, const char* uri, int versionMajor, int versionMinor, const char* qmlName) +{ + using namespace Shiboken; + + static PyTypeObject* qobjectType = Shiboken::Conversions::getPythonTypeObject("QObject*"); + static PyTypeObject* qdeclarativeType = Shiboken::Conversions::getPythonTypeObject("QDeclarativeItem*"); + assert(qobjectType); + static int nextType = 0; + + if (nextType >= PYSIDE_MAX_QML_TYPES) { + PyErr_Format(PyExc_TypeError, "QML doesn't really like language bindings, so you can only export %d types to QML.", PYSIDE_MAX_QML_TYPES); + return -1; + } + + if (!PySequence_Contains(((PyTypeObject*)pyObj)->tp_mro, (PyObject*)qobjectType)) { + PyErr_Format(PyExc_TypeError, "A type inherited from %s expected, got %s.", qobjectType->tp_name, ((PyTypeObject*)pyObj)->tp_name); + return -1; + } + + bool isDeclarativeType = PySequence_Contains(((PyTypeObject*)pyObj)->tp_mro, (PyObject*)qdeclarativeType); + + QMetaObject* metaObject = reinterpret_cast(ObjectType::getTypeUserData(reinterpret_cast(pyObj))); + Q_ASSERT(metaObject); + + // Inc ref the type object, don't worry about dec ref them because there's no way to unregister a QML type + Py_INCREF(pyObj); + + // All ready... now the ugly code begins... :-) + pyTypes[nextType] = pyObj; + + // Init proxy object static meta object + QDeclarativePrivate::RegisterType type; + type.version = 0; + if (isDeclarativeType) { + type.typeId = qMetaTypeId(); + type.listId = qMetaTypeId >(); + + type.attachedPropertiesFunction = QDeclarativePrivate::attachedPropertiesFunc(); + type.attachedPropertiesMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject(); + + type.parserStatusCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueSourceCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueInterceptorCast = QDeclarativePrivate::StaticCastSelector::cast(); + } else { + type.typeId = qMetaTypeId(); + type.listId = qMetaTypeId >(); + type.attachedPropertiesFunction = QDeclarativePrivate::attachedPropertiesFunc(); + type.attachedPropertiesMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject(); + + type.parserStatusCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueSourceCast = QDeclarativePrivate::StaticCastSelector::cast(); + type.valueInterceptorCast = QDeclarativePrivate::StaticCastSelector::cast(); + } + type.objectSize = PySide::getSizeOfQObject(reinterpret_cast(pyObj)); + type.create = createFuncs[nextType]; + type.uri = uri; + type.versionMajor = versionMajor; + type.versionMinor = versionMinor; + type.elementName = qmlName; + type.metaObject = metaObject; + + type.extensionObjectCreate = 0; + type.extensionMetaObject = 0; + type.customParser = 0; + + int qmlTypeId = QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type); + ++nextType; + return qmlTypeId; +} + +extern "C" +{ + +// This is the user data we store in the property. +struct DeclarativeListProperty +{ + PyTypeObject* type; + PyObject* append; + PyObject* at; + PyObject* clear; + PyObject* count; +}; + +static int propListTpInit(PyObject* self, PyObject* args, PyObject* kwds) +{ + static const char *kwlist[] = {"type", "append", "at", "clear", "count", 0}; + PySideProperty* pySelf = reinterpret_cast(self); + DeclarativeListProperty* data = new DeclarativeListProperty; + memset(data, 0, sizeof(DeclarativeListProperty)); + + if (!PyArg_ParseTupleAndKeywords(args, kwds, + "OO|OOO:QtDeclarative.ListProperty", (char**) kwlist, + &data->type, + &data->append, + &data->at, + &data->clear, + &data->count)) { + return 0; + } + PySide::Property::setMetaCallHandler(pySelf, &propListMetaCall); + PySide::Property::setTypeName(pySelf, "QDeclarativeListProperty"); + PySide::Property::setUserData(pySelf, data); + + return 1; +} + +void propListTpFree(void* self) +{ + PySideProperty* pySelf = reinterpret_cast(self); + delete reinterpret_cast(PySide::Property::userData(pySelf)); + // calls base type constructor + Py_TYPE(pySelf)->tp_base->tp_free(self); +} + +PyTypeObject PropertyListType = { + PyVarObject_HEAD_INIT(0, 0) + "ListProperty", /*tp_name*/ + sizeof(PySideProperty), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + 0, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + 0, /*tp_doc */ + 0, /*tp_traverse */ + 0, /*tp_clear */ + 0, /*tp_richcompare */ + 0, /*tp_weaklistoffset */ + 0, /*tp_iter */ + 0, /*tp_iternext */ + 0, /*tp_methods */ + 0, /*tp_members */ + 0, /*tp_getset */ + &PySidePropertyType, /*tp_base */ + 0, /*tp_dict */ + 0, /*tp_descr_get */ + 0, /*tp_descr_set */ + 0, /*tp_dictoffset */ + propListTpInit, /*tp_init */ + 0, /*tp_alloc */ + 0, /*tp_new */ + propListTpFree, /*tp_free */ + 0, /*tp_is_gc */ + 0, /*tp_bases */ + 0, /*tp_mro */ + 0, /*tp_cache */ + 0, /*tp_subclasses */ + 0, /*tp_weaklist */ + 0, /*tp_del */ +}; + +} // extern "C" + +// Implementation of QDeclarativeListProperty::AppendFunction callback +void propListAppender(QDeclarativeListProperty* propList, QDeclarativeItem* item) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(2)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + PyTuple_SET_ITEM(args, 1, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtDeclarativeTypes[SBK_QDECLARATIVEITEM_IDX], item)); + + DeclarativeListProperty* data = reinterpret_cast(propList->data); + Shiboken::AutoDecRef retVal(PyObject_CallObject(data->append, args)); + + if (PyErr_Occurred()) + PyErr_Print(); +} + +// Implementation of QDeclarativeListProperty::CountFunction callback +int propListCount(QDeclarativeListProperty* propList) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(1)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + + DeclarativeListProperty* data = reinterpret_cast(propList->data); + Shiboken::AutoDecRef retVal(PyObject_CallObject(data->count, args)); + + // Check return type + int cppResult = 0; + PythonToCppFunc pythonToCpp; + if (PyErr_Occurred()) + PyErr_Print(); + else if ((pythonToCpp = Shiboken::Conversions::isPythonToCppConvertible(Shiboken::Conversions::PrimitiveTypeConverter(), retVal))) + pythonToCpp(retVal, &cppResult); + return cppResult; +} + +// Implementation of QDeclarativeListProperty::AtFunction callback +QDeclarativeItem* propListAt(QDeclarativeListProperty* propList, int index) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(2)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + PyTuple_SET_ITEM(args, 1, Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter(), &index)); + + DeclarativeListProperty* data = reinterpret_cast(propList->data); + Shiboken::AutoDecRef retVal(PyObject_CallObject(data->at, args)); + + QDeclarativeItem* result = 0; + if (PyErr_Occurred()) + PyErr_Print(); + else if (PyType_IsSubtype(Py_TYPE(retVal), data->type)) + Shiboken::Conversions::pythonToCppPointer((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QDECLARATIVEITEM_IDX], retVal, &result); + return result; +} + +// Implementation of QDeclarativeListProperty::ClearFunction callback +void propListClear(QDeclarativeListProperty* propList) +{ + Shiboken::GilState state; + + Shiboken::AutoDecRef args(PyTuple_New(1)); + PyTuple_SET_ITEM(args, 0, Shiboken::Conversions::pointerToPython((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], propList->object)); + + DeclarativeListProperty* data = reinterpret_cast(propList->data); + Shiboken::AutoDecRef retVal(PyObject_CallObject(data->clear, args)); + + if (PyErr_Occurred()) + PyErr_Print(); +} + +// qt_metacall specialization for ListProperties +static void propListMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::Call call, void** args) +{ + if (call != QMetaObject::ReadProperty) + return; + + DeclarativeListProperty* data = reinterpret_cast(PySide::Property::userData(pp)); + QObject* qobj; + Shiboken::Conversions::pythonToCppPointer((SbkObjectType*)SbkPySide_QtCoreTypes[SBK_QOBJECT_IDX], self, &qobj); + QDeclarativeListProperty declProp(qobj, data, &propListAppender); + + if (data->count) + declProp.count = &propListCount; + if (data->at) + declProp.at = &propListAt; + if (data->clear) + declProp.clear = &propListClear; + + // Copy the data to the memory location requested by the meta call + void* v = args[0]; + *reinterpret_cast*>(v) = declProp; +} + + +void PySide::initQmlSupport(PyObject* module) +{ + ElementFactory::init(); + + // Export DeclarativeListProperty type + if (PyType_Ready(&PropertyListType) < 0) + return; + + Py_INCREF((PyObject*)&PropertyListType); + PyModule_AddObject(module, PropertyListType.tp_name, (PyObject*)&PropertyListType); + +} + + diff --git a/PySide/QtDeclarative/pysideqmlregistertype.h b/PySide/QtDeclarative/pysideqmlregistertype.h new file mode 100644 index 0000000..aa25200 --- /dev/null +++ b/PySide/QtDeclarative/pysideqmlregistertype.h @@ -0,0 +1,57 @@ +/* + * This file is part of the Shiboken Python Bindings Generator project. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PYSIDEQMLREGISTERTYPE_H +#define PYSIDEQMLREGISTERTYPE_H + +#include + +struct SbkObjectType; + +namespace PySide +{ + +extern void* nextQmlElementMemoryAddr; + +/** + * Init the QML support doign things like registering QtDeclarative.ListProperty and create the necessary stuff for + * qmlRegisterType. + * + * \param module QtDeclarative python module + */ +void initQmlSupport(PyObject* module); + +/** + * PySide implementation of qmlRegisterType function. + * + * \param pyObj Python type to be registered. + * \param uri QML element uri. + * \param versionMajor QML component major version. + * \param versionMinor QML component minor version. + * \param qmlName QML element name + * \return the metatype id of the registered type. + */ +int qmlRegisterType(PyObject* pyObj, const char* uri, int versionMajor, int versionMinor, const char* qmlName); + +} + +#endif diff --git a/PySide/QtDeclarative/typesystem_declarative.xml b/PySide/QtDeclarative/typesystem_declarative.xml index 888ca6f..1bc18ba 100644 --- a/PySide/QtDeclarative/typesystem_declarative.xml +++ b/PySide/QtDeclarative/typesystem_declarative.xml @@ -23,27 +23,111 @@ + + + This function registers the Python type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor. + Returns the QML type id. + + For example, this registers a Python class MySliderItem as a QML type named Slider for version 1.0 of a module called "com.mycompany.qmlcomponents": + + :: + + qmlRegisterType(MySliderItem, "com.mycompany.qmlcomponents", 1, 0, "Slider") + + Once this is registered, the type can be used in QML by importing the specified module name and version number: + + :: + + import com.mycompany.qmlcomponents 1.0 + + Slider { ... } + + Note that it's perfectly reasonable for a library to register types to older versions than the actual version of the library. Indeed, it is normal for the new library to allow QML written to previous versions to continue to work, even if more advanced versions of some of its types are available. + + + + int %0 = PySide::qmlRegisterType(%ARGUMENT_NAMES); + %PYARG_0 = %CONVERTTOPYTHON[int](%0); + + + + + + + + + + + + + PySide::initQmlSupport(module); + + + - + + + + QByteArray key("%FUNCTION_NAME_"); + key.append(%1.toLocal8Bit()); + Shiboken::Object::keepReference(reinterpret_cast<SbkObject*>(%PYSELF), key.constData(), %PYARG_2); + + + + + + + + + + + + + + + + + + QString errorString; + %BEGIN_ALLOW_THREADS + %RETURN_TYPE ok_ = %CPPSELF.%FUNCTION_NAME(%1, %2, &errorString); + %END_ALLOW_THREADS + %PYARG_0 = PyTuple_New(2); + PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](ok_)); + PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](errorString)); + + - + + + + + + + + + + + + + @@ -62,7 +146,20 @@ - + + <code># create our data +ownerData = QDeclarativePropertyMap() +ownerData.insert("name", "John Smith") +ownerData.insert("phone", "555-5555") + +# expose it to the UI layer +view = QDeclarativeView() +ctxt = view.rootContext() +ctxt.setContextProperty("owner", ownerData) + +view.setSource(QUrl.fromLocalFile("main.qml")) +view.show()</code> + diff --git a/PySide/QtGui/CMakeLists.txt b/PySide/QtGui/CMakeLists.txt index 85c61b9..7625634 100644 --- a/PySide/QtGui/CMakeLists.txt +++ b/PySide/QtGui/CMakeLists.txt @@ -5,7 +5,7 @@ if(ENABLE_X11) ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qx11info_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qx11embedcontainer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qx11embedwidget_wrapper.cpp - ) + ) if(Q_WS_MAEMO_5) set(SPECIFIC_OS_FILES @@ -15,9 +15,8 @@ if(ENABLE_X11) endif() endif() - if (${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} LESS 6) - set (QtGui_46_SRC ) + set(QtGui_46_SRC "") else() set(QtGui_46_SRC ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qmatrix2x2_wrapper.cpp @@ -60,6 +59,31 @@ else() ) endif () +if (${QT_VERSION_MAJOR} EQUAL 4 AND ${QT_VERSION_MINOR} LESS 7) + set(QtGui_47_SRC "") +else() + set(QtGui_47_SRC + ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpainter_pixmapfragment_wrapper.cpp + ) +endif() + +set(QtGui_OPTIONAL_SRC ) +set(QtGui_DROPPED_ENTRIES ) +check_qt_class(QtGui QAbstractPageSetupDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QAbstractPrintDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QGtkStyle QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPageSetupDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintEngine QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintPreviewDialog QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrintPreviewWidget QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrinter QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QPrinterInfo QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QSessionManager QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QSizeGrip QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QSystemTrayIcon QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) +check_qt_class(QtGui QMacStyle QtGui_OPTIONAL_SRC QtGui_DROPPED_ENTRIES) + qt4_wrap_cpp(QPYTEXTOBJECT_MOC "${pyside_SOURCE_DIR}/qpytextobject.h") set(QtGui_SRC @@ -225,6 +249,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpen_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpictureio_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpicture_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpixmapcache_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpixmapcache_key_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qpixmap_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qplaintextdocumentlayout_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qplaintextedit_wrapper.cpp @@ -378,39 +403,27 @@ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qwizard_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/qworkspace_wrapper.cpp ${SPECIFIC_OS_FILES} +${QPYTEXTOBJECT_MOC} ${QtGui_46_SRC} +${QtGui_47_SRC} +${QtGui_OPTIONAL_SRC} ) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/typesystem_gui.xml.in" "${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml" @ONLY) -check_qt_class(QtGui QGtkStyle QtGui_SRC) -check_qt_class(QtGui QSessionManager QtGui_SRC) -check_qt_class(QtGui QSizeGrip QtGui_SRC) -check_qt_class(QtGui QSystemTrayIcon QtGui_SRC) +set(QtGui_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtCore_BINARY_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}") -check_qt_class(QtGui QAbstractPageSetupDialog QtGui_SRC) -check_qt_class(QtGui QAbstractPrintDialog QtGui_SRC) -check_qt_class(QtGui QPageSetupDialog QtGui_SRC) -check_qt_class(QtGui QPrintDialog QtGui_SRC) -check_qt_class(QtGui QPrintPreviewWidget QtGui_SRC) -check_qt_class(QtGui QPrintPreviewDialog QtGui_SRC) -check_qt_class(QtGui QPrinter QtGui_SRC) -check_qt_class(QtGui QPrinterInfo QtGui_SRC) -check_qt_class(QtGui QPrintEngine QtGui_SRC) - -set(QtGui_typesystem_path "${QtCore_SOURCE_DIR}${PATH_SEP}${QtGui_SOURCE_DIR}") set(QtGui_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtGui/ ${pyside_SOURCE_DIR} ${QT_INCLUDE_DIR} ${SHIBOKEN_INCLUDE_DIR} ${libpyside_SOURCE_DIR} - ${PYTHON_INCLUDE_PATH} + ${SHIBOKEN_PYTHON_INCLUDE_DIR} ${QtCore_BINARY_DIR}/PySide/QtCore/) set(QtGui_libraries pyside - ${PYSIDE_PYTHON_LIBRARIES} + ${SHIBOKEN_PYTHON_LIBRARIES} ${SHIBOKEN_LIBRARY} ${QT_QTGUI_LIBRARY}) set(QtGui_deps "QtCore") @@ -421,8 +434,7 @@ create_pyside_module(QtGui QtGui_deps QtGui_typesystem_path QtGui_SRC - "${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml" - QPYTEXTOBJECT_MOC) - + "" + ${CMAKE_CURRENT_BINARY_DIR}/typesystem_gui.xml) install(FILES ${pyside_SOURCE_DIR}/qpytextobject.h DESTINATION include/PySide/QtGui/) diff --git a/PySide/QtGui/glue/qapplication_init.cpp b/PySide/QtGui/glue/qapplication_init.cpp index d082b99..f2e972a 100644 --- a/PySide/QtGui/glue/qapplication_init.cpp +++ b/PySide/QtGui/glue/qapplication_init.cpp @@ -5,61 +5,18 @@ static int QApplicationArgCount; static char** QApplicationArgValues; static const char QAPP_MACRO[] = "qApp"; -void DeleteQApplicationAtExit() +bool QApplicationConstructorStart(PyObject* argv) { - PySide::SignalManager::instance().clear(); - QCoreApplication* cpp = QApplication::instance(); - if (cpp) { - Shiboken::BindingManager &bmngr = Shiboken::BindingManager::instance(); - - // Delete all widgets, this is slow but is necessary to avoid problems with python object - foreach(QWidget* w, QApplication::allWidgets()) { - PyObject* wrapper = bmngr.retrieveWrapper(w); - if (wrapper) { - if (SbkBaseWrapper_hasOwnership(wrapper)) - delete w; // destroy C++ object and invalidate wrapper object - else - bmngr.destroyWrapper(wrapper); // only invalidate wrapper object - } - } - cpp->flush(); - delete cpp; - } -} - -int SbkQApplication_Init(PyObject* self, PyObject* args, PyObject*) -{ - if (Shiboken::isUserType(self) && !Shiboken::canCallConstructor(self->ob_type, Shiboken::SbkType())) - return -1; - if (QApplication::instance()) { PyErr_SetString(PyExc_RuntimeError, "A QApplication instance already exists."); - return -1; + return false; } - int numArgs = PyTuple_GET_SIZE(args); - if (numArgs != 1) { - PyErr_BadArgument(); - return -1; - } - - if (!PySequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QApplicationArgCount, &QApplicationArgValues, "PySideApp")) { - PyErr_BadArgument(); - return -1; - } - - QApplicationWrapper* cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues); - Shiboken::setCppPointer(reinterpret_cast(self), - Shiboken::SbkType(), - cptr); - SbkBaseWrapper_setValidCppObject(self, 1); - SbkBaseWrapper *sbkSelf = reinterpret_cast(self); - sbkSelf->containsCppWrapper = 1; - sbkSelf->hasOwnership = 0; - Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr); - PySide::signalUpdateSource(self); - cptr->metaObject(); + return Shiboken::sequenceToArgcArgv(argv, &QApplicationArgCount, &QApplicationArgValues, "PySideApp"); +} +void QApplicationConstructorEnd(PyObject* self) +{ // Verify if qApp is in main module PyObject* globalsDict = PyEval_GetGlobals(); if (globalsDict) { @@ -69,7 +26,25 @@ int SbkQApplication_Init(PyObject* self, PyObject* args, PyObject*) } PyObject_SetAttrString(moduleQtGui, QAPP_MACRO, self); - PySide::registerCleanupFunction(DeleteQApplicationAtExit); + PySide::registerCleanupFunction(&PySide::destroyQCoreApplication); Py_INCREF(self); - return 1; +} + +static void QApplicationConstructor(PyObject* self, PyObject* argv, QApplicationWrapper** cptr) +{ + if (QApplicationConstructorStart(argv)) { + *cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues); + Shiboken::Object::releaseOwnership(reinterpret_cast(self)); + QApplicationConstructorEnd(self); + } +} + +template +static void QApplicationConstructor(PyObject* self, PyObject* argv, T extraArg, QApplicationWrapper** cptr) +{ + if (QApplicationConstructorStart(argv)) { + *cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues, extraArg); + Shiboken::Object::releaseOwnership(reinterpret_cast(self)); + QApplicationConstructorEnd(self); + } } diff --git a/PySide/QtGui/glue/qlayout_help_functions.cpp b/PySide/QtGui/glue/qlayout_help_functions.cpp new file mode 100644 index 0000000..b366061 --- /dev/null +++ b/PySide/QtGui/glue/qlayout_help_functions.cpp @@ -0,0 +1,122 @@ +void addLayoutOwnership(QLayout* layout, QLayoutItem* item); +void removeLayoutOwnership(QLayout* layout, QWidget* widget); + +inline QByteArray retrieveObjectName(PyObject* obj) +{ + Shiboken::AutoDecRef objName(PyObject_Str(obj)); + return Shiboken::String::toCString(objName); +} + +inline void addLayoutOwnership(QLayout* layout, QWidget* widget) +{ + //transfer ownership to parent widget + QWidget *lw = layout->parentWidget(); + QWidget *pw = widget->parentWidget(); + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](widget)); + + //Transfer parent to layout widget + if (pw && lw && pw != lw) + Shiboken::Object::setParent(0, pyChild); + + if (!lw && !pw) { + //keep the reference while the layout is orphan + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](layout)); + Shiboken::Object::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); + } else { + if (!lw) + lw = pw; + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](lw)); + Shiboken::Object::setParent(pyParent, pyChild); + } +} + +inline void addLayoutOwnership(QLayout* layout, QLayout* other) +{ + //transfer all children widgets from other to layout parent widget + QWidget* parent = layout->parentWidget(); + if (!parent) { + //keep the reference while the layout is orphan + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout*](other)); + Shiboken::Object::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); + return; + } + + for (int i=0, i_max=other->count(); i < i_max; i++) { + QLayoutItem* item = other->itemAt(i); + if (PyErr_Occurred() || !item) + return; + addLayoutOwnership(layout, item); + } + + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout*](other)); + Shiboken::Object::setParent(pyParent, pyChild); +} + +inline void addLayoutOwnership(QLayout* layout, QLayoutItem* item) +{ + if (!item) + return; + + QWidget* w = item->widget(); + if (w) + addLayoutOwnership(layout, w); + else { + QLayout* l = item->layout(); + if (l) + addLayoutOwnership(layout, l); + } + + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayoutItem*](item)); + Shiboken::Object::setParent(pyParent, pyChild); +} + +static void removeWidgetFromLayout(QLayout* layout, QWidget* widget) +{ + QWidget* parent = widget->parentWidget(); + + if (!parent) { + //remove reference on layout + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](widget)); + Shiboken::Object::removeReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild); + } else { + //give the ownership to parent + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](parent)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](widget)); + Shiboken::Object::setParent(pyParent, pyChild); + } +} + +inline void removeLayoutOwnership(QLayout* layout, QLayoutItem* item) +{ + QWidget* w = item->widget(); + if (w) + removeWidgetFromLayout(layout, w); + else { + QLayout* l = item->layout(); + if (l) + removeLayoutOwnership(layout, l); + } + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayoutItem*](item)); + Shiboken::Object::invalidate(pyChild); + Shiboken::Object::setParent(0, pyChild); +} + +inline void removeLayoutOwnership(QLayout* layout, QWidget* widget) +{ + if (!widget) + return; + + for (int i=0, i_max=layout->count(); i < i_max; i++) { + QLayoutItem* item = layout->itemAt(i); + if (PyErr_Occurred() || !item) + return; + if (item->widget() == widget) + removeLayoutOwnership(layout, item); + } +} diff --git a/PySide/QtGui/glue/qlayout_help_functions.h b/PySide/QtGui/glue/qlayout_help_functions.h deleted file mode 100644 index e62077a..0000000 --- a/PySide/QtGui/glue/qlayout_help_functions.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef QLAYOUT_HELP_FUNCTIONS -#define QLAYOUT_HELP_FUNCTIONS - -void addLayoutOwnership(QLayout *layout, QLayoutItem *item); - -inline QByteArray retrieveObjectName(PyObject *obj) -{ - Shiboken::AutoDecRef objName(PyObject_Str(obj)); - return PyString_AsString(objName); -} - -inline void addLayoutOwnership(QLayout *layout, QWidget *widget) -{ - //transfer ownership to parent widget - QWidget *parent = layout->parentWidget(); - - if (!parent) { - //keep the reference while the layout is orphan - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(widget)); - Shiboken::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); - } else { - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(parent)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(widget)); - Shiboken::setParent(pyParent, pyChild); - } -} - -inline void addLayoutOwnership(QLayout *layout, QLayout *other) -{ - //transfer all children widgetes from other to layout parent widget - QWidget *parent = layout->parentWidget(); - if (!parent) { - //keep the reference while the layout is orphan - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(other)); - Shiboken::keepReference(reinterpret_cast(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true); - return; - } - - for (int i=0, i_max=other->count(); i < i_max; i++) { - addLayoutOwnership(layout, other->itemAt(i)); - } - - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(other)); - Shiboken::setParent(pyParent, pyChild); - -} - -inline void addLayoutOwnership(QLayout *layout, QLayoutItem *item) -{ - QWidget *w = item->widget(); - if (w) - addLayoutOwnership(layout, w); - else { - QLayout *l = item->layout(); - if (l) - addLayoutOwnership(layout, l); - } - - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(layout)); - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(item)); - Shiboken::setParent(pyParent, pyChild); -} - -#endif diff --git a/PySide/QtGui/glue/qmenu_glue.h b/PySide/QtGui/glue/qmenu_glue.cpp similarity index 58% rename from PySide/QtGui/glue/qmenu_glue.h rename to PySide/QtGui/glue/qmenu_glue.cpp index 1a6cb19..0636dfa 100644 --- a/PySide/QtGui/glue/qmenu_glue.h +++ b/PySide/QtGui/glue/qmenu_glue.cpp @@ -1,8 +1,6 @@ - -inline PyObject* -addActionWithPyObject(QMenu *self, const QIcon& icon, const QString& text, PyObject *callback, const QKeySequence &shortcut) +inline PyObject* addActionWithPyObject(QMenu* self, const QIcon& icon, const QString& text, PyObject* callback, const QKeySequence& shortcut) { - QAction *act = new QAction(text, self); + QAction* act = new QAction(text, self); if (!icon.isNull()) act->setIcon(icon); @@ -12,7 +10,7 @@ addActionWithPyObject(QMenu *self, const QIcon& icon, const QString& text, PyObj self->addAction(act); - PyObject *pyAct = Shiboken::Converter::toPython(act); + PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, SIGNAL(triggered()), callback)); if (result.isNull()) { Py_DECREF(pyAct); diff --git a/PySide/QtGui/glue/qmenubar_glue.h b/PySide/QtGui/glue/qmenubar_glue.cpp similarity index 87% rename from PySide/QtGui/glue/qmenubar_glue.h rename to PySide/QtGui/glue/qmenubar_glue.cpp index 9568fa8..2326a76 100644 --- a/PySide/QtGui/glue/qmenubar_glue.h +++ b/PySide/QtGui/glue/qmenubar_glue.cpp @@ -5,7 +5,7 @@ addActionWithPyObject(QMenuBar* self, const QString& text, PyObject* callback) self->addAction(act); - PyObject* pyAct = Shiboken::Converter::toPython(act); + PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); PyObject* result = PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, SIGNAL(triggered(bool)), callback); diff --git a/PySide/QtGui/glue/qtgui_qapp.cpp b/PySide/QtGui/glue/qtgui_qapp.cpp index f893f8e..5148b57 100644 --- a/PySide/QtGui/glue/qtgui_qapp.cpp +++ b/PySide/QtGui/glue/qtgui_qapp.cpp @@ -1,4 +1,10 @@ // Init qApp macro to None. -Py_INCREF(Py_None); -PyModule_AddObject(module, "qApp", Py_None); +if (qApp) { + PyObject* pyApp = %CONVERTTOPYTHON[QApplication*](qApp); + Py_INCREF(pyApp); + PyModule_AddObject(module, "qApp", pyApp); +} else { + Py_INCREF(Py_None); + PyModule_AddObject(module, "qApp", Py_None); +} moduleQtGui = module; diff --git a/PySide/QtGui/glue/qwidget_glue.cpp b/PySide/QtGui/glue/qwidget_glue.cpp new file mode 100644 index 0000000..cfa3f67 --- /dev/null +++ b/PySide/QtGui/glue/qwidget_glue.cpp @@ -0,0 +1,65 @@ +static QString retrieveObjectName(PyObject *obj) +{ + Shiboken::AutoDecRef objName(PyObject_Str(obj)); + return QString(Shiboken::String::toCString(objName)); +} + + +/** + * Tranfer objects ownership from layout to widget + **/ +static inline void qwidgetReparentLayout(QWidget *parent, QLayout *layout) +{ + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](parent)); + + for (int i=0; i < layout->count(); i++) { + QLayoutItem* item = layout->itemAt(i); + if (PyErr_Occurred() || !item) + return; + + QWidget* w = item->widget(); + if (w) { + QWidget* pw = w->parentWidget(); + if (pw != parent) { + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget*](w)); + Shiboken::Object::setParent(pyParent, pyChild); + } + } else { + QLayout* l = item->layout(); + if (l) + qwidgetReparentLayout(parent, l); + } + } + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::Object::setParent(pyParent, pyChild); + //remove previous references + Shiboken::Object::keepReference(reinterpret_cast(pyChild.object()), qPrintable(retrieveObjectName(pyChild)), Py_None); +} + +static inline void qwidgetSetLayout(QWidget *self, QLayout *layout) +{ + if (!layout || self->layout()) + return; + + QObject* oldParent = layout->parent(); + if (oldParent && oldParent != self) { + if (oldParent->isWidgetType()) { + // remove old parent policy + Shiboken::AutoDecRef pyLayout(%CONVERTTOPYTHON[QLayout*](layout)); + Shiboken::Object::setParent(Py_None, pyLayout); + } else { + PyErr_Format(PyExc_RuntimeError, "QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", + qPrintable(layout->objectName()), self->metaObject()->className(), qPrintable(self->objectName())); + return; + } + } + + if (oldParent != self) { + qwidgetReparentLayout(self, layout); + if (PyErr_Occurred()) + return; + + self->setLayout(layout); + } +} diff --git a/PySide/QtGui/glue/qwidget_glue.h b/PySide/QtGui/glue/qwidget_glue.h deleted file mode 100644 index 6be6518..0000000 --- a/PySide/QtGui/glue/qwidget_glue.h +++ /dev/null @@ -1,65 +0,0 @@ -static QString retrieveObjectName(PyObject *obj) -{ - Shiboken::AutoDecRef objName(PyObject_Str(obj)); - return QString(PyString_AsString(objName)); -} - - -/** - * Tranfer objects ownership from layout to widget - **/ -static inline void -qwidgetReparentLayout(QWidget *parent, QLayout *layout) -{ - Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(parent)); - - for (int i=0; i < layout->count(); i++) - { - QLayoutItem *item = layout->itemAt(i); - QWidget *w = item->widget(); - if (w) - { - QWidget* pw = w->parentWidget(); - if (pw != parent) { - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(w)); - Shiboken::setParent(pyParent, pyChild); - } - } - else - { - QLayout *l = item->layout(); - if (l) - qwidgetReparentLayout(parent, l); - } - } - - Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(layout)); - Shiboken::setParent(pyParent, pyChild); - //remove previous references - Shiboken::keepReference(reinterpret_cast(pyChild.object()), qPrintable(retrieveObjectName(pyChild)), Py_None); -} - -static inline void -qwidgetSetLayout(QWidget *self, QLayout *layout) -{ - if (!layout || self->layout()) - return; - - QObject* oldParent = layout->parent(); - if (oldParent && oldParent != self) { - if (oldParent->isWidgetType()) { - // remove old parent policy - Shiboken::AutoDecRef pyLayout(Shiboken::Converter::toPython(layout)); - Shiboken::setParent(Py_None, pyLayout); - } else { - PyErr_Format(PyExc_RuntimeError, "QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", - qPrintable(layout->objectName()), self->metaObject()->className(), qPrintable(self->objectName())); - return; - } - } - - if (oldParent != self) { - qwidgetReparentLayout(self, layout); - self->setLayout(layout); - } -} diff --git a/PySide/QtGui/qpixmap_conversion.h b/PySide/QtGui/qpixmap_conversion.h deleted file mode 100644 index 1423959..0000000 --- a/PySide/QtGui/qpixmap_conversion.h +++ /dev/null @@ -1,49 +0,0 @@ -namespace Shiboken { -inline bool Converter::checkType(PyObject* pyObj) -{ - return ValueTypeConverter::checkType(pyObj); -} - -inline bool Converter::isConvertible(PyObject* pyobj) -{ - if (ValueTypeConverter::isConvertible(pyobj)) - return true; - SbkBaseWrapperType* shiboType = reinterpret_cast(SbkType()); - bool isVariant = Converter::checkType(pyobj); - if (isVariant) { - QVariant var(Converter::toCpp(pyobj)); - return var.type() == QVariant::Pixmap; - } else if (Converter::checkType(pyobj) || Converter::checkType(pyobj)) { - return true; - } else if (shiboType->ext_isconvertible) { - return shiboType->ext_isconvertible(pyobj); - } - return false; - -} - -inline QPixmap Converter::toCpp(PyObject* pyobj) -{ - SbkBaseWrapperType* shiboType = reinterpret_cast(SbkType()); - bool isVariant = Converter::checkType(pyobj); - if (isVariant) { - QVariant var(Converter::toCpp(pyobj)); - return var.value(); - } else if (Converter::checkType(pyobj)) { - return QPixmap(Shiboken::Converter::toCpp(pyobj)); - } else if (Converter::checkType(pyobj)) { - return QPixmap(Shiboken::Converter::toCpp(pyobj)); - } else if (shiboType->ext_isconvertible && shiboType->ext_tocpp && shiboType->ext_isconvertible(pyobj)) { - QPixmap* cptr = reinterpret_cast(shiboType->ext_tocpp(pyobj)); - std::auto_ptr cptr_auto_ptr(cptr); - return *cptr; - } - - return *Converter::toCpp(pyobj); -} - -inline PyObject* Converter::toPython(const QPixmap& cppObj) -{ - return ValueTypeConverter::toPython(cppObj); -} -} diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml index 68d5c0d..552636a 100644 --- a/PySide/QtGui/typesystem_gui_common.xml +++ b/PySide/QtGui/typesystem_gui_common.xml @@ -22,11 +22,12 @@