diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dd2ae89..fa5155d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,27 +103,12 @@ set(SONGBOOK_CLIENT_RCS # }}} -# Finding Qt5 find_package(Qt5 CONFIG REQUIRED Network Widgets Script Svg) -list(APPEND QT_LIBRARIES ${Qt5Widgets_LIBRARIES};${Qt5Script_LIBRARIES};${Qt5Svg_LIBRARIES}) +LIST(APPEND QT_LIBRARIES ${Qt5Widgets_LIBRARIES};${Qt5Script_LIBRARIES};${Qt5Svg_LIBRARIES}) -################ DIRTY HACK FOR IT TO WORK FOR NOW ################### -#### Problem lies with cmake, can't properly find python3 on Mac ##### -SET(PYTHON_INCLUDE_DIR /Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m) -SET(PYTHON_LIBRARY /Library/Frameworks/Python.framework/Versions/3.4/lib) -############################# End of Hack ############################ +#set(QT_USE_QTSCRIPT true) +#set(QT_USE_QTSVG true) -# Finding Python 3 -find_package(PythonLibs 3.3 REQUIRED) -include_directories(${PYTHON_INCLUDE_DIRS}) -list(APPEND LIBRARIES ${PYTHON_LIBRARIES}) - -# Setup PythonQt -include(${CMAKE_MODULE_PATH}/FindPythonQt.cmake) -list(APPEND LIBRARIES ${PYTHONQT_LIBRARIES}) -include_directories(${PYTHONQT_INCLUDE_DIR}) - -# Use LibArchive if(ENABLE_LIBRARY_DOWNLOAD) set(QT_USE_QTNETWORK true) LIST(APPEND QT_LIBRARIES ${Qt5Network_LIBRARIES}) @@ -131,16 +116,15 @@ if(ENABLE_LIBRARY_DOWNLOAD) LIST(APPEND LIBRARIES ${LibArchive_LIBRARIES}) endif() -# Use Hunspell if(ENABLE_SPELLCHECK) include_directories(${HUNSPELL_INCLUDE_DIR}) LIST(APPEND LIBRARIES ${HUNSPELL_LIBRARIES}) endif() -# Qt Property Editor configuration +# include(${QT_USE_FILE}) + include(${CMAKE_MODULE_PATH}/qt-property-editor-config.cmake) -# Local Includes include_directories( ${SOURCE_DIR} ${SOURCE_DIR}/src/ @@ -174,8 +158,9 @@ if(WIN32) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-enable-auto-import") endif(WIN32) -# Setup Libraries for linking list(APPEND LIBRARIES ${QT_LIBRARIES}) +#message("Qt Libraries = ${QT_LIBRARIES}") +#message("Test = ${SONGBOOK_CLIENT_SOURCES}") target_link_libraries(${SONGBOOK_CLIENT_APPLICATION_NAME} ${LIBRARIES}) # {{{ Internationalization diff --git a/cmake/CMakeLists-Mac.cmake b/cmake/CMakeLists-Mac.cmake index 2c0d20fb..fb13eef7 100644 --- a/cmake/CMakeLists-Mac.cmake +++ b/cmake/CMakeLists-Mac.cmake @@ -92,7 +92,6 @@ COMMAND ${CCS2} COMMAND ${CCS3} COMMAND ${CCS4} - COMMAND cp ARGS ${SOURCE_DIR}/pythonqt/lib/*.dylib ${CMAKE_CURRENT_BINARY_DIR}/${SONGBOOK_CLIENT_APPLICATION_NAME}.app/Contents/Frameworks COMMAND macdeployqt ${CMAKE_CURRENT_BINARY_DIR}/${SONGBOOK_CLIENT_APPLICATION_NAME}.app ) diff --git a/cmake/FindPythonQt.cmake b/cmake/FindPythonQt.cmake deleted file mode 100644 index 66ecb70e..00000000 --- a/cmake/FindPythonQt.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# Find PythonQt -# -# Sets PYTHONQT_FOUND, PYTHONQT_INCLUDE_DIR, PYTHONQT_LIBRARY, PYTHONQT_LIBRARIES -# - -set(PYTHONQT_INSTALL_DIR ${SOURCE_DIR}/pythonqt) -#find_path(PYTHONQT_INSTALL_DIR ${SOURCE_DIR}/pythonqt DOC "Directory where PythonQt was installed.") -find_path(PYTHONQT_INCLUDE_DIR PythonQt.h "${PYTHONQT_INSTALL_DIR}/include" DOC "Path to the PythonQt include directory") -find_library(PYTHONQT_LIBRARY PythonQt PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "The PythonQt library.") - -mark_as_advanced(PYTHONQT_INSTALL_DIR) -mark_as_advanced(PYTHONQT_INCLUDE_DIR) -mark_as_advanced(PYTHONQT_LIBRARY) - -# On linux, also find libutil -if(UNIX AND NOT APPLE) - find_library(PYTHONQT_LIBUTIL util) - mark_as_advanced(PYTHONQT_LIBUTIL) -endif() - -set(PYTHONQT_FOUND 0) -if(PYTHONQT_INCLUDE_DIR AND PYTHONQT_LIBRARY) - # Currently CMake'ified PythonQt only supports building against a python Release build. - # This applies independently of CTK build type (Release, Debug, ...) - add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK) - set(PYTHONQT_FOUND 1) - set(PYTHONQT_LIBRARIES ${PYTHONQT_LIBRARY} ${PYTHONQT_LIBUTIL}) -endif() - -if(NOT ${PYTHONQT_FOUND}) - message(FATAL_ERROR "PythonQt is required to build ${PROJECT_NAME}") -else() - message(STATUS "PythonQt found") -endif() diff --git a/pythonqt/include/PythonQt.h b/pythonqt/include/PythonQt.h deleted file mode 100644 index 5d22b4c3..00000000 --- a/pythonqt/include/PythonQt.h +++ /dev/null @@ -1,741 +0,0 @@ -#ifndef _PYTHONQT_H -#define _PYTHONQT_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQt.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include -#include "PythonQtUtils.h" -#include "PythonQtSystem.h" -#include "PythonQtInstanceWrapper.h" -#include "PythonQtClassWrapper.h" -#include "PythonQtSlot.h" -#include "PythonQtObjectPtr.h" -#include "PythonQtStdIn.h" -#include -#include -#include -#include -#include -#include -#include - -class PythonQtClassInfo; -class PythonQtPrivate; -class PythonQtMethodInfo; -class PythonQtSignalReceiver; -class PythonQtImportFileInterface; -class PythonQtCppWrapperFactory; -class PythonQtForeignWrapperFactory; -class PythonQtQFileImporter; - -typedef void PythonQtQObjectWrappedCB(QObject* object); -typedef void PythonQtQObjectNoLongerWrappedCB(QObject* object); -typedef void* PythonQtPolymorphicHandlerCB(const void *ptr, const char **class_name); - -typedef void PythonQtShellSetInstanceWrapperCB(void* object, PythonQtInstanceWrapper* wrapper); - -template void PythonQtSetInstanceWrapperOnShell(void* object, PythonQtInstanceWrapper* wrapper) { - (reinterpret_cast(object))->_wrapper = wrapper; -} - -//! returns the offset that needs to be added to upcast an object of type T1 to T2 -template int PythonQtUpcastingOffset() { - return ((reinterpret_cast(static_cast(reinterpret_cast(0x100)))) - - (reinterpret_cast(reinterpret_cast(0x100)))); -} - -//! callback to create a QObject lazily -typedef QObject* PythonQtQObjectCreatorFunctionCB(); - -//! helper template to create a derived QObject class -template QObject* PythonQtCreateObject() { return new T(); }; - -//! The main interface to the Python Qt binding, realized as a singleton -/*! - Use PythonQt::init() to initialize the singleton and PythonQt::self() to access it. - While there can be only one PythonQt instance, you can have any number of Python context to do scripting in. - One possibility is to use createModuleFromFile(), createModuleFromScript() or createUniqueModule() to get a context - that is separated from the other contexts. Alternatively you can use Python dicts as contexts for script evaluation, - but you will need to populate the dict with the __builtins__ instance to have all Pythons available when running - code in the scope of a dict. - */ -class PYTHONQT_EXPORT PythonQt : public QObject { - - Q_OBJECT - -public: - - //! flags that can be passed to PythonQt::init() - enum InitFlags { - RedirectStdOut = 1, //!<< sets if the std out/err is redirected to pythonStdOut() and pythonStdErr() signals - IgnoreSiteModule = 2, //!<< sets if Python should ignore the site module - ExternalHelp = 4, //!<< sets if help() calls on PythonQt modules are forwarded to the pythonHelpRequest() signal - PythonAlreadyInitialized = 8 //!<< sets that PythonQt should not can PyInitialize, since it is already done - }; - - //! flags that tell PythonQt which operators to expect on the registered type - enum TypeSlots { - Type_Add = 1, - Type_Subtract = 1 << 1, - Type_Multiply = 1 << 2, - Type_Divide = 1 << 3, - Type_Mod = 1 << 4, - Type_And = 1 << 5, - Type_Or = 1 << 6, - Type_Xor = 1 << 7, - Type_LShift = 1 << 8, - Type_RShift = 1 << 9, - - Type_InplaceAdd = 1 << 10, - Type_InplaceSubtract = 1 << 11, - Type_InplaceMultiply = 1 << 12, - Type_InplaceDivide = 1 << 13, - Type_InplaceMod = 1 << 14, - Type_InplaceAnd = 1 << 15, - Type_InplaceOr = 1 << 16, - Type_InplaceXor = 1 << 17, - Type_InplaceLShift = 1 << 18, - Type_InplaceRShift = 1 << 19, - - Type_Length = 1 << 20, - Type_MappingSetItem = 1 << 21, - Type_MappingGetItem = 1 << 22, - - Type_Invert = 1 << 29, - Type_RichCompare = 1 << 30, - Type_NonZero = 1 << 31, - - }; - - //! enum for profiling callback - enum ProfilingCallbackState { - Enter = 1, - Leave = 2 - }; - - //! callback for profiling. className and methodName are only passed when state == Enter, otherwise - //! they are NULL. - typedef void ProfilingCB(ProfilingCallbackState state, const char* className, const char* methodName, PyObject* args); - - //--------------------------------------------------------------------------- - //! \name Singleton Initialization - //@{ - - //! initialize the python qt binding (flags are a or combination of PythonQt::InitFlags), if \c pythonQtModuleName is given - //! it defines the name of the python module that PythonQt will add, otherwise "PythonQt" is used. - //! This can be used to e.g. pass in PySide or PyQt4 to make it more compatible. - static void init(int flags = IgnoreSiteModule | RedirectStdOut, const QByteArray& pythonQtModuleName = QByteArray()); - - //! cleanup of the singleton - static void cleanup(); - - //! get the singleton instance - static PythonQt* self(); - - //@} - - //! defines the object types for introspection - enum ObjectType { - Class, - Function, - Variable, - Module, - Anything, - CallOverloads - }; - - - //--------------------------------------------------------------------------- - //! \name Standard input handling - //@{ - - //! Overwrite default handling of stdin using a custom callback. It internally backup - //! the original 'sys.stdin' into 'sys.pythonqt_original_stdin' - void setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * callbackData = 0); - - //! Enable or disable stdin custom callback. It resets 'sys.stdin' using either 'sys.pythonqt_stdin' - //! or 'sys.pythonqt_original_stdin' - void setRedirectStdInCallbackEnabled(bool enabled); - - //@} - - //--------------------------------------------------------------------------- - //! \name Modules - //@{ - - //! get the __main__ module of python - PythonQtObjectPtr getMainModule(); - - //! import the given module and return a reference to it (useful to import e.g. "sys" and call something on it) - //! If a module is already imported, this returns the already imported module. - PythonQtObjectPtr importModule(const QString& name); - - //! creates the new module \c name and evaluates the given file in the context of that module - //! If the \c script is empty, the module contains no initial code. You can use evalScript/evalCode to add code - //! to a module later on. - //! The user needs to make sure that the \c name is unique in the python module dictionary. - PythonQtObjectPtr createModuleFromFile(const QString& name, const QString& filename); - - //! creates the new module \c name and evaluates the given script in the context of that module. - //! If the \c script is empty, the module contains no initial code. You can use evalScript/evalCode to add code - //! to a module later on. - //! The user needs to make sure that the \c name is unique in the python module dictionary. - PythonQtObjectPtr createModuleFromScript(const QString& name, const QString& script = QString()); - - //! create a uniquely named module, you can use evalFile or evalScript to populate the module with - //! script code - PythonQtObjectPtr createUniqueModule(); - - //@} - - //--------------------------------------------------------------------------- - //! \name Importing/Paths - //@{ - - //! overwrite the python sys path (call this directly after PythonQt::init() if you want to change the std python sys path) - void overwriteSysPath(const QStringList& paths); - - //! prepend a path to sys.path to allow importing from it - void addSysPath(const QString& path); - - //! sets the __path__ list of a module to the given list (important for local imports) - void setModuleImportPath(PyObject* module, const QStringList& paths); - - //@} - - //--------------------------------------------------------------------------- - //! \name Registering Classes - //@{ - - //! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well) - /* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject, - you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */ - void registerClass(const QMetaObject* metaobject, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL); - - //! add a wrapper object for the given QMetaType typeName, also does an addClassDecorators() to add constructors for variants - //! (ownership of wrapper is passed to PythonQt) - /*! Make sure that you have done a qRegisterMetaType first, if typeName is a user type! - - This will add a wrapper object that is used to make calls to the given classname \c typeName. - All slots that take a pointer to typeName as the first argument will be callable from Python on - a variant object that contains such a type. - */ - void registerCPPClass(const char* typeName, const char* parentTypeName = NULL, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL); - - //! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes - //! and it will register the classes when it first sees a pointer to such a derived class - void registerQObjectClassNames(const QStringList& names); - - //! add a parent class relation to the \c given typeName, the upcastingOffset is needed for multiple inheritance - //! and can be calculated using PythonQtUpcastingOffset(), which also verifies that - //! type is really derived from parentType. - //! Returns false if the typeName was not yet registered. - bool addParentClass(const char* typeName, const char* parentTypeName, int upcastingOffset=0); - - //! add a handler for polymorphic downcasting - void addPolymorphicHandler(const char* typeName, PythonQtPolymorphicHandlerCB* cb); - - //@} - - //--------------------------------------------------------------------------- - //! \name Script Parsing and Evaluation - //@{ - - //! parses the given file and returns the python code object, this can then be used to call evalCode() - PythonQtObjectPtr parseFile(const QString& filename); - - //! evaluates the given code and returns the result value (use Py_Compile etc. to create pycode from string) - //! If pycode is NULL, a python error is printed. - QVariant evalCode(PyObject* object, PyObject* pycode); - - //! evaluates the given script code and returns the result value - QVariant evalScript(PyObject* object, const QString& script, int start = Py_file_input); - - //! evaluates the given script code from file - void evalFile(PyObject* object, const QString& filename); - - //@} - - //--------------------------------------------------------------------------- - //! \name Signal Handlers - //@{ - - //! add a signal handler to the given \c signal of \c obj and connect it to a callable \c objectname in module - bool addSignalHandler(QObject* obj, const char* signal, PyObject* module, const QString& objectname); - - //! remove a signal handler from the given \c signal of \c obj - bool removeSignalHandler(QObject* obj, const char* signal, PyObject* module, const QString& objectname); - - //! add a signal handler to the given \c signal of \c obj and connect it to a callable \c receiver - bool addSignalHandler(QObject* obj, const char* signal, PyObject* receiver); - - //! remove a signal handler from the given \c signal of \c obj - bool removeSignalHandler(QObject* obj, const char* signal, PyObject* receiver); - - //@} - - //--------------------------------------------------------------------------- - //! \name Variable access - //@{ - - //! add the given \c qObject to the python \c object as a variable with \c name (it can be removed via clearVariable) - void addObject(PyObject* object, const QString& name, QObject* qObject); - - //! add the given variable to the object - void addVariable(PyObject* object, const QString& name, const QVariant& v); - - //! remove the given variable - void removeVariable(PyObject* module, const QString& name); - - //! get the variable with the \c name of the \c object, returns an invalid QVariant on error - QVariant getVariable(PyObject* object, const QString& name); - - //! read vars etc. in scope of an \c object, optional looking inside of an object \c objectname - QStringList introspection(PyObject* object, const QString& objectname, ObjectType type); - //! read vars etc. in scope of the given \c object - QStringList introspectObject(PyObject* object, ObjectType type); - //! read vars etc. in scope of the type object called \c typename. First the typename - //! of the form module.type is split into module and type. Then the module is looked up - //! in sys.modules. If the module or type is not found there, then the type is looked up in - //! the __builtin__ module. - QStringList introspectType(const QString& typeName, ObjectType type); - - //! returns the found callable object or NULL - //! @return new reference - PythonQtObjectPtr lookupCallable(PyObject* object, const QString& name); - - //! returns the return type of the method of a wrapped c++ object referenced by \c objectname - QString getReturnTypeOfWrappedMethod(PyObject* module, const QString& objectname); - //! returns the return type of the method \c methodName of a wrapped c++ type referenced by \c typeName - QString getReturnTypeOfWrappedMethod(const QString& typeName, const QString& methodName); - //@} - - //--------------------------------------------------------------------------- - //! \name Calling Python Objects - //@{ - - //! call the given python \c callable in the scope of object, returns the result converted to a QVariant - QVariant call(PyObject* object, const QString& callable, const QVariantList& args = QVariantList(), const QVariantMap& kwargs = QVariantMap()); - - //! call the given python object, returns the result converted to a QVariant - QVariant call(PyObject* callable, const QVariantList& args = QVariantList(), const QVariantMap& kwargs = QVariantMap()); - - //! call the given python object, returns the result as new PyObject - PyObject* callAndReturnPyObject(PyObject* callable, const QVariantList& args = QVariantList(), const QVariantMap& kwargs = QVariantMap()); - - //@} - - //--------------------------------------------------------------------------- - //! \name Decorations, Constructors, Wrappers... - //@{ - - //! add an object whose slots will be used as decorator slots for - //! other QObjects or CPP classes. The slots need to follow the - //! convention that the first argument is a pointer to the wrapped object. - //! (ownership is passed to PythonQt) - /*! - Example: - - A slot with the signature - - \code - bool doSomething(QWidget* w, int a) - \endcode - - will extend QWidget instances (and derived classes) with a "bool doSomething(int a)" slot - that will be called with the concrete instance as first argument. - So in Python you can now e.g. call - - \code - someWidget.doSomething(12) - \endcode - - without QWidget really having this method. This allows to easily make normal methods - of Qt classes callable by forwarding them with such decorator slots - or to make CPP classes (which are not derived from QObject) callable from Python. - */ - void addInstanceDecorators(QObject* o); - - //! add an object whose slots will be used as decorator slots for - //! class objects (ownership is passed to PythonQt) - /*! - The slots need to follow the following convention: - - SomeClass* new_SomeClass(...) - - QVariant new_SomeClass(...) - - void delete_SomeClass(SomeClass*) - - ... static_SomeClass_someName(...) - - This will add: - - a constructor - - a constructor which generates a QVariant - - a destructor (only useful for CPP objects) - - a static decorator slot which will be available on the MetaObject (visible in PythonQt module) - - */ - void addClassDecorators(QObject* o); - - //! this will add the object both as class and instance decorator (ownership is passed to PythonQt) - void addDecorators(QObject* o); - - //! add the given factory to PythonQt (ownership stays with caller) - void addWrapperFactory(PythonQtCppWrapperFactory* factory); - - //! add the given factory to PythonQt (ownership stays with caller) - void addWrapperFactory(PythonQtForeignWrapperFactory* factory); - - //! remove the wrapper factory - void removeWrapperFactory(PythonQtCppWrapperFactory* factory); - - //! remove the wrapper factory - void removeWrapperFactory(PythonQtForeignWrapperFactory* factory); - - //@} - - //--------------------------------------------------------------------------- - //! \name Custom Importer - //@{ - - //! replace the internal import implementation and use the supplied interface to load files (both py and pyc files) - //! (this method should be called directly after initialization of init() and before calling overwriteSysPath(). - //! On the first call to this method, it will install a generic PythonQt importer in Pythons "path_hooks". - //! This is not reversible, so even setting setImporter(NULL) afterwards will - //! keep the custom PythonQt importer with a QFile default import interface. - //! Subsequent python import calls will make use of the passed importInterface - //! which forwards all import calls to the given \c importInterface. - //! Passing NULL will install a default QFile importer. - //! (\c importInterface ownership stays with caller) - void setImporter(PythonQtImportFileInterface* importInterface); - - //! this installs the default QFile importer (which effectively does a setImporter(NULL)) - //! (without calling setImporter or installDefaultImporter at least once, the default python import - //! mechanism is in place) - //! the default importer allows to import files from anywhere QFile can read from, - //! including the Qt resource system using ":". Keep in mind that you need to extend - //! "sys.path" with ":" to be able to import from the Qt resources. - void installDefaultImporter() { setImporter(NULL); } - - //! set paths that the importer should ignore - void setImporterIgnorePaths(const QStringList& paths); - - //! get paths that the importer should ignore - const QStringList& getImporterIgnorePaths(); - - //! get access to the file importer (if set) - static PythonQtImportFileInterface* importInterface(); - - //@} - - //--------------------------------------------------------------------------- - //! \name Other Stuff - //@{ - - //! get access to internal data (should not be used on the public API, but is used by some C functions) - static PythonQtPrivate* priv() { return _self->_p; } - - //! clear all NotFound entries on all class infos, to ensure that - //! newly loaded wrappers can add methods even when the object was wrapped by PythonQt before the wrapper was loaded - void clearNotFoundCachedMembers(); - - //! handle a python error, call this when a python function fails. If no error occurred, it returns false. - //! The error is currently just output to the python stderr, future version might implement better trace printing - bool handleError(); - - //! return \a true if \a handleError() has been called and an error occured. - bool hadError()const; - - //! reset error flag. After calling this, hadError() will return false. - //! \sa hadError() - void clearError(); - - //! if set to true, the systemExitExceptionRaised signal will be emitted if exception SystemExit is caught - //! \sa handleError() - void setSystemExitExceptionHandlerEnabled(bool value); - - //! return \a true if SystemExit exception is handled by PythonQt - //! \sa setSystemExitExceptionHandlerEnabled() - bool systemExitExceptionHandlerEnabled() const; - - //! set a callback that is called when a QObject with parent == NULL is wrapped by PythonQt - void setQObjectWrappedCallback(PythonQtQObjectWrappedCB* cb); - //! set a callback that is called when a QObject with parent == NULL is no longer wrapped by PythonQt - void setQObjectNoLongerWrappedCallback(PythonQtQObjectNoLongerWrappedCB* cb); - - //! call the callback if it is set - static void qObjectNoLongerWrappedCB(QObject* o); - - //! called by internal help methods - PyObject* helpCalled(PythonQtClassInfo* info); - - //! returns the found object or NULL - //! @return new reference - PythonQtObjectPtr lookupObject(PyObject* module, const QString& name); - - //! sets a callback that is called before and after function calls for profiling - void setProfilingCallback(ProfilingCB* cb); - - //@} - -Q_SIGNALS: - //! emitted when python outputs something to stdout (and redirection is turned on) - void pythonStdOut(const QString& str); - //! emitted when python outputs something to stderr (and redirection is turned on) - void pythonStdErr(const QString& str); - - //! emitted when help() is called on a PythonQt object and \c ExternalHelp is enabled - void pythonHelpRequest(const QByteArray& cppClassName); - - //! emitted when both custom SystemExit exception handler is enabled and a SystemExit - //! exception is raised. - //! \sa setSystemExitExceptionHandlerEnabled(bool) - void systemExitExceptionRaised(int exitCode); - -private: - void initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQtModuleName); - - QString getReturnTypeOfWrappedMethodHelper(const PythonQtObjectPtr& variableObject, const QString& methodName, const QString& context); - - PyObject* getObjectByType(const QString& typeName); - - //! callback for stdout redirection, emits pythonStdOut signal - static void stdOutRedirectCB(const QString& str); - //! callback for stderr redirection, emits pythonStdErr signal - static void stdErrRedirectCB(const QString& str); - - //! get (and create if not available) the signal receiver of that QObject, signal receiver is made child of the passed \c obj - PythonQtSignalReceiver* getSignalReceiver(QObject* obj); - - PythonQt(int flags, const QByteArray& pythonQtModuleName); - ~PythonQt(); - - static PythonQt* _self; - static int _uniqueModuleCount; - - PythonQtPrivate* _p; - -}; - -//! internal PythonQt details -class PYTHONQT_EXPORT PythonQtPrivate : public QObject { - - Q_OBJECT - -public: - PythonQtPrivate(); - ~PythonQtPrivate(); - - enum DecoratorTypes { - StaticDecorator = 1, - ConstructorDecorator = 2, - DestructorDecorator = 4, - InstanceDecorator = 8, - AllDecorators = 0xffff - }; - - //! get the suffixes that are used for shared libraries - const QStringList& sharedLibrarySuffixes() { return _sharedLibrarySuffixes; } - - //! returns if the id is the id for PythonQtObjectPtr - bool isPythonQtObjectPtrMetaId(int id) { return _PythonQtObjectPtr_metaId == id; } - - //! add the wrapper pointer (for reuse if the same obj appears while wrapper still exists) - void addWrapperPointer(void* obj, PythonQtInstanceWrapper* wrapper); - //! remove the wrapper ptr again - void removeWrapperPointer(void* obj); - - //! called by destructor of shells to allow invalidation of the Python wrapper - void shellClassDeleted(void* shellClass); - - //! try to unwrap the given object to a C++ pointer using the foreign wrapper factories - void* unwrapForeignWrapper(const QByteArray& classname, PyObject* obj); - - //! add parent class relation - bool addParentClass(const char* typeName, const char* parentTypeName, int upcastingOffset); - - //! add a handler for polymorphic downcasting - void addPolymorphicHandler(const char* typeName, PythonQtPolymorphicHandlerCB* cb); - - //! lookup existing classinfo and return new if not yet present - PythonQtClassInfo* lookupClassInfoAndCreateIfNotPresent(const char* typeName); - - //! called when a signal emitting QObject is destroyed to remove the signal handler from the hash map - void removeSignalEmitter(QObject* obj); - - //! wrap the given QObject into a Python object (or return existing wrapper!) - PyObject* wrapQObject(QObject* obj); - - //! wrap the given ptr into a Python object (or return existing wrapper!) if there is a known QObject of that name or a known wrapper in the factory - PyObject* wrapPtr(void* ptr, const QByteArray& name); - - //! create a read-only buffer object from the given memory - static PyObject* wrapMemoryAsBuffer(const void* data, Py_ssize_t size); - - //! create a read-write buffer object from the given memory - static PyObject* wrapMemoryAsBuffer(void* data, Py_ssize_t size); - - //! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well) - /* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject, - you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */ - void registerClass(const QMetaObject* metaobject, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL, PyObject* module = NULL, int typeSlots = 0); - - //! add a wrapper object for the given QMetaType typeName, also does an addClassDecorators() to add constructors for variants - //! (ownership of wrapper is passed to PythonQt) - /*! Make sure that you have done a qRegisterMetaType first, if typeName is a user type! - - This will add a wrapper object that is used to make calls to the given classname \c typeName. - All slots that take a pointer to typeName as the first argument will be callable from Python on - a variant object that contains such a type. - */ - void registerCPPClass(const char* typeName, const char* parentTypeName = NULL, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL, PyObject* module = NULL, int typeSlots = 0); - - //! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes - //! and it will register the classes when it first sees a pointer to such a derived class - void registerQObjectClassNames(const QStringList& names); - - //! add a decorator object - void addDecorators(QObject* o, int decoTypes); - - //! helper method that creates a PythonQtClassWrapper object (returns a new reference) - PythonQtClassWrapper* createNewPythonQtClassWrapper(PythonQtClassInfo* info, PyObject* module, const QByteArray& pythonClassName); - - //! create a new instance of the given enum type with given value (returns a new reference) - static PyObject* createEnumValueInstance(PyObject* enumType, unsigned int enumValue); - - //! helper that creates a new int derived class that represents the enum of the given name (returns a new reference) - static PyObject* createNewPythonQtEnumWrapper(const char* enumName, PyObject* parentObject); - - //! helper method that creates a PythonQtInstanceWrapper object and registers it in the object map - PythonQtInstanceWrapper* createNewPythonQtInstanceWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr = NULL); - - //! get the class info for a meta object (if available) - PythonQtClassInfo* getClassInfo(const QMetaObject* meta) { return _knownClassInfos.value(meta->className()); } - - //! get the class info for a meta object (if available) - PythonQtClassInfo* getClassInfo(const QByteArray& className) { return _knownClassInfos.value(className); } - - //! creates the new module from the given pycode - PythonQtObjectPtr createModule(const QString& name, PyObject* pycode); - - //! get the current class info (for the next PythonQtClassWrapper that is created) and reset it to NULL again - PythonQtClassInfo* currentClassInfoForClassWrapperCreation(); - - //! the dummy tuple (which is empty and may be used to detected that a wrapper is called from internal wrapper creation - static PyObject* dummyTuple(); - - //! called by virtual overloads when a python return value can not be converted to the required Qt type - void handleVirtualOverloadReturnError(const char* signature, const PythonQtMethodInfo* methodInfo, PyObject* result); - - //! get access to the PythonQt module - PythonQtObjectPtr pythonQtModule() const { return _pythonQtModule; } - - //! returns the profiling callback, which may be NULL - PythonQt::ProfilingCB* profilingCB() const { return _profilingCB; } - - //! determines the signature of the given callable object (similar as pydoc) - QString getSignature(PyObject* object); - - //! returns true if the object is a method descriptor (same as inspect.ismethoddescriptor() in inspect.py) - bool isMethodDescriptor(PyObject* object) const; - -private: - //! Setup the shared library suffixes by getting them from the "imp" module. - void setupSharedLibrarySuffixes(); - - //! create a new pythonqt class wrapper and place it in the pythonqt module - void createPythonQtClassWrapper(PythonQtClassInfo* info, const char* package, PyObject* module = NULL); - - //! get/create new package module (the returned object is a borrowed reference) - PyObject* packageByName(const char* name); - - //! get the wrapper for a given pointer (and remove a wrapper of an already destroyed qobject) - PythonQtInstanceWrapper* findWrapperAndRemoveUnused(void* obj); - - //! stores pointer to PyObject mapping of wrapped QObjects AND C++ objects - QHash _wrappedObjects; - - //! stores the meta info of known Qt classes - QHash _knownClassInfos; - - //! names of qobject derived classes that can be casted to qobject savely - QHash _knownQObjectClassNames; - - //! stores signal receivers for QObjects - QHash _signalReceivers; - - //! the PythonQt python module - PythonQtObjectPtr _pythonQtModule; - - //! the name of the PythonQt python module - QByteArray _pythonQtModuleName; - - //! the importer interface (if set) - PythonQtImportFileInterface* _importInterface; - - //! the default importer - PythonQtQFileImporter* _defaultImporter; - - PythonQtQObjectNoLongerWrappedCB* _noLongerWrappedCB; - PythonQtQObjectWrappedCB* _wrappedCB; - - QStringList _importIgnorePaths; - QStringList _sharedLibrarySuffixes; - - //! the cpp object wrapper factories - QList _cppWrapperFactories; - - QList _foreignWrapperFactories; - - QHash _packages; - - PythonQtClassInfo* _currentClassInfoForClassWrapperCreation; - - PythonQt::ProfilingCB* _profilingCB; - - int _initFlags; - int _PythonQtObjectPtr_metaId; - - bool _hadError; - bool _systemExitExceptionHandlerEnabled; - - friend class PythonQt; -}; - -#endif diff --git a/pythonqt/include/PythonQtBoolResult.h b/pythonqt/include/PythonQtBoolResult.h deleted file mode 100644 index 11faad33..00000000 --- a/pythonqt/include/PythonQtBoolResult.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _PYTHONQTBOOLRESULT_H -#define _PYTHONQTBOOLRESULT_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtBoolResultt.h -// \author Florian Link -// \date 2014-09 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" -#include "structmember.h" - -extern PYTHONQT_EXPORT PyTypeObject PythonQtBoolResult_Type; - -#define PythonQtBoolResult_Check(op) (Py_TYPE(op) == &PythonQtBoolResult_Type) - -//! defines a python object that stores a single bool -typedef struct { - PyObject_HEAD - bool _value; -} PythonQtBoolResultObject; - - -#endif diff --git a/pythonqt/include/PythonQtClassInfo.h b/pythonqt/include/PythonQtClassInfo.h deleted file mode 100644 index 7222d024..00000000 --- a/pythonqt/include/PythonQtClassInfo.h +++ /dev/null @@ -1,268 +0,0 @@ -#ifndef _PYTHONQTCLASSINFO_H -#define _PYTHONQTCLASSINFO_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -#include -#include -#include -#include -#include -#include "PythonQt.h" - -class PythonQtSlotInfo; - -struct PythonQtMemberInfo { - enum Type { - Invalid, Slot, Signal, EnumValue, EnumWrapper, Property, NestedClass, NotFound - }; - - PythonQtMemberInfo():_type(Invalid),_slot(NULL),_pythonType(NULL),_enumValue(0) { } - - PythonQtMemberInfo(PythonQtSlotInfo* info); - - PythonQtMemberInfo(const PythonQtObjectPtr& enumValue); - - PythonQtMemberInfo(const QMetaProperty& prop); - - Type _type; - - // TODO: this could be a union... - PythonQtSlotInfo* _slot; - PyObject* _pythonType; - PythonQtObjectPtr _enumValue; - QMetaProperty _property; -}; - -//! a class that stores all required information about a Qt object (and an optional associated C++ class name) -/*! for fast lookup of slots when calling the object from Python -*/ -class PYTHONQT_EXPORT PythonQtClassInfo { - -public: - PythonQtClassInfo(); - ~PythonQtClassInfo(); - - //! store information about parent classes - struct ParentClassInfo { - ParentClassInfo(PythonQtClassInfo* parent, int upcastingOffset=0):_parent(parent),_upcastingOffset(upcastingOffset) - {}; - - PythonQtClassInfo* _parent; - int _upcastingOffset; - }; - - - //! setup as a QObject, taking the meta object as meta information about the QObject - void setupQObject(const QMetaObject* meta); - - //! setup as a CPP (non-QObject), taking the classname - void setupCPPObject(const QByteArray& classname); - - //! set the type capabilities - void setTypeSlots(int typeSlots) { _typeSlots = typeSlots; } - //! get the type capabilities - int typeSlots() const { return _typeSlots; } - - //! get the Python method definition for a given slot name (without return type and signature) - PythonQtMemberInfo member(const char* member); - - //! get access to the constructor slot (which may be overloaded if there are multiple constructors) - PythonQtSlotInfo* constructors(); - - //! get access to the destructor slot - PythonQtSlotInfo* destructor(); - - //! add a constructor, ownership is passed to classinfo - void addConstructor(PythonQtSlotInfo* info); - - //! set a destructor, ownership is passed to classinfo - void setDestructor(PythonQtSlotInfo* info); - - //! add a decorator slot, ownership is passed to classinfo - void addDecoratorSlot(PythonQtSlotInfo* info); - - //! add a nested class, so that it can be shown as outer class member - void addNestedClass(PythonQtClassInfo* info); - - //! get the classname (either of the QObject or of the wrapped CPP object) - const QByteArray& className() const; - - //! get the unscoped classname (without ParentClass::) for nested classes - QByteArray unscopedClassName() const; - - //! returns if the QObject - bool isQObject() { return _isQObject; } - - //! returns if the class is a CPP wrapper - bool isCPPWrapper() { return !_isQObject; } - - //! get the meta object - const QMetaObject* metaObject() { return _meta; } - - //! set the meta object, this will reset the caching - void setMetaObject(const QMetaObject* meta); - - //! returns if this class inherits from the given classname - bool inherits(const char* classname); - - //! returns if this class inherits from the given classinfo - bool inherits(PythonQtClassInfo* info); - - //! casts the given \c ptr to an object of type \c classname, returns the new pointer - //! which might be different to \c ptr due to C++ multiple inheritance - //! (if the cast is not possible or if ptr is NULL, NULL is returned) - void* castTo(void* ptr, const char* classname); - - //! get help string for the metaobject - QString help(); - - //! get list of all properties (on QObjects only, otherwise the list is empty) - QStringList propertyList(); - - //! get list of all members (excluding properties, which can be listed with propertyList()) - QStringList memberList(); - - //! get the meta type id of this class (only valid for isCPPWrapper() == true) - int metaTypeId() { return _metaTypeId; } - - //! set an additional decorator provider that offers additional decorator slots for this class - void setDecoratorProvider(PythonQtQObjectCreatorFunctionCB* cb); - - //! get the decorator qobject instance - QObject* decorator(); - - //! add the parent class info of a CPP object - void addParentClass(const ParentClassInfo& info) { _parentClasses.append(info); } - - //! set the associated PythonQtClassWrapper (which handles instance creation of this type) - void setPythonQtClassWrapper(PyObject* obj) { _pythonQtClassWrapper = obj; } - - //! get the associated PythonQtClassWrapper (which handles instance creation of this type) - PyObject* pythonQtClassWrapper() { return _pythonQtClassWrapper; } - - //! set the shell set instance wrapper cb - void setShellSetInstanceWrapperCB(PythonQtShellSetInstanceWrapperCB* cb) { - _shellSetInstanceWrapperCB = cb; - } - - //! get the shell set instance wrapper cb - PythonQtShellSetInstanceWrapperCB* shellSetInstanceWrapperCB() { - return _shellSetInstanceWrapperCB; - } - - //! add a handler for polymorphic downcasting - void addPolymorphicHandler(PythonQtPolymorphicHandlerCB* cb) { _polymorphicHandlers.append(cb); } - - //! cast the pointer down in the class hierarchy if a polymorphic handler allows to do that - void* castDownIfPossible(void* ptr, PythonQtClassInfo** resultClassInfo); - - //! returns if the localScope has an enum of that type name or if the enum contains a :: scope, if that class contails the enum - static PyObject* findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool* isLocalEnum = NULL); - - //! clear all members that where cached as "NotFound" - void clearNotFoundCachedMembers(); - - //! get nested classes - const QList& nestedClasses() { return _nestedClasses; } - - //! Create a copy of the given C++ object (which is known to be of a derived class), wrapped by Python and owned by PythonQt. - //! This will downcast if possible and return a copy of the down casted object. - //! This either requires a copy constructor on the class or it needs to be registered - //! as a meta type. - PyObject* copyObject(void* cppObject); - - //! Get the copy constructor for this class - PythonQtSlotInfo* getCopyConstructor(); - -private: - void createEnumWrappers(); - void createEnumWrappers(const QMetaObject* meta); - PyObject* findEnumWrapper(const char* name); - - //! clear all cached members - void clearCachedMembers(); - - void* recursiveCastDownIfPossible(void* ptr, const char** resultClassName); - - PythonQtSlotInfo* findDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash& memberCache, int upcastingOffset); - void listDecoratorSlotsFromDecoratorProvider(QStringList& list, bool metaOnly); - PythonQtSlotInfo* recursiveFindDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash& memberCache, int upcastingOffset); - - void recursiveCollectClassInfos(QList& classInfoObjects); - void recursiveCollectDecoratorObjects(QList& decoratorObjects); - - bool lookForPropertyAndCache(const char* memberName); - bool lookForMethodAndCache(const char* memberName); - bool lookForEnumAndCache(const QMetaObject* m, const char* memberName); - - PythonQtSlotInfo* findDecoratorSlots(const char* memberName, PythonQtSlotInfo* tail, bool &found, QHash& memberCache, int upcastingOffset); - int findCharOffset(const char* sigStart, char someChar); - - QHash _cachedMembers; - - PythonQtSlotInfo* _constructors; - PythonQtSlotInfo* _destructor; - QList _decoratorSlots; - - QList _enumWrappers; - - const QMetaObject* _meta; - - QByteArray _wrappedClassName; - QList _parentClasses; - - QList _polymorphicHandlers; - - QList _nestedClasses; - - QObject* _decoratorProvider; - PythonQtQObjectCreatorFunctionCB* _decoratorProviderCB; - - PyObject* _pythonQtClassWrapper; - - PythonQtShellSetInstanceWrapperCB* _shellSetInstanceWrapperCB; - - int _metaTypeId; - int _typeSlots; - - bool _isQObject; - bool _enumsCreated; - bool _searchPolymorphicHandlerOnParent; - -}; - -//--------------------------------------------------------------- - - -#endif diff --git a/pythonqt/include/PythonQtClassWrapper.h b/pythonqt/include/PythonQtClassWrapper.h deleted file mode 100644 index 5b7b3002..00000000 --- a/pythonqt/include/PythonQtClassWrapper.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef _PYTHONQTCLASSWRAPPER_H -#define _PYTHONQTCLASSWRAPPER_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtClassWrapper.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" - -#include "structmember.h" -#include "methodobject.h" -#include "compile.h" -#include "eval.h" -#include - -class PythonQtClassInfo; - -//! the type of the PythonQt class wrapper objects -extern PYTHONQT_EXPORT PyTypeObject PythonQtClassWrapper_Type; - -//--------------------------------------------------------------- -//! a Python wrapper object for PythonQt wrapped classes -//! which inherits from the Python type object to allow -//! deriving of wrapped CPP classes from Python. -typedef struct { - PyHeapTypeObject _base; - - //! the additional class information that PythonQt stores for the CPP class - PythonQtClassInfo* _classInfo; - - //! get the class info - PythonQtClassInfo* classInfo() { return _classInfo; } - -} PythonQtClassWrapper; - -//--------------------------------------------------------------- - -#endif diff --git a/pythonqt/include/PythonQtConversion.h b/pythonqt/include/PythonQtConversion.h deleted file mode 100644 index fd89fbe9..00000000 --- a/pythonqt/include/PythonQtConversion.h +++ /dev/null @@ -1,500 +0,0 @@ -#ifndef _PYTHONQTCONVERSION_H -#define _PYTHONQTCONVERSION_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtConversion.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQt.h" -#include "PythonQtMisc.h" -#include "PythonQtClassInfo.h" -#include "PythonQtMethodInfo.h" - -#include -#include -#include - -typedef PyObject* PythonQtConvertMetaTypeToPythonCB(const void* inObject, int metaTypeId); -typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject* inObject, void* outObject, int metaTypeId, bool strict); - -#define PythonQtRegisterListTemplateConverter(type, innertype) \ -{ int typeId = qRegisterMetaType >(#type"<"#innertype">"); \ -PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfValueType, innertype>); \ -PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfValueTypeToPythonList, innertype>); \ -} - -#define PythonQtRegisterListTemplateConverterForKnownClass(type, innertype) \ -{ int typeId = qRegisterMetaType >(#type"<"#innertype">"); \ - PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfKnownClass, innertype>); \ - PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfKnownClassToPythonList, innertype>); \ -} - -#define PythonQtRegisterQPairConverter(type1, type2) \ -{ int typeId = qRegisterMetaType >("QPair<"#type1","#type2">"); \ - PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToPair); \ - PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertPairToPython); \ -} - -#define PythonQtRegisterIntegerMapConverter(type, innertype) \ -{ int typeId = qRegisterMetaType >(#type""); \ - PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToIntegerMap, innertype>); \ - PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertIntegerMapToPython, innertype>); \ -} - -#define PythonQtRegisterListTemplateQPairConverter(listtype, type1, type2) \ -{ \ - qRegisterMetaType >("QPair<"#type1","#type2">"); \ - int typeId = qRegisterMetaType > >(#listtype">"); \ - PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfPair >, type1, type2>); \ - PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfPairToPythonList >, type1, type2>); \ -} - -#define PythonQtRegisterToolClassesTemplateConverter(innertype) \ - PythonQtRegisterListTemplateConverter(QList, innertype); \ - PythonQtRegisterListTemplateConverter(QVector, innertype); \ - PythonQtRegisterListTemplateConverter(std::vector, innertype); - -#define PythonQtRegisterToolClassesTemplateConverterForKnownClass(innertype) \ - PythonQtRegisterListTemplateConverterForKnownClass(QList, innertype); \ - PythonQtRegisterListTemplateConverterForKnownClass(QVector, innertype); \ - PythonQtRegisterListTemplateConverterForKnownClass(std::vector, innertype); - -//! a static class that offers methods for type conversion -class PYTHONQT_EXPORT PythonQtConv { - -public: - - //! get a ref counted True or False Python object - static PyObject* GetPyBool(bool val); - - //! converts the Qt parameter given in \c data, interpreting it as a \c info parameter, into a Python object, - static PyObject* ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo& info, const void* data); - - //! convert python object to Qt (according to the given parameter) and if the conversion should be strict (classInfo is currently not used anymore) - static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, PythonQtClassInfo* classInfo, void* alreadyAllocatedCPPObject = NULL); - - //! creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] of qt_metacall - static void* CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo& info); - - //! converts QString to Python string (unicode!) - static PyObject* QStringToPyObject(const QString& str); - - //! converts QStringList to Python tuple - static PyObject* QStringListToPyObject(const QStringList& list); - - //! converts QStringList to Python list - static PyObject* QStringListToPyList(const QStringList& list); - - //! get string representation of py object - static QString PyObjGetRepresentation(PyObject* val); - - //! get string value from py object - static QString PyObjGetString(PyObject* val) { bool ok; QString s = PyObjGetString(val, false, ok); return s; } - //! get string value from py object - static QString PyObjGetString(PyObject* val, bool strict, bool &ok); - //! get bytes from py object - static QByteArray PyObjGetBytes(PyObject* val, bool strict, bool &ok); - //! get int from py object - static int PyObjGetInt(PyObject* val, bool strict, bool &ok); - //! get int64 from py object - static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok); - //! get int64 from py object - static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok); - //! get double from py object - static double PyObjGetDouble(PyObject* val, bool strict, bool &ok); - //! get bool from py object - static bool PyObjGetBool(PyObject* val, bool strict, bool &ok); - - //! create a string list from python sequence - static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok); - - //! convert python object to qvariant, if type is given it will try to create a qvariant of that type, otherwise - //! it will guess from the python type - static QVariant PyObjToQVariant(PyObject* val, int type = -1); - - //! convert QVariant from PyObject - static PyObject* QVariantToPyObject(const QVariant& v); - - static PyObject* QVariantHashToPyObject(const QVariantHash& m); - static PyObject* QVariantMapToPyObject(const QVariantMap& m); - static PyObject* QVariantListToPyObject(const QVariantList& l); - - //! get human readable string from CPP object (when the metatype is known) - static QString CPPObjectToString(int type, const void* data); - - //! register a converter callback from python to cpp for given metatype - static void registerPythonToMetaTypeConverter(int metaTypeId, PythonQtConvertPythonToMetaTypeCB* cb) { _pythonToMetaTypeConverters.insert(metaTypeId, cb); } - - //! register a converter callback from cpp to python for given metatype - static void registerMetaTypeToPythonConverter(int metaTypeId, PythonQtConvertMetaTypeToPythonCB* cb) { _metaTypeToPythonConverters.insert(metaTypeId, cb); } - - //! converts the Qt parameter given in \c data, interpreting it as a \c type registered qvariant/meta type, into a Python object, - static PyObject* ConvertQtValueToPythonInternal(int type, const void* data); - - //! creates a copy of given object, using the QMetaType - static PyObject* createCopyFromMetaType( int type, const void* object ); - - //! cast wrapper to given className if possible - static void* castWrapperTo(PythonQtInstanceWrapper* wrapper, const QByteArray& className, bool& ok); - -public: - - static PythonQtValueStorage global_valueStorage; - static PythonQtValueStorage global_ptrStorage; - static PythonQtValueStorageWithCleanup global_variantStorage; - -protected: - static QHash _metaTypeToPythonConverters; - static QHash _pythonToMetaTypeConverters; - - //! handle automatic conversion of some special types (QColor, QBrush, ...) - static void* handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject); - - //! converts the list of pointers of given type to Python - static PyObject* ConvertQListOfPointerTypeToPythonList(QList* list, const QByteArray& type); - //! tries to convert the python object to a QList of pointers to \c type objects, returns true on success - static bool ConvertPythonListToQListOfPointerType(PyObject* obj, QList* list, const QByteArray& type, bool strict); - - //! helper template method for conversion from Python to QVariantMap/Hash - template - static void pythonToMapVariant(PyObject* val, QVariant& result); - //! helper template function for QVariantMapToPyObject/QVariantHashToPyObject - template - static PyObject* mapToPython (const Map& m); -}; - -template -PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList* */ inList, int metaTypeId) -{ - ListType* list = (ListType*)inList; - static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId))); - if (innerType == QVariant::Invalid) { - std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - PyObject* result = PyTuple_New(list->size()); - int i = 0; - Q_FOREACH (const T& value, *list) { - PyTuple_SET_ITEM(result, i, PythonQtConv::ConvertQtValueToPythonInternal(innerType, &value)); - i++; - } - return result; -} - -template -bool PythonQtConvertPythonListToListOfValueType(PyObject* obj, void* /*QList* */ outList, int metaTypeId, bool /*strict*/) -{ - ListType* list = (ListType*)outList; - static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId))); - if (innerType == QVariant::Invalid) { - std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - bool result = false; - if (PySequence_Check(obj)) { - int count = PySequence_Size(obj); - if (count >= 0) { - result = true; - PyObject* value; - for (int i = 0;ipush_back(qvariant_cast(v)); - } else { - result = false; - break; - } - } - } - } - return result; -} - -//-------------------------------------------------------------------------------------------------------------------- - -template -PyObject* PythonQtConvertListOfKnownClassToPythonList(const void* /*QList* */ inList, int metaTypeId) -{ - ListType* list = (ListType*)inList; - static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)))); - if (innerType == NULL) { - std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type " << innerType->className().constData() << std::endl; - } - PyObject* result = PyTuple_New(list->size()); - int i = 0; - Q_FOREACH(const T& value, *list) { - T* newObject = new T(value); - PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv()->wrapPtr(newObject, innerType->className()); - wrap->_ownedByPythonQt = true; - PyTuple_SET_ITEM(result, i, (PyObject*)wrap); - i++; - } - return result; -} - -template -bool PythonQtConvertPythonListToListOfKnownClass(PyObject* obj, void* /*QList* */ outList, int metaTypeId, bool /*strict*/) -{ - ListType* list = (ListType*)outList; - static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)))); - if (innerType == NULL) { - std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type " << innerType->className().constData() << std::endl; - } - bool result = false; - if (PySequence_Check(obj)) { - int count = PySequence_Size(obj); - if (count >= 0) { - result = true; - PyObject* value; - for (int i = 0; i < count; i++) { - value = PySequence_GetItem(obj, i); - if (PyObject_TypeCheck(value, &PythonQtInstanceWrapper_Type)) { - PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)value; - bool ok; - T* object = (T*)PythonQtConv::castWrapperTo(wrap, innerType->className(), ok); - if (ok) { - list->push_back(*object); - } else { - result = false; - break; - } - } else { - result = false; - break; - } - } - } - } - return result; -} - -//-------------------------------------------------------------------------------------------------------------------- - -template -PyObject* PythonQtConvertPairToPython(const void* /*QPair* */ inPair, int metaTypeId) -{ - QPair* pair = (QPair*)inPair; - static int innerType1 = -1; - static int innerType2 = -1; - if (innerType1==-1) { - QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId))); - QList names = innerTypes.split(','); - innerType1 = QMetaType::type(names.at(0).trimmed()); - innerType2 = QMetaType::type(names.at(1).trimmed()); - } - if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) { - std::cerr << "PythonQtConvertPairToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - PyObject* result = PyTuple_New(2); - PyTuple_SET_ITEM(result, 0, PythonQtConv::ConvertQtValueToPythonInternal(innerType1, &pair->first)); - PyTuple_SET_ITEM(result, 1, PythonQtConv::ConvertQtValueToPythonInternal(innerType2, &pair->second)); - return result; -} - -template -bool PythonQtConvertPythonToPair(PyObject* obj, void* /*QPair* */ outPair, int metaTypeId, bool /*strict*/) -{ - QPair* pair = (QPair*)outPair; - static int innerType1 = -1; - static int innerType2 = -1; - if (innerType1 == -1) { - QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId))); - QList names = innerTypes.split(','); - innerType1 = QMetaType::type(names.at(0).trimmed()); - innerType2 = QMetaType::type(names.at(1).trimmed()); - } - if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) { - std::cerr << "PythonQtConvertPythonToPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - bool result = false; - if (PySequence_Check(obj)) { - int count = PySequence_Size(obj); - if (count == 2) { - result = true; - PyObject* value; - - value = PySequence_GetItem(obj, 0); - // this is quite some overhead, but it avoids having another large switch... - QVariant v = PythonQtConv::PyObjToQVariant(value, innerType1); - if (v.isValid()) { - pair->first = qvariant_cast(v); - } else { - return false; - } - - value = PySequence_GetItem(obj, 1); - // this is quite some overhead, but it avoids having another large switch... - v = PythonQtConv::PyObjToQVariant(value, innerType2); - if (v.isValid()) { - pair->second = qvariant_cast(v); - } else { - return false; - } - } - } - return result; -} - -//-------------------------------------------------------------------------------------------------------------------- - -template -PyObject* PythonQtConvertListOfPairToPythonList(const void* /*QList >* */ inList, int metaTypeId) -{ - ListType* list = (ListType*)inList; - static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId))); - if (innerType == QVariant::Invalid) { - std::cerr << "PythonQtConvertListOfPairToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - PyObject* result = PyTuple_New(list->size()); - int i = 0; - typedef const QPair Pair; - Q_FOREACH(Pair& value, *list) { - PyObject* object = PythonQtConvertPairToPython(&value, innerType); - PyTuple_SET_ITEM(result, i, object); - i++; - } - return result; -} - -template -bool PythonQtConvertPythonListToListOfPair(PyObject* obj, void* /*QList >* */ outList, int metaTypeId, bool /*strict*/) -{ - ListType* list = (ListType*)outList; - static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId))); - if (innerType == QVariant::Invalid) { - std::cerr << "PythonQtConvertPythonListToListOfPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - bool result = false; - if (PySequence_Check(obj)) { - int count = PySequence_Size(obj); - if (count >= 0) { - result = true; - PyObject* value; - for (int i = 0; i < count; i++) { - QPair pair; - value = PySequence_GetItem(obj, i); - if (PythonQtConvertPythonToPair(value, &pair, innerType, false)) { - list->push_back(pair); - } else { - result = false; - break; - } - } - } - } - return result; -} - -//-------------------------------------------------------------------------------------------------------------------- - -template -PyObject* PythonQtConvertIntegerMapToPython(const void* /*QMap* */ inMap, int metaTypeId) -{ - MapType* map = (MapType*)inMap; - static int innerType = -1; - if (innerType == -1) { - QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId))); - QList names = innerTypes.split(','); - innerType = QMetaType::type(names.at(1).trimmed()); - } - if (innerType == QVariant::Invalid) { - std::cerr << "PythonQtConvertIntegerMapToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - - PyObject* result = PyDict_New(); - typename MapType::const_iterator t = map->constBegin(); - PyObject* key; - PyObject* val; - for (; t != map->constEnd(); t++) { - key = PyInt_FromLong(t.key()); - val = PythonQtConv::ConvertQtValueToPythonInternal(innerType, &t.value()); - PyDict_SetItem(result, key, val); - Py_DECREF(key); - Py_DECREF(val); - } - return result; -} - -template -bool PythonQtConvertPythonToIntegerMap(PyObject* val, void* /*QMap* */ outMap, int metaTypeId, bool /*strict*/) -{ - MapType* map = (MapType*)outMap; - static int innerType = -1; - if (innerType == -1) { - QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId))); - QList names = innerTypes.split(','); - innerType = QMetaType::type(names.at(1).trimmed()); - } - if (innerType == QVariant::Invalid) { - std::cerr << "PythonQtConvertPythonToIntegerMap: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; - } - bool result = false; - if (PyMapping_Check(val)) { - result = true; - PyObject* items = PyMapping_Items(val); - if (items) { - int count = PyList_Size(items); - PyObject* value; - PyObject* key; - PyObject* tuple; - for (int i = 0; i < count; i++) { - tuple = PyList_GetItem(items, i); - key = PyTuple_GetItem(tuple, 0); - value = PyTuple_GetItem(tuple, 1); - - bool ok; - int intKey = PythonQtConv::PyObjGetInt(key, false, ok); - // this is quite some overhead, but it avoids having another large switch... - QVariant v = PythonQtConv::PyObjToQVariant(value, innerType); - if (v.isValid() && ok) { - map->insert(intKey, qvariant_cast(v)); - } else { - result = false; - break; - } - } - Py_DECREF(items); - } - } - return result; -} - - -#endif diff --git a/pythonqt/include/PythonQtCppWrapperFactory.h b/pythonqt/include/PythonQtCppWrapperFactory.h deleted file mode 100644 index e4bf2012..00000000 --- a/pythonqt/include/PythonQtCppWrapperFactory.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _PYTHONQTCPPWRAPPERFACTORY_H -#define _PYTHONQTCPPWRAPPERFACTORY_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtCppWrapperFactory.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-06 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" -#include -#include - -//! Factory interface for C++ classes that can be wrapped by QObject objects -/*! To create your own factory, derive PythonQtCppWrapperFactory and implement -the create() method. -A factory can be added to PythonQt by PythonQt::addCppWrapperFactory(). -*/ -class PYTHONQT_EXPORT PythonQtCppWrapperFactory -{ -public: - PythonQtCppWrapperFactory() {}; - virtual ~PythonQtCppWrapperFactory() {}; - - //! create a wrapper for the given object - virtual QObject* create(const QByteArray& classname, void *ptr) = 0; - -}; - -//! Factory interface for C++ classes that can be mapped directly from/to -//! Python with other means than PythonQt/QObjects. -class PYTHONQT_EXPORT PythonQtForeignWrapperFactory -{ -public: - PythonQtForeignWrapperFactory() {}; - virtual ~PythonQtForeignWrapperFactory() {}; - - //! create a Python object (with new reference count), wrapping the given \p ptr as class of type \p classname - //! Return NULL (and not Py_None) if the object could not be wrapped. - virtual PyObject* wrap(const QByteArray& classname, void *ptr) = 0; - - //! unwrap the given object to a C++ object of type \p classname if possible - //! Return NULL otherwise. - virtual void* unwrap(const QByteArray& classname, PyObject* object) = 0; - -}; - -#endif - diff --git a/pythonqt/include/PythonQtDoc.h b/pythonqt/include/PythonQtDoc.h deleted file mode 100644 index 15005266..00000000 --- a/pythonqt/include/PythonQtDoc.h +++ /dev/null @@ -1,546 +0,0 @@ -#ifndef _PYTHONQTDOC_H -#define _PYTHONQTDOC_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtDoc.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-10 -*/ -//---------------------------------------------------------------------------------- - -/*! - \if USE_GLOBAL_DOXYGEN_DOC - \page PythonQtPage PythonQt Overview - \else - \mainpage notitle - \endif - - \image html PythonQt.jpg - - \section Introduction - - \b PythonQt is a dynamic -Python binding for the -Qt framework. - It offers an easy way to embed the Python scripting language into - your C++ Qt applications. - - The focus of PythonQt is on embedding Python into an existing C++ application, not on writing the whole - application completely in Python. If you want to write your whole application in Python, - you should use PyQt or PySide instead. - - If you are looking for a simple way to embed Python objects into your C++/Qt Application - and to script parts of your application via Python, PythonQt is the way to go! - - PythonQt is a stable library that was developed to make the - Image Processing and Visualization platform MeVisLab - scriptable from Python. - - - \ref Features - - \ref Download - - \ref License - - \ref Developer - - \ref Building - - \ref Examples - - \page Features Features - - \section Builtin Built-in Features - - The following are the built-in features of the PythonQt library: - - - Access all \b slots, \b properties, children and registered enums of any QObject derived class from Python - - Connecting Qt Signals to Python functions (both from within Python and from C++) - - Easy wrapping of Python objects from C++ with smart, reference-counting PythonQtObjectPtr. - - Convenient conversions to/from QVariant for PythonQtObjectPtr. - - Wrapping of C++ objects (which are not derived from QObject) via PythonQtCppWrapperFactory - - Extending C++ and QObject derived classes with additional slots, static methods and constructors (see Decorators) - - StdOut/Err redirection to Qt signals instead of cout - - Interface for creating your own \c import replacement, so that Python scripts can be e.g. signed/verified before they are executed (PythonQtImportFileInterface) - - Mapping of plain-old-datatypes and ALL QVariant types to and from Python - - Support for wrapping of user QVariant types which are registerd via QMetaType - - Support for Qt namespace (with all enumerators) - - All PythonQt wrapped objects support the dir() statement, so that you can see easily which attributes a QObject, CPP object or QVariant has - - No preprocessing/wrapping tool needs to be started, PythonQt can script any QObject without prior knowledge about it (except for the MetaObject information from the \b moc) - - Multiple inheritance for C++ objects (e.g. a QWidget is derived from QObject and QPaintDevice, PythonQt will automatically cast a QWidget to a QPaintDevice when needed) - - Polymorphic downcasting (if e.g. PythonQt sees a QEvent, it can downcast it depending on the type(), so the Python e.g. sees a QPaintEvent instead of a plain QEvent) - - Deriving C++ objects from Python and overwriting virtual method with a Python implementation (requires usage of wrapper generator or manual work!) - - Extensible handler for Python/C++ conversion of complex types, e.g. mapping of QVector to/from a Python array - - Setting of dynamic QObject properties via setProperty(), dynamic properties can be accessed for reading and writing like normal Python attributes (but creating a new property needs to be done with setProperty(), to distinguish from normal Python attributes) - - \section FeaturesQtAll Features with wrapper generator - - PythonQt offers the additional PythonQt_QtAll library which wraps the complete Qt API, including all C++ classes and all non-slots on QObject derived classes. - This offers the following features: - - - Complete Qt API wrapped and accessible - - The following modules are available as submodules of the PythonQt module: - - QtCore - - QtGui - - QtNetwork - - QtOpenGL - - QtSql - - QtSvg - - QtUiTools - - QtWebKit - - QtXml - - QtXmlPatterns - - (QtMultiMedia, QtScript, QtHelp, phonon, assistant, designer are currently not supported, this would require some additional effort on the code generator) - - For convenience, all classes are also available in the PythonQt.Qt module, for people who do not care in which module a class is located - - Any Qt class that has virtual methods can be easily derived from Python and the virtual methods can be reimplemented in Python - - Polymorphic downcasting on QEvent, QGraphicsItem, QStyleOption, ... - - Multiple inheritance support (e.g., QGraphicsTextItem is a QObject and a QGraphicsItem, PythonQt will handle this well) - - \section Supported Supported Versions - - PythonQt supports: - - Python 2 (>= Python 2.6) - - Python 3 (>= Python 3.3) - - Qt 4.x (Qt 4.7 and Qt 4.8 recommended) - - Qt 5.x (Tested with Qt 5.0 and 5.3) - - The Qt5 support does not yet include Qt modules that have been introduced with Qt5. The new QtWidgets module is wrapped as part of QtGui. - This allows to run scripts that were written with the Qt4 binding on a Qt5 PythonQt without porting. - - \section Comparison Comparison with PyQt/PySide - - - PythonQt is not as pythonic as PyQt/PySide in many details (e.g. buffer protocol, pickling, translation support, ...) and it is mainly thought for embedding and intercommunication between Qt/Cpp and Python - - PythonQt allows to communicate in both directions, e.g., calling a Python object from C++ AND calling a C++ method from Python, while PyQt only handles the Python->C++ direction - - PythonQt offers properties as Python attributes, while PyQt offers them as setter/getter methods (e.g. QWidget.width is a property in PythonQt and a method in PyQt) - - PythonQt currently does not support instanceof checks for Qt classes, except for the exact match and derived Python classes - - QObject.emit to emit Qt signals from Python is not yet implemented but PythonQt allows to just emit a signal by calling it like a normal slot - - PythonQt does not (yet) offer to add new signals/slots to Python/C++ objects and it does not create QMetaObjects for derived classes on the fly - - Ownership of objects is a bit different in PythonQt, currently Python classes derived from a C++ class need to be manually referenced in Python to not get deleted too early (this will be fixed in a future version) - - QStrings are always converted to unicode Python objects, QByteArray always stays a QByteArray and can be converted using QByteArray.data() - - Qt methods that take an extra "bool* ok" parameter can be called passing PythonQt.BoolResult as parameter. In PyQt, a tuple is returned instead. - - \page Download Download - - PythonQt is hosted on SourceForge. - - You can download the source code as a tarball at http://sourceforge.net/projects/pythonqt/files/. - Alternatively you can get the latest version from the svn repository. - - You can also browse the source code online via ViewVC: http://pythonqt.svn.sourceforge.net/viewvc/pythonqt/trunk/ - - \note We do not offer prebuilt binaries, since there are so many possible combinations of - platforms (Windows/Linux/MacOs), architectures (32/64 bit) and Qt / Python versions. - - \page License License - - PythonQt is distributed under the LGPL license, so it pairs well with the LGPL of the Qt 4.5 release and allows - to be used in commercial applications when following the LGPL 2.1 obligations. - - The build system of PythonQt makes use of a modified version of the LGPL'ed QtScript generator, - located in the "generator" directory. - - See http://qt.gitorious.org/qt-labs/qtscriptgenerator for details on the original project. - Thanks a lot to the QtJambi guys and the QtScript Generator project for the C++ parser and - Qt typesystem files! - - The PythonQt wrappers generated by the generator located in the "generated_cpp" directory are free to be used without any licensing restrictions. - - The generated wrappers are pre-generated and checked-in for Qt 4.7, 4.8, 5.0 and 5.3, so you only need to build and run the - generator when you want to build additional wrappers or you want to upgrade/downgrade to another Qt version. - You may use the generator to generate C++ bindings for your own C++ classes (e.g., to make them inheritable in Python), - but this is currently not documented and involves creating your own typesystem files. - - \page Developer Developer - - \section Interface Interface - - The main interface to PythonQt is the PythonQt singleton. - PythonQt needs to be initialized via PythonQt::init() once. - Afterwards you communicate with the singleton via PythonQt::self(). - PythonQt offers a complete Qt binding, which - needs to be enabled via PythonQt_QtAll::init(). - - - \section Datatype Datatype Mapping - - The following table shows the mapping between Python and Qt objects: - - - - - - - - - - - - - - - - - - - - - - - -
Qt/C++Python
boolbool
doublefloat
floatfloat
char/uchar,int/uint,short,ushort,QCharinteger
longinteger
ulong,longlong,ulonglonglong
QStringunicode string
QByteArrayQByteArray wrapper
char*str
QStringListtuple of unicode strings
QVariantListtuple of objects
QVariantMapdict of objects
QVariantdepends on type, see below
QSize, QRect and all other standard Qt QVariantsvariant wrapper that supports complete API of the respective Qt classes
OwnRegisteredMetaTypeC++ wrapper, optionally with additional information/wrapping provided by registerCPPClass()
QListconverts to a list of CPP wrappers
QVectorconverts to a list of CPP wrappers
EnumTypeEnum wrapper derived from python integer
QObject (and derived classes)QObject wrapper
C++ objectCPP wrapper, either wrapped via PythonQtCppWrapperFactory or just decorated with decorators
PyObjectPyObject
- - PyObject is passed as direct pointer, which allows to pass/return any Python object directly to/from - a Qt slot that uses PyObject* as its argument/return value. - QVariants are mapped recursively as given above, e.g. a dictionary can - contain lists of dictionaries of doubles. - All Qt QVariant types are implemented, PythonQt supports the complete Qt API for these object. - - \section QObject QObject Wrapping - - All classes derived from QObject are automatically wrapped with a python wrapper class - when they become visible to the Python interpreter. This can happen via - - the PythonQt::addObject() method - - when a Qt \b slot returns a QObject derived object to python - - when a Qt \b signal contains a QObject and is connected to a python function - - It is important that you call PythonQt::registerClass() for any QObject derived class - that may become visible to Python, except when you add it via PythonQt::addObject(). - This will register the complete parent hierachy of the registered class, so that - when you register e.g. a QPushButton, QWidget will be registered as well (and all intermediate - parents). - - From Python, you can talk to the returned QObjects in a natural way by calling - their slots and receiving the return values. You can also read/write all - properties of the objects as if they where normal python properties. - - In addition to this, the wrapped objects support - - className() - returns a string that reprents the classname of the QObject - - help() - shows all properties, slots, enums, decorator slots and constructors of the object, in a printable form - - delete() - deletes the object (use with care, especially if you passed the ownership to C++) - - connect(signal, function) - connect the signal of the given object to a python function - - connect(signal, qobject, slot) - connect the signal of the given object to a slot of another QObject - - disconnect(signal, function) - disconnect the signal of the given object from a python function - - disconnect(signal, qobject, slot) - disconnect the signal of the given object from a slot of another QObject - - children() - returns the children of the object - - setParent(QObject) - set the parent - - QObject* parent() - get the parent - - The below example shows how to connect signals in Python: - - \code - # define a signal handler function - def someFunction(flag): - print flag - - # button1 is a QPushButton that has been added to Python via addObject() - # connect the clicked signal to a python function: - button1.connect("clicked(bool)", someFunction) - - \endcode - -\section CPP CPP Wrapping - -You can create dedicated wrapper QObjects for any C++ class. This is done by deriving from PythonQtCppWrapperFactory -and adding your factory via addWrapperFactory(). -Whenever PythonQt encounters a CPP pointer (e.g. on a slot or signal) -and it does not known it as a QObject derived class, it will create a generic CPP wrapper. So even unknown C++ objects -can be passed through Python. If the wrapper factory supports the CPP class, a QObject wrapper will be created for each -instance that enters Python. An alternative to a complete wrapper via the wrapper factory are decorators, see \ref Decorators - -\section MetaObject Meta Object/Class access - -For each known C++ class, PythonQt provides a Python class. These classes are visible -inside of the "PythonQt" python module or in subpackages if a package is given when the class is registered. - -A Meta class supports: - -- access to all declared enum values -- constructors -- static methods -- unbound non-static methods -- help() and className() - -From within Python, you can import the module "PythonQt" to access these classes and the Qt namespace. - -\code -from PythonQt import QtCore - -# namespace access: -print QtCore.Qt.AlignLeft - -# constructors -a = QtCore.QSize(12,13) -b = QtCore.QFont() - -# static method -QtCore.QDate.currentDate() - -# enum value -QtCore.QFont.UltraCondensed - -\endcode - -\section Decorators Decorator slots - -PythonQt introduces a new generic approach to extend any wrapped QObject or CPP object with - -- constructors -- destructors (for CPP objects) -- additional slots -- static slots (callable on both the Meta object and the instances) - -The idea behind decorators is that we wanted to make it as easy as possible to extend -wrapped objects. Since we already have an implementation for invoking any Qt Slot from -Python, it looked promising to use this approach for the extension of wrapped objects as well. -This avoids that the PythonQt user needs to care about how Python arguments are mapped from/to -Qt when he wants to create static methods, constructors and additional member functions. - -The basic idea about decorators is to create a QObject derived class that implements slots -which take one of the above roles (e.g. constructor, destructor etc.) via a naming convention. -These slots are then assigned to other classes via the naming convention. - -- SomeClassName* new_SomeClassName(...) - defines a constructor for "SomeClassName" that returns a new object of type SomeClassName (where SomeClassName can be any CPP class, not just QObject classes) -- void delete_SomeClassName(SomeClassName* o) - defines a destructor, which should delete the passed in object o -- anything static_SomeClassName_someMethodName(...) - defines a static method that is callable on instances and the meta class -- anything someMethodName(SomeClassName* o, ...) - defines a slot that will be available on SomeClassName instances (and derived instances). When such a slot is called the first argument is the pointer to the instance and the rest of the arguments can be used to make a call on the instance. - -The below example shows all kinds of decorators in action: - -\code - -// an example CPP object -class YourCPPObject { -public: - YourCPPObject(int arg1, float arg2) { a = arg1; b = arg2; } - - float doSomething(int arg1) { return arg1*a*b; }; - - private: - - int a; - float b; -}; - -// an example decorator -class ExampleDecorator : public QObject -{ - Q_OBJECT - -public slots: - // add a constructor to QSize that takes a QPoint - QSize* new_QSize(const QPoint& p) { return new QSize(p.x(), p.y()); } - - // add a constructor for QPushButton that takes a text and a parent widget - QPushButton* new_QPushButton(const QString& text, QWidget* parent=NULL) { return new QPushButton(text, parent); } - - // add a constructor for a CPP object - YourCPPObject* new_YourCPPObject(int arg1, float arg2) { return new YourCPPObject(arg1, arg2); } - - // add a destructor for a CPP object - void delete_YourCPPObject(YourCPPObject* obj) { delete obj; } - - // add a static method to QWidget - QWidget* static_QWidget_mouseGrabber() { return QWidget::mouseGrabber(); } - - // add an additional slot to QWidget (make move() callable, which is not declared as a slot in QWidget) - void move(QWidget* w, const QPoint& p) { w->move(p); } - - // add an additional slot to QWidget, overloading the above move method - void move(QWidget* w, int x, int y) { w->move(x,y); } - - // add a method to your own CPP object - int doSomething(YourCPPObject* obj, int arg1) { return obj->doSomething(arg1); } -}; - -... - -PythonQt::self()->addDecorators(new ExampleDecorator()); -PythonQt::self()->registerCPPClass("YourCPPObject"); - -\endcode - -After you have registered an instance of the above ExampleDecorator, you can do the following from Python -(all these calls are mapped to the above decorator slots): - -\code -from PythonQt import QtCore, QtGui, YourCPPObject - -# call our new constructor of QSize -size = QtCore.QSize(QPoint(1,2)); - -# call our new QPushButton constructor -button = QtGui.QPushButton("sometext"); - -# call the move slot (overload1) -button.move(QPoint(0,0)) - -# call the move slot (overload2) -button.move(0,0) - -# call the static method -grabber = QtGui.QWidget.mouseWrapper(); - -# create a CPP object via constructor -yourCpp = YourCPPObject(1,11.5) - -# call the wrapped method on CPP object -print yourCpp.doSomething(1); - -# destructor will be called: -yourCpp = None - -\endcode - - \page Building Building - - PythonQt requires at least Qt 4.6.1 (for earlier Qt versions, you will need to run the pythonqt_generator, Qt 4.3 is the absolute minimum) and Python 2.6.x/2.7.x or Python 3.3 (or higher). - To compile PythonQt, you will need a python developer installation which includes Python's header files and -the python2x.[lib | dll | so | dynlib]. - The recommended way to build PythonQt is to use the QMake-based *.pro file. - The build scripts a currently set to use Python 2.6. - You may need to tweak the \b build/python.prf file to set the correct Python includes and libs on your system. - - \subsection Windows - - On Windows, the (non-source) Python Windows installer can be used. - Make sure that you use the same compiler as the one that your Python distribution is built with. - If you want to use another compiler, you will need to build - Python yourself, using your compiler. - - To build PythonQt, you need to set the environment variable \b PYTHON_PATH to point to the root - dir of the python installation and \b PYTHON_LIB to point to - the directory where the python lib file is located. - - When using the prebuild Python installer, this will be: - - \code - > set PYTHON_PATH = c:\Python26 - > set PYTHON_LIB = c:\Python26\libs - \endcode - - When using the python sources, this will be something like: - - \code - > set PYTHON_PATH = c:\yourDir\Python-2.6.1\ - > set PYTHON_LIB = c:\yourDir\Python-2.6.1\PCbuild8\Win32 - \endcode - - To build all, do the following (after setting the above variables): - - \code - > cd PythonQtRoot - > vcvars32 - > qmake - > nmake - \endcode - - This should build everything. If Python can not be linked or include files can not be found, - you probably need to tweak \b build/python.prf - - The tests and examples are located in PythonQt/lib. - - When using a Python distribution, the debug build typically does not work because the - pythonxx_d.lib/.dll are not provided. You can tweak linking of the debug build to the release - Python version, but this typically requires patching pyconfig.h and removing Py_DEBUG and linker pragmas - (google for it!). - - \subsection Linux - - On Linux, you need to install a Python-dev package. - If Python can not be linked or include files can not be found, - you probably need to tweak \b build/python.prf - - To build PythonQt, just do a: - - \code - > cd PythonQtRoot - > qmake - > make all - \endcode - - The tests and examples are located in PythonQt/lib. - You should add PythonQt/lib to your LD_LIBRARY_PATH so that the runtime - linker can find the *.so files. - - \subsection MacOsX - - On Mac, Python is installed as a Framework, so you should not need to install it. - To build PythonQt, just do a: - - \code - > cd PythonQtRoot - > qmake - > make all - \endcode - - \section Tests - - There is a unit test that tests most features of PythonQt, see the \b tests subdirectory for details. - - \page Examples Examples - - Examples are available in the \b examples directory. The PyScriptingConsole implements a simple - interactive scripting console that shows how to script a simple application. The PyLauncher application can be used to run arbitrary PythonQt scripts given on the commandline. - - The following shows a simple example on how to integrate PythonQt into your Qt application: - - \code - #include "PythonQt.h" - #include - ... - - int main( int argc, char **argv ) - { - - QApplication qapp(argc, argv); - - // init PythonQt and Python itself - PythonQt::init(); - - // get a smart pointer to the __main__ module of the Python interpreter - PythonQtObjectPtr context = PythonQt::self()->getMainModule(); - - // add a QObject as variable of name "example" to the namespace of the __main__ module - PyExampleObject example; - context.addObject("example", &example); - - // do something - context.evalScript("print example"); - context.evalScript("def multiply(a,b):\n return a*b;\n"); - QVariantList args; - args << 42 << 47; - QVariant result = context.call("multiply", args); - ... - \endcode - - -*/ diff --git a/pythonqt/include/PythonQtImportFileInterface.h b/pythonqt/include/PythonQtImportFileInterface.h deleted file mode 100644 index d012b915..00000000 --- a/pythonqt/include/PythonQtImportFileInterface.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _PYTHONQTIMPORTFILEINTERFACE_H -#define _PYTHONQTIMPORTFILEINTERFACE_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtImportFileInterface.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include -#include -#include - -//! Defines an abstract interface to file access for the Python import statement. -//! see PythonQt::setImporter() -class PythonQtImportFileInterface { - -public: - // get rid of warnings - virtual ~PythonQtImportFileInterface() {} - - //! read the given file as byte array, without doing any linefeed translations - virtual QByteArray readFileAsBytes(const QString& filename) = 0; - - //! read a source file, expects a readable Python text file with translated line feeds. - //! If the file can not be load OR it can not be verified, ok is set to false - virtual QByteArray readSourceFile(const QString& filename, bool& ok) = 0; - - //! returns if the file exists - virtual bool exists(const QString& filename) = 0; - - //! get the last modified data of a file - virtual QDateTime lastModifiedDate(const QString& filename) = 0; - - //! indicates that *.py files which are newer than their corresponding *.pyc files - //! are ignored - virtual bool ignoreUpdatedPythonSourceFiles() { return false; } - - //! called by PythonQt after successful import to allow - //! recording of imports - virtual void importedModule(const QString& /*module*/) {}; - -}; - -#endif - diff --git a/pythonqt/include/PythonQtImporter.h b/pythonqt/include/PythonQtImporter.h deleted file mode 100644 index a5d0f8ce..00000000 --- a/pythonqt/include/PythonQtImporter.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef _PYTHONQTIMPORTER_ -#define _PYTHONQTIMPORTER_ - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtImporter.h -// \author Florian Link -// \author Last changed by $Author: stk $ -// \date 2004-06 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "structmember.h" -#include "osdefs.h" -#include "marshal.h" -#include "compile.h" -#include - -#include -#include - - -//! defines a python object that stores a Qt slot info -typedef struct _PythonQtImporter { - PyObject_HEAD - QString* _path; -} PythonQtImporter; - - -//! implements importing of python files into PythonQt -/*! also compiles/marshalls/unmarshalls py/pyc files and handles time stamps correctly -*/ -class PythonQtImport -{ -public: - - enum ModuleType { - MI_NOT_FOUND, - MI_MODULE, - MI_PACKAGE, - MI_SHAREDLIBRARY - }; - - struct ModuleInfo { - ModuleInfo() { - type = MI_NOT_FOUND; - } - QString fullPath; //!< the full path to the found file - QString moduleName; //!< the module name without the package prefix - ModuleType type; - }; - - //! initialize - static void init(); - - //! writes the python code to disk, marshalling and writing the time stamp - static void writeCompiledModule(PyCodeObject *co, const QString& filename, long mtime); - - /*! Given the contents of a .py[co] file in a buffer, unmarshal the data - and return the code object. Return None if it the magic word doesn't - match (we do this instead of raising an exception as we fall back - to .py if available and we don't want to mask other errors). - Returns a new reference. */ - static PyObject *unmarshalCode(const QString& path, const QByteArray& data, time_t mtime); - - //! Given a string buffer containing Python source code, compile it - //! return and return a code object as a new reference. - static PyObject *compileSource(const QString& path, const QByteArray& data); - - //! Return the code object for the module named by 'fullname' from the - //! Zip archive as a new reference. - static PyObject *getCodeFromData(const QString& path, int isbytecode = 0, int ispackage = 0, - time_t mtime = 0); - - //! Get the code object associated with the module specified by - //! 'fullname'. - static PyObject * getModuleCode(PythonQtImporter *self, - const char* fullname, QString& modpath); - - - //! gets the compiled code for the given *.py file if there is a valid pyc file, otherwise compiles the file and writes the pyc - static PyObject* getCodeFromPyc(const QString& file); - - //! Return if module exists and is a package or a module - static ModuleInfo getModuleInfo(PythonQtImporter* self, const QString& fullname); - - //! get the last name of a dot chain (first.second.last) - static QString getSubName(const QString& str); - - //! Given a buffer, return the long that is represented by the first - //! 4 bytes, encoded as little endian. This partially reimplements - //! marshal.c:r_long() - static long getLong(unsigned char *buf); - - //! get time stamp of file - static time_t getMTimeOfSource(const QString& path); - - //! replace extension of file - static QString replaceExtension(const QString& str, const QString& ext); - -}; - -#endif - diff --git a/pythonqt/include/PythonQtInstanceWrapper.h b/pythonqt/include/PythonQtInstanceWrapper.h deleted file mode 100644 index 761c8448..00000000 --- a/pythonqt/include/PythonQtInstanceWrapper.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef _PYTHONQTINSTANCEWRAPPER_H -#define _PYTHONQTINSTANCEWRAPPER_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtInstanceWrapper.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" -#include - -#include "structmember.h" -#include "methodobject.h" -#include "compile.h" -#include "eval.h" - -class PythonQtClassInfo; -class QObject; - -extern PYTHONQT_EXPORT PyTypeObject PythonQtInstanceWrapper_Type; - -//--------------------------------------------------------------- -//! a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjects) -typedef struct PythonQtInstanceWrapperStruct { - PyObject_HEAD - - //! the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL pointers - PythonQtClassInfo* classInfo(); - - //! set the QObject pointer - void setQObject(QObject* object) { - _obj = object; - _objPointerCopy = object; - } - - //! pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr - QPointer _obj; - //! a copy of the _obj pointer, which is required because the wrapper needs to - //! deregister itself via the _obj pointer, even when the QPointer object was destroyed - void* _objPointerCopy; - - //! optional C++ object Ptr that is wrapped by the above _obj - void* _wrappedPtr; - - // TODO xxx: put booleans into int that holds flags - - //! flag that stores if the object is owned by pythonQt - bool _ownedByPythonQt; - - //! stores that the owned object should be destroyed using QMetaType::destroy() - bool _useQMetaTypeDestroy; - - //! stores if the object is a shell instance - bool _isShellInstance; - -} PythonQtInstanceWrapper; - -int PythonQtInstanceWrapper_init(PythonQtInstanceWrapper * self, PyObject * args, PyObject * kwds); - -PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self); - -#endif - diff --git a/pythonqt/include/PythonQtMethodInfo.h b/pythonqt/include/PythonQtMethodInfo.h deleted file mode 100644 index 94db76d7..00000000 --- a/pythonqt/include/PythonQtMethodInfo.h +++ /dev/null @@ -1,209 +0,0 @@ -#ifndef _PYTHONQTMETHODINFO_H -#define _PYTHONQTMETHODINFO_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtMethodInfo.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtSystem.h" - -#include -#include -#include -#include - -class PythonQtClassInfo; -struct _object; -typedef struct _object PyObject; - -//! stores information about a specific signal/slot/method -class PYTHONQT_EXPORT PythonQtMethodInfo -{ -public: - enum ParameterType { - Unknown = -1, - Variant = -2 - }; - - //! stores various informations about a parameter/type name - struct ParameterInfo { - QByteArray name; - QByteArray innerName; // if the type is a template, this stores the inner name - PyObject* enumWrapper; // if it is an enum, a pointer to the enum wrapper - int typeId; // a mixture from QMetaType and ParameterType - char pointerCount; // the number of pointer indirections - char innerNamePointerCount; // the number of pointer indirections in the inner name - bool isConst; - bool isQList; - }; - - PythonQtMethodInfo() {}; - ~PythonQtMethodInfo() {}; - PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInfo* classInfo); - PythonQtMethodInfo(const QByteArray& typeName, const QList& args); - PythonQtMethodInfo(const PythonQtMethodInfo& other) { - _parameters = other._parameters; - } - - //! returns the method info of the signature, uses a cache internally to speed up - //! multiple requests for the same method, classInfo is passed to allow local enum resolution (if NULL is passed, no local enums are recognized) - static const PythonQtMethodInfo* getCachedMethodInfo(const QMetaMethod& method, PythonQtClassInfo* classInfo); - - //! get the cached method info using the passed in list of return value and arguments, return value needs to be passed as first arg - static const PythonQtMethodInfo* getCachedMethodInfoFromArgumentList(int numArgs, const char** args); - - //! cleanup the cache - static void cleanupCachedMethodInfos(); - - //! returns the number of parameters including the return value - int parameterCount() const { return _parameters.size(); }; - - //! returns the id for the given type (using an internal dictionary) - static int nameToType(const char* name); - - //! get the parameter infos - const QList& parameters() const { return _parameters; } - - //! add an alias for a typename, e.g. QObjectList and QList. - static void addParameterTypeAlias(const QByteArray& alias, const QByteArray& name); - - //! fill the parameter info for the given type name - static void fillParameterInfo(ParameterInfo& type, const QByteArray& name, PythonQtClassInfo* classInfo = NULL); - - //! returns a parameter info for the given metatype (and creates and caches one if it is not yet present) - static const ParameterInfo& getParameterInfoForMetaType(int type); - - //! returns the inner type id of a simple template of the form SomeObject - static int getInnerTemplateMetaType(const QByteArray& typeName); - - //! returns the inner type name of a simple template of the form SomeObject - static QByteArray getInnerTemplateTypeName(const QByteArray& typeName); - -protected: - - static QHash _parameterTypeDict; - static QHash _parameterNameAliases; - - //! stores the cached signatures of methods to speedup mapping from Qt to Python types - static QHash _cachedSignatures; - - static QHash _cachedParameterInfos; - - QList _parameters; -}; - -//! stores information about a slot, including a next pointer to overloaded slots -class PythonQtSlotInfo : public PythonQtMethodInfo -{ -public: - enum Type { - MemberSlot, InstanceDecorator, ClassDecorator - }; - - PythonQtSlotInfo(const PythonQtSlotInfo& info):PythonQtMethodInfo() { - _meta = info._meta; - _parameters = info._parameters; - _slotIndex = info._slotIndex; - _next = NULL; - _decorator = info._decorator; - _type = info._type; - _upcastingOffset = 0; - } - - PythonQtSlotInfo(PythonQtClassInfo* classInfo, const QMetaMethod& meta, int slotIndex, QObject* decorator = NULL, Type type = MemberSlot ):PythonQtMethodInfo() - { - const PythonQtMethodInfo* info = getCachedMethodInfo(meta, classInfo); - _meta = meta; - _parameters = info->parameters(); - _slotIndex = slotIndex; - _next = NULL; - _decorator = decorator; - _type = type; - _upcastingOffset = 0; - } - - -public: - - void deleteOverloadsAndThis(); - - const QMetaMethod* metaMethod() const { return &_meta; } - - void setUpcastingOffset(int upcastingOffset) { _upcastingOffset = upcastingOffset; } - - int upcastingOffset() const { return _upcastingOffset; } - - //! get the index of the slot (needed for qt_metacall) - int slotIndex() const { return _slotIndex; } - - //! get next overloaded slot (which has the same name) - PythonQtSlotInfo* nextInfo() const { return _next; } - - //! set the next overloaded slot - void setNextInfo(PythonQtSlotInfo* next) { _next = next; } - - //! returns if the slot is a decorator slot - bool isInstanceDecorator() { return _decorator!=NULL && _type == InstanceDecorator; } - - //! returns if the slot is a constructor slot - bool isClassDecorator() { return _decorator!=NULL && _type == ClassDecorator; } - - QObject* decorator() { return _decorator; } - - //! get the full signature including return type - QString fullSignature(); - - //! get the Qt signature of the slot - QByteArray signature() const; - - //! get the short slot name - QByteArray slotName() const; - -private: - int _slotIndex; - PythonQtSlotInfo* _next; - QObject* _decorator; - Type _type; - QMetaMethod _meta; - int _upcastingOffset; -}; - - -#endif diff --git a/pythonqt/include/PythonQtMisc.h b/pythonqt/include/PythonQtMisc.h deleted file mode 100644 index 2c75c456..00000000 --- a/pythonqt/include/PythonQtMisc.h +++ /dev/null @@ -1,175 +0,0 @@ -#ifndef _PYTHONQTMISC_H -#define _PYTHONQTMISC_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtMisc.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - - -#include - -#define PythonQtValueStorage_ADD_VALUE(store, type, value, ptr) \ -{ type* item = (type*)store.nextValuePtr(); \ - *item = value; \ - ptr = (void*)item; \ -} - -#define PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedPtr,store, type, value, ptr) \ -{ \ - type* item = (type*)(alreadyAllocatedPtr?alreadyAllocatedPtr:store.nextValuePtr()); \ - *item = value; \ - ptr = (void*)item; \ -} - -//! stores a position in the PythonQtValueStorage -class PythonQtValueStoragePosition { - -public: - PythonQtValueStoragePosition() { chunkIdx = 0; chunkOffset = 0; } - - int chunkIdx; - int chunkOffset; - -}; - -//! a helper class that stores basic C++ value types in chunks -template class PythonQtValueStorage -{ -public: - PythonQtValueStorage() { - _chunkIdx = 0; - _chunkOffset = 0; - _currentChunk = new T[chunkEntries]; - _chunks.append(_currentChunk); - }; - - //! clear all memory - void clear() { - T* chunk; - Q_FOREACH(chunk, _chunks) { - delete[]chunk; - } - _chunks.clear(); - } - - //! get the current position to be restored with setPos - void getPos(PythonQtValueStoragePosition & pos) { - pos.chunkIdx = _chunkIdx; - pos.chunkOffset = _chunkOffset; - } - - //! set the current position (without freeing memory, thus caching old entries for reuse) - void setPos(const PythonQtValueStoragePosition& pos) { - _chunkOffset = pos.chunkOffset; - if (_chunkIdx != pos.chunkIdx) { - _chunkIdx = pos.chunkIdx; - _currentChunk = _chunks.at(_chunkIdx); - } - } - - //! add one default constructed value and return the pointer to it - T* nextValuePtr() { - if (_chunkOffset>=chunkEntries) { - _chunkIdx++; - if (_chunkIdx >= _chunks.size()) { - T* newChunk = new T[chunkEntries]; - _chunks.append(newChunk); - _currentChunk = newChunk; - } else { - _currentChunk = _chunks.at(_chunkIdx); - } - _chunkOffset = 0; - } - T* newEntry = _currentChunk + _chunkOffset; - _chunkOffset++; - return newEntry; - }; - -protected: - QList _chunks; - - int _chunkIdx; - int _chunkOffset; - T* _currentChunk; - -}; - -//! a helper class that stores basic C++ value types in chunks and clears the unused values on setPos() usage. -template class PythonQtValueStorageWithCleanup : public PythonQtValueStorage -{ -public: - void setPos(const PythonQtValueStoragePosition& pos) { - if (_chunkIdx > pos.chunkIdx) { - T* firstChunk = _chunks.at(pos.chunkIdx); - // clear region in first chunk - for (int i = pos.chunkOffset; i < chunkEntries; i++) { - firstChunk[i] = T(); - } - for (int chunk = pos.chunkIdx + 1; chunk < _chunkIdx; chunk++) { - // clear the full chunks between the first and last chunk - T* fullChunk = _chunks.at(chunk); - for (int i = 0; i < chunkEntries; i++) { - fullChunk[i] = T(); - } - } - // clear region in last chunk - T* lastChunk = _chunks.at(_chunkIdx); - for (int i = 0; i < _chunkOffset; i++) { - lastChunk[i] = T(); - } - } else if (_chunkIdx == pos.chunkIdx) { - // clear the region in the last chunk only - T* lastChunk = _chunks.at(_chunkIdx); - for (int i = pos.chunkOffset; i<_chunkOffset; i++) { - lastChunk[i] = T(); - } - } - - PythonQtValueStorage::setPos(pos); - } - -private: - using PythonQtValueStorage::_chunks; - using PythonQtValueStorage::_chunkIdx; - using PythonQtValueStorage::_chunkOffset; - using PythonQtValueStorage::_currentChunk; -}; - -#endif diff --git a/pythonqt/include/PythonQtObjectPtr.h b/pythonqt/include/PythonQtObjectPtr.h deleted file mode 100644 index c4b7611a..00000000 --- a/pythonqt/include/PythonQtObjectPtr.h +++ /dev/null @@ -1,164 +0,0 @@ -#ifndef _PYTHONQTOBJECTPTR_H -#define _PYTHONQTOBJECTPTR_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtObjectPtr.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" -#include -#include -#include - -//! a smart pointer that stores a PyObject pointer and that handles reference counting automatically -class PYTHONQT_EXPORT PythonQtObjectPtr -{ -public: - PythonQtObjectPtr():_object(NULL) {} - - PythonQtObjectPtr(const PythonQtObjectPtr &p) - :_object(NULL) { - setObject(p.object()); - } - - //! If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count. - PythonQtObjectPtr(const QVariant& variant):_object(NULL) { - fromVariant(variant); - } - - PythonQtObjectPtr(PyObject* o); - - ~PythonQtObjectPtr(); - - //! If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count. - bool fromVariant(const QVariant& variant); - - PythonQtObjectPtr &operator=(const PythonQtObjectPtr &p) { - setObject(p.object()); - return *this; - } - - PythonQtObjectPtr &operator=(PyObject* o) { - setObject(o); - return *this; - } - - - PythonQtObjectPtr &operator=(const QVariant& variant) { - fromVariant(variant); - return *this; - } - - - bool operator==( const PythonQtObjectPtr &p ) const { - return object() == p.object(); - } - - bool operator!= ( const PythonQtObjectPtr& p ) const { - return !( *this == p ); - } - - bool operator==( PyObject* p ) const { - return object() == p; - } - - bool operator!= ( PyObject* p ) const { - return object() != p; - } - - bool isNull() const { return !object(); } - - PyObject* operator->() const { return object(); } - - PyObject& operator*() const { return *( object() ); } - - operator PyObject*() const { return object(); } - - //! sets the object and passes the ownership (stealing the reference, in Python slang) - void setNewRef(PyObject* o); - - PyObject* object() const { - return _object; - } - - //! evaluates the given script code in the context of this object and returns the result value - QVariant evalScript(const QString& script, int start = Py_file_input); - - //! evaluates the given code and returns the result value (use Py_Compile etc. to create pycode from string) - //! If pycode is NULL, a python error is printed. - QVariant evalCode(PyObject* pycode); - - //! evaluates the given code in the context - void evalFile(const QString& filename); - - //! add the given \c object to the \c module as a variable with \c name (it can be removed via clearVariable) - void addObject(const QString& name, QObject* object); - - //! add the given variable to the module - void addVariable(const QString& name, const QVariant& v); - - //! remove the given variable - void removeVariable(const QString& name); - - //! get the variable with the \c name of the \c module, returns an invalid QVariant on error - QVariant getVariable(const QString& name); - - //! call the given python object (in the scope of the current object), returns the result converted to a QVariant - QVariant call(const QString& callable, const QVariantList& args = QVariantList(), const QVariantMap& kwargs = QVariantMap()); - - //! call the contained python object directly, returns the result converted to a QVariant - QVariant call(const QVariantList& args = QVariantList(), const QVariantMap& kwargs = QVariantMap()); - -protected: - - void setObject(PyObject* o); - -private: - PyObject* _object; -}; - - -// register it to the meta type system -Q_DECLARE_METATYPE(PythonQtObjectPtr) - -#endif - diff --git a/pythonqt/include/PythonQtPythonInclude.h b/pythonqt/include/PythonQtPythonInclude.h deleted file mode 100644 index e001b808..00000000 --- a/pythonqt/include/PythonQtPythonInclude.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Copyright (C) 2011 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -#ifndef __PythonQtPythonInclude_h -#define __PythonQtPythonInclude_h - -// Undefine macros that Python.h defines to avoid redefinition warning. -#undef _POSIX_C_SOURCE -#undef _POSIX_THREADS -#undef _XOPEN_SOURCE - -// Undefine Qt keywords that conflict with Python headers -#ifdef slots -#undef slots -#define PYTHONQT_RESTORE_KEYWORDS -#endif - -// If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link -// release Python DLL if it is available by undefining _DEBUG while -// including Python.h -#if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG) -#undef _DEBUG -#if defined(_MSC_VER) && _MSC_VER >= 1400 -#define _CRT_NOFORCE_MANIFEST 1 -#define _STL_NOFORCE_MANIFEST 1 -#endif -#include -#define _DEBUG -#else -#include -#endif - -// get Qt keywords back -#ifdef PYTHONQT_RESTORE_KEYWORDS -#define slots Q_SLOTS -#undef PYTHONQT_RESTORE_KEYWORDS -#endif - -#if PY_MAJOR_VERSION >= 3 -#define PY3K -// Helper defines to facilitate porting -#define PyString_FromString PyUnicode_FromString -#define PyString_AS_STRING PyUnicode_AsUTF8 -#define PyString_AsString PyUnicode_AsUTF8 -#define PyString_FromFormat PyUnicode_FromFormat -#define PyString_Check PyUnicode_Check - -#define PyInt_Type PyLong_Type -#define PyInt_FromLong PyLong_FromLong -#define PyInt_AS_LONG PyLong_AS_LONG -#define PyInt_Check PyLong_Check -#define PyInt_AsLong PyLong_AsLong - -#else -// Defines to use Python 3 names in Python 2 code -#define PyBytes_Type PyString_Type -#define PyBytes_Check PyString_Check -#define PyBytes_AS_STRING PyString_AS_STRING -#define PyBytes_AsString PyString_AsString -#define PyBytes_GET_SIZE PyString_GET_SIZE -#define PyBytes_FromStringAndSize PyString_FromStringAndSize -#endif - -#endif diff --git a/pythonqt/include/PythonQtQFileImporter.h b/pythonqt/include/PythonQtQFileImporter.h deleted file mode 100644 index 310b3f7a..00000000 --- a/pythonqt/include/PythonQtQFileImporter.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _PYTHONQTQFILEIMPORTER_H -#define _PYTHONQTQFILEIMPORTER_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! - // \file PythonQtQFileImporter.h - // \author Florian Link - // \author Last changed by $Author: florian $ - // \date 2009-03 - */ -//---------------------------------------------------------------------------------- - -#include - -//! default importer implementation using QFile to load python code -class PythonQtQFileImporter : public PythonQtImportFileInterface { -public: - PythonQtQFileImporter(); - ~PythonQtQFileImporter(); - - QByteArray readFileAsBytes (const QString &filename); - - QByteArray readSourceFile (const QString &filename, bool &ok); - - bool exists (const QString &filename); - - QDateTime lastModifiedDate (const QString &filename); - -}; - -#endif diff --git a/pythonqt/include/PythonQtSignal.h b/pythonqt/include/PythonQtSignal.h deleted file mode 100644 index 3ee66500..00000000 --- a/pythonqt/include/PythonQtSignal.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _PythonQtSignal_H -#define _PythonQtSignal_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtSignal.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" -#include "structmember.h" - -class PythonQtSlotInfo; - -extern PYTHONQT_EXPORT PyTypeObject PythonQtSignalFunction_Type; - -#define PythonQtSignalFunction_Check(op) (Py_TYPE(op) == &PythonQtSignalFunction_Type) - -PyObject* PythonQtSignalFunction_New(PythonQtSlotInfo *, PyObject *, - PyObject *); - -//! defines a python object that stores a Qt signal info -typedef struct { - PyObject_HEAD - PythonQtSlotInfo *m_ml; /* Description of the C function to call */ - PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ - PyObject *m_module; /* The __module__ attribute, can be anything */ -} PythonQtSignalFunctionObject; - - -#endif diff --git a/pythonqt/include/PythonQtSignalReceiver.h b/pythonqt/include/PythonQtSignalReceiver.h deleted file mode 100644 index 16682cf2..00000000 --- a/pythonqt/include/PythonQtSignalReceiver.h +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef _PYTHONQTSIGNALRECEIVER_H -#define _PYTHONQTSIGNALRECEIVER_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtSignalReceiver.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" -#include "PythonQtObjectPtr.h" - -class PythonQtMethodInfo; -class PythonQtClassInfo; - -//! stores information about a signal target -/*! copy construction and assignment works fine with the C++ standard behavior and are thus not implemented -*/ -class PYTHONQT_EXPORT PythonQtSignalTarget { -public: - PythonQtSignalTarget() { - _signalId = -1; - _methodInfo = NULL; - _slotId = -1; - } - - PythonQtSignalTarget(int signalId,const PythonQtMethodInfo* methodInfo, int slotId, PyObject* callable) - { - _signalId = signalId; - _slotId = slotId; - _methodInfo = methodInfo; - _callable = callable; - }; - - ~PythonQtSignalTarget() { - }; - - //! get the id of the original signal - int signalId() const { return _signalId; } - - //! get the id that was assigned to this simulated slot - int slotId() const { return _slotId; } - - //! get the signals parameter info - const PythonQtMethodInfo* methodInfo() const { return _methodInfo; } - - //! call the python callable with the given arguments (as defined in methodInfo) - void call(void **arguments) const; - - //! check if it is the same signal target - bool isSame(int signalId, PyObject* callable) const; - - //! call the given callable with arguments described by PythonQtMethodInfo, returns a new reference as result value (or NULL) - static PyObject* call(PyObject* callable, const PythonQtMethodInfo* methodInfo, void **arguments, bool skipFirstArgumentOfMethodInfo = false); - -private: - int _signalId; - int _slotId; - const PythonQtMethodInfo* _methodInfo; - PythonQtObjectPtr _callable; -}; - -//! base class for signal receivers -/*! -*/ -class PythonQtSignalReceiverBase : public QObject { - Q_OBJECT -public: - PythonQtSignalReceiverBase(QObject* obj):QObject(obj) {}; -}; - -//! receives all signals for one QObject -/*! we derive from our base but do not declare the QObject macro because we want to reimplement qt_metacall only. -*/ -class PythonQtSignalReceiver : public PythonQtSignalReceiverBase { - -public: - PythonQtSignalReceiver(QObject* obj); - ~PythonQtSignalReceiver(); - - //! add a signal handler - bool addSignalHandler(const char* signal, PyObject* callable); - - //! remove a signal handler for given callable (or all callables on that signal if callable is NULL) - bool removeSignalHandler(const char* signal, PyObject* callable = NULL); - - //! we implement this method to simulate a number of slots that match the ids in _targets - virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments); - -private: - //! get the index of the signal - int getSignalIndex(const char* signal); - - QObject* _obj; - PythonQtClassInfo* _objClassInfo; - int _slotCount; - int _destroyedSignalCount; - // linear list may get slow on multiple targets, but I think typically we have many objects and just a few signals - QList _targets; - - static int _destroyedSignal1Id; - static int _destroyedSignal2Id; -}; - - -#endif - diff --git a/pythonqt/include/PythonQtSlot.h b/pythonqt/include/PythonQtSlot.h deleted file mode 100644 index 0fdc06e7..00000000 --- a/pythonqt/include/PythonQtSlot.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _PYTHONQTSLOT_H -#define _PYTHONQTSLOT_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtSlot.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" -#include "structmember.h" - -class PythonQtSlotInfo; - -extern PYTHONQT_EXPORT PyTypeObject PythonQtSlotFunction_Type; - -#define PythonQtSlotFunction_Check(op) (Py_TYPE(op) == &PythonQtSlotFunction_Type) - -PythonQtSlotInfo* PythonQtSlotFunction_GetSlotInfo(PyObject *); -PyObject* PythonQtSlotFunction_GetSelf(PyObject *); - -/* Macros for direct access to these values. Type checks are *not* - done, so use with care. */ -#define PythonQtSlotFunction_GET_SELF(func) \ - (((PythonQtSlotFunctionObject *)func) -> m_self) - -PyObject* PythonQtSlotFunction_Call(PyObject *, PyObject *, PyObject *); - -PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject *kw, void* firstArg=NULL, void** directReturnValuePointer=NULL); - -PyObject* PythonQtSlotFunction_New(PythonQtSlotInfo *, PyObject *, - PyObject *); - -PyObject *PythonQtMemberFunction_Call(PythonQtSlotInfo* info, PyObject* m_self, PyObject *args, PyObject *kw); -PyObject *PythonQtMemberFunction_parameterTypes(PythonQtSlotInfo* theInfo); -PyObject *PythonQtMemberFunction_parameterNames(PythonQtSlotInfo* theInfo); -PyObject *PythonQtMemberFunction_typeName(PythonQtSlotInfo* theInfo); - -//! defines a python object that stores a Qt slot info -typedef struct { - PyObject_HEAD - PythonQtSlotInfo *m_ml; /* Description of the C function to call */ - PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ - PyObject *m_module; /* The __module__ attribute, can be anything */ -} PythonQtSlotFunctionObject; - - -#endif diff --git a/pythonqt/include/PythonQtStdDecorators.h b/pythonqt/include/PythonQtStdDecorators.h deleted file mode 100644 index 3a6bee15..00000000 --- a/pythonqt/include/PythonQtStdDecorators.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef _PYTHONQTSTDDECORATORS_H -#define _PYTHONQTSTDDECORATORS_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtStdDecorators.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2007-04 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" - -#include "PythonQtSystem.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class PYTHONQT_EXPORT PythonQtStdDecorators : public QObject -{ - Q_OBJECT - -public Q_SLOTS: - bool connect(QObject* sender, const QByteArray& signal, PyObject* callable); - bool connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection); - bool connect(QObject* receiver, QObject* sender, const QByteArray& signal, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); } - bool static_QObject_connect(QObject* sender, const QByteArray& signal, PyObject* callable) { return connect(sender, signal, callable); } - bool static_QObject_connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); } - bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = NULL); - bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot); - bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = NULL) { return disconnect(sender, signal, callable); } - bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) { return connect(sender, signal, receiver, slot); } - - const QMetaObject* metaObject( QObject* obj ); - - QObject* parent(QObject* o); - void setParent(QObject* o, QObject* parent); - - const QObjectList* children(QObject* o); - QObject* findChild(QObject* parent, PyObject* type, const QString& name = QString()); - QList findChildren(QObject* parent, PyObject* type, const QString& name= QString()); - QList findChildren(QObject* parent, PyObject* type, const QRegExp& regExp); - - bool setProperty(QObject* o, const char* name, const QVariant& value); - QVariant property(QObject* o, const char* name); - - double static_Qt_qAbs(double a) { return qAbs(a); } - double static_Qt_qBound(double a,double b,double c) { return qBound(a,b,c); } - void static_Qt_qDebug(const QByteArray& msg) { qDebug("%s", msg.constData()); } - // TODO: multi arg qDebug... - void static_Qt_qWarning(const QByteArray& msg) { qWarning("%s", msg.constData()); } - // TODO: multi arg qWarning... - void static_Qt_qCritical(const QByteArray& msg) { qCritical("%s", msg.constData()); } - // TODO: multi arg qCritical... - void static_Qt_qFatal(const QByteArray& msg) { qFatal("%s", msg.constData()); } - // TODO: multi arg qFatal... - bool static_Qt_qFuzzyCompare(double a, double b) { return qFuzzyCompare(a, b); } - double static_Qt_qMax(double a, double b) { return qMax(a, b); } - double static_Qt_qMin(double a, double b) { return qMin(a, b); } - int static_Qt_qRound(double a) { return qRound(a); } - qint64 static_Qt_qRound64(double a) { return qRound64(a); } - const char* static_Qt_qVersion() { return qVersion(); } - int static_Qt_qrand() { return qrand(); } - void static_Qt_qsrand(uint a) { qsrand(a); } - - QString tr(QObject* obj, const QByteArray& text, const QByteArray& ambig = QByteArray(), int n = -1); - - QByteArray static_Qt_SIGNAL(const QByteArray& s) { return QByteArray("2") + s; } - QByteArray static_Qt_SLOT(const QByteArray& s) { return QByteArray("1") + s; } - -private: - QObject* findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name); - int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList& list); - int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QRegExp& regExp, QList& list); -}; - -class PythonQtWrapper_QMetaObject : public QObject -{ - Q_OBJECT - -public Q_SLOTS: - const char *className(QMetaObject* obj) const { return obj->className(); } - const QMetaObject *superClass(QMetaObject* obj) const { return obj->superClass(); } - - int methodOffset(QMetaObject* obj) const { return obj->methodOffset(); } - int enumeratorOffset(QMetaObject* obj) const { return obj->enumeratorOffset(); } - int propertyOffset(QMetaObject* obj) const { return obj->propertyOffset(); } - int classInfoOffset(QMetaObject* obj) const { return obj->classInfoOffset(); } - - int constructorCount(QMetaObject* obj) const { return obj->constructorCount(); } - int methodCount(QMetaObject* obj) const { return obj->methodCount(); } - int enumeratorCount(QMetaObject* obj) const { return obj->enumeratorCount(); } - int propertyCount(QMetaObject* obj) const { return obj->propertyCount(); } - int classInfoCount(QMetaObject* obj) const { return obj->classInfoCount(); } - - int indexOfConstructor(QMetaObject* obj, const char *constructor) const { return obj->indexOfConstructor(constructor); } - int indexOfMethod(QMetaObject* obj, const char *method) const { return obj->indexOfMethod(method); } - int indexOfSignal(QMetaObject* obj, const char *signal) const { return obj->indexOfSignal(signal); } - int indexOfSlot(QMetaObject* obj, const char *slot) const { return obj->indexOfSlot(slot); } - int indexOfEnumerator(QMetaObject* obj, const char *name) const { return obj->indexOfEnumerator(name); } - int indexOfProperty(QMetaObject* obj, const char *name) const { return obj->indexOfProperty(name); } - int indexOfClassInfo(QMetaObject* obj, const char *name) const { return obj->indexOfClassInfo(name); } - - QMetaMethod constructor(QMetaObject* obj, int index) const { return obj->constructor(index); } - QMetaMethod method(QMetaObject* obj, int index) const { return obj->method(index); } - QMetaEnum enumerator(QMetaObject* obj, int index) const { return obj->enumerator(index); } - QMetaProperty property(QMetaObject* obj, int index) const { return obj->property(index); } - QMetaClassInfo classInfo(QMetaObject* obj, int index) const { return obj->classInfo(index); } - QMetaProperty userProperty(QMetaObject* obj) const { return obj->userProperty(); } - - bool static_QMetaObject_checkConnectArgs(const char *signal, const char *method) { return QMetaObject::checkConnectArgs(signal, method); } - QByteArray static_QMetaObject_normalizedSignature(const char *method) { return QMetaObject::normalizedSignature(method); } - QByteArray static_QMetaObject_normalizedType(const char *type) { return QMetaObject::normalizedType(type); } - -}; - -#endif diff --git a/pythonqt/include/PythonQtStdIn.h b/pythonqt/include/PythonQtStdIn.h deleted file mode 100644 index 8377e0d1..00000000 --- a/pythonqt/include/PythonQtStdIn.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _PYTHONQTSTDIN_H -#define _PYTHONQTSTDIN_H - -/* - * - * Copyright (C) 2011 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtStdIn.h -// \author Jean-Christophe Fillion-Robin -// \author Last changed by $Author: jcfr $ -// \date 2011 -*/ -//---------------------------------------------------------------------------------- - - -#include "PythonQtPythonInclude.h" -#include "structmember.h" -#include - -//! declares the type of the stdout redirection class -extern PyTypeObject PythonQtStdInRedirectType; - -//! declares the callback that is called from the write() function -typedef QString PythonQtInputChangedCB(void* callData); - -//! declares the stdin redirection class -typedef struct { - PyObject_HEAD - PythonQtInputChangedCB* _cb; - void * _callData; -} PythonQtStdInRedirect; - -#endif diff --git a/pythonqt/include/PythonQtStdOut.h b/pythonqt/include/PythonQtStdOut.h deleted file mode 100644 index 01724deb..00000000 --- a/pythonqt/include/PythonQtStdOut.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _PYTHONQTSTDOUT_H -#define _PYTHONQTSTDOUT_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtStdOut.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - - -#include "PythonQtPythonInclude.h" - -#include "structmember.h" -#include - -//! declares the type of the stdout redirection class -extern PyTypeObject PythonQtStdOutRedirectType; - -//! declares the callback that is called from the write() function -typedef void PythonQtOutputChangedCB(const QString& str); - -//! declares the stdout redirection class -typedef struct { - PyObject_HEAD - PythonQtOutputChangedCB* _cb; - int softspace; -} PythonQtStdOutRedirect; - -#endif diff --git a/pythonqt/include/PythonQtSystem.h b/pythonqt/include/PythonQtSystem.h deleted file mode 100644 index d7131bb7..00000000 --- a/pythonqt/include/PythonQtSystem.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _PYTHONQTSYSTEM_ -#define _PYTHONQTSYSTEM_ - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtSystem.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2006-05 -*/ -//---------------------------------------------------------------------------------- - -#ifdef WIN32 -#ifdef PYTHONQT_EXPORTS -#define PYTHONQT_EXPORT __declspec(dllexport) -#else -#define PYTHONQT_EXPORT __declspec(dllimport) -#endif -#else -#define PYTHONQT_EXPORT -#endif - -#endif - diff --git a/pythonqt/include/PythonQtUtils.h b/pythonqt/include/PythonQtUtils.h deleted file mode 100644 index 50692d47..00000000 --- a/pythonqt/include/PythonQtUtils.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef _PYTHONQTUTILS_H -#define _PYTHONQTUTILS_H - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtUtils.h -// \author Florian Link -// \author Last changed by $Author: florian $ -// \date 2014-09 -*/ -//---------------------------------------------------------------------------------- - -#include "PythonQtPythonInclude.h" -#include "PythonQtSystem.h" - -#include -#include - -namespace PythonQtUtils -{ - inline QByteArray signature(const QMetaMethod& method) { -#if( QT_VERSION >= QT_VERSION_CHECK(5,0,0) ) - return method.methodSignature(); -#else - return QByteArray(method.signature()); -#endif - } - - inline QByteArray methodName(const QMetaMethod& method) { -#if( QT_VERSION >= QT_VERSION_CHECK(5,0,0) ) - return method.name(); -#else - QByteArray sig(method.signature()); - int idx = sig.indexOf('('); - sig = sig.left(idx); - return sig; -#endif - } - - inline QByteArray typeName(const QMetaMethod& method) { -#if( QT_VERSION >= QT_VERSION_CHECK(5,0,0) ) - QByteArray result = method.typeName(); - if (result == "void") { - return QByteArray(); - } else { - return result; - } -#else - return method.typeName(); -#endif - } - - //! Returns of the python object is a class type - inline bool isPythonClassType(PyObject* obj) { -#ifdef PY3K - return PyType_Check(obj); -#else - // support old-style classes and new style classes - return (obj->ob_type == &PyClass_Type || obj->ob_type == &PyType_Type); -#endif - } -} - -#endif - diff --git a/pythonqt/include/PythonQtVariants.h b/pythonqt/include/PythonQtVariants.h deleted file mode 100644 index 7e069101..00000000 --- a/pythonqt/include/PythonQtVariants.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _PYTHONQTVARIANTS_ -#define _PYTHONQTVARIANTS_ - -/* - * - * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. - * - * 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. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, - * 28359 Bremen, Germany or: - * - * http://www.mevis.de - * - */ - -//---------------------------------------------------------------------------------- -/*! -// \file PythonQtVariants.h -// \author Florian Link -// \author Last changed by $Author: stk $ -// \date 2006-08 -*/ -//---------------------------------------------------------------------------------- - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif - diff --git a/pythonqt/lib/libPythonQt.1.dylib b/pythonqt/lib/libPythonQt.1.dylib deleted file mode 100755 index 7ab8bc02..00000000 Binary files a/pythonqt/lib/libPythonQt.1.dylib and /dev/null differ diff --git a/pythonqt/lib/libPythonQt.dylib b/pythonqt/lib/libPythonQt.dylib new file mode 120000 index 00000000..0ba75495 --- /dev/null +++ b/pythonqt/lib/libPythonQt.dylib @@ -0,0 +1 @@ +libPythonQt.1.dylib \ No newline at end of file diff --git a/pythonqt/lib/libPythonQt_QtAll.1.dylib b/pythonqt/lib/libPythonQt_QtAll.1.dylib deleted file mode 100755 index e619f030..00000000 Binary files a/pythonqt/lib/libPythonQt_QtAll.1.dylib and /dev/null differ diff --git a/pythonqt/lib/libPythonQt_QtAll.dylib b/pythonqt/lib/libPythonQt_QtAll.dylib new file mode 120000 index 00000000..33973656 --- /dev/null +++ b/pythonqt/lib/libPythonQt_QtAll.dylib @@ -0,0 +1 @@ +libPythonQt_QtAll.1.dylib \ No newline at end of file diff --git a/src/make-songbook-process.cc b/src/make-songbook-process.cc index 7b0f5a38..b3d44fe9 100644 --- a/src/make-songbook-process.cc +++ b/src/make-songbook-process.cc @@ -18,7 +18,6 @@ //****************************************************************************** #include "make-songbook-process.hh" -#include "PythonQt.h" #include #include