diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000..c8dfc2a --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,37 @@ + +Version 1.1 ChangeLog: + +florianlink | 2007-11-15 08:38:24 -0800 (Thu, 15 Nov 2007) +- added support for mapping Python lists to QList lists on slot calls +- added support for QList return values and signal signatures +- changed binary output to lib as well, so that the setting of PATH can be avoided +- changed profiles to use a new common.prf to facilitate global settings +- improved docs +- added _d extension for debug build (see common.prf) +- added $$PWD, which is important if the file is included from somewhere else (which we do in mevis) +- added softspace support (implemented by Andre Kramer) +- updated windows documentation and variables which need to be set +- changed to use only PYTHON_PATH on Windows +- added more build docs +- changed date conversion from/to strings to ISODate +- fixed return argument initialization to NULL +- added mevis doc +- fixed handling of unknown reference types +- made lookupObject public +- added overload calls to introspection + +marcusbarann | 2007-11-08 06:15:55 -0800 (Thu, 08 Nov 2007) +- Added PythonQt.pro, cleaned up build system + +akramer | 2007-10-17 08:02:25 -0700 (Wed, 17 Oct 2007) +- external variant was missing the "config += qtestlib" needed for using the Qt unit test framework. +- provide relative path to Gui extension lib +- added a sentence about using the Windows installer version of Python +- Fix for converting QByteArray values that include 0 chars. + They are still converted to/from Python strings but using + size of contents rather than string 0 (null) termination. +- bug fix for getMTimeOfSource when PythonQt::importInterface() is null +- Linux external build improvements + +2007-01-30 00:11:25 -0800 (Tue, 30 Jan 2007) | 1 line +- Released version 1.0 diff --git a/README b/README index 26f53c4..b9aa6a2 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ PythonQt -------- PythonQt is a dynamic Python (http://www.python.org) binding for Qt (http://www.trolltech.com). -It offers an easy way to embedd the Python scripting language into +It offers an easy way to embed the Python scripting language into your Qt applications. It makes heavy use of the QMetaObject system and thus requires Qt4.x. Licensing diff --git a/doxygen/doc.cfg b/doxygen/doc.cfg index 99b0655..2f4c01a 100644 --- a/doxygen/doc.cfg +++ b/doxygen/doc.cfg @@ -23,7 +23,7 @@ PROJECT_NAME = PythonQt # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 1.0 +PROJECT_NUMBER = 1.1 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. diff --git a/examples/CPPPyWrapperExample/CPPPyWrapperExample.cpp b/examples/CPPPyWrapperExample/CPPPyWrapperExample.cpp new file mode 100644 index 0000000..d4e0934 --- /dev/null +++ b/examples/CPPPyWrapperExample/CPPPyWrapperExample.cpp @@ -0,0 +1,34 @@ +#include +#include +int main (int argc, char* argv[]) { + QApplication app(argc, argv); + PythonQt::init(); + PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule(); + Q_ASSERT(!mainModule.isNull()); + { + // evaluate a python file embedded in executable as resource: + mainModule.evalFile(":eyed3tagger.py"); + PythonQtObjectPtr tag = mainModule.evalScript("EyeD3Tagger()\n", Py_eval_input); + Q_ASSERT(!tag.isNull()); + tag.call("setFileName", QVariantList() << "t.mp3"); + QVariant fn = tag.call("fileName", QVariantList()); + Q_ASSERT(fn.toString() == QString("t.mp3")); + } + qDebug() << "test1"; + { // alternative using import and loading it as a real module from sys.path + // import sys first + mainModule.evalScript(QString("import sys\n")); + // append the current directory to the sys.path + mainModule.evalScript(QString("sys.path.append('%1')\n").arg(QDir::currentPath())); + + mainModule.evalScript("import eyed3tagger\n"); + PythonQtObjectPtr tag = mainModule.evalScript("eyed3tagger.EyeD3Tagger()\n", Py_eval_input); + Q_ASSERT(!tag.isNull()); + tag.call("setFileName", QVariantList() << "t.mp3"); + QVariant fn = tag.call("fileName", QVariantList()); + Q_ASSERT(fn.toString() == QString("t.mp3")); + } + + qDebug() << "finished"; + return 0; +} diff --git a/examples/CPPPyWrapperExample/CPPPyWrapperExample.pro b/examples/CPPPyWrapperExample/CPPPyWrapperExample.pro new file mode 100644 index 0000000..931c034 --- /dev/null +++ b/examples/CPPPyWrapperExample/CPPPyWrapperExample.pro @@ -0,0 +1,9 @@ +CONFIG += debug +VPATH += +INCLUDEPATH += . $$(PYTHONQT_ROOT)/src /usr/include/python2.5 + +SOURCES += CPPPyWrapperExample.cpp + +LIBS += -L$$(PYTHONQT_ROOT)/lib -lPythonQt -lutil + +RESOURCES += CPPPyWrapperExample.qrc diff --git a/examples/CPPPyWrapperExample/CPPPyWrapperExample.qrc b/examples/CPPPyWrapperExample/CPPPyWrapperExample.qrc new file mode 100644 index 0000000..5c54cb0 --- /dev/null +++ b/examples/CPPPyWrapperExample/CPPPyWrapperExample.qrc @@ -0,0 +1,5 @@ + + + eyed3tagger.py + + diff --git a/examples/CPPPyWrapperExample/README.txt b/examples/CPPPyWrapperExample/README.txt new file mode 100644 index 0000000..4b5ba69 --- /dev/null +++ b/examples/CPPPyWrapperExample/README.txt @@ -0,0 +1,9 @@ +It also shows how to add user defined Python classes to the +embedded Python mainModule. +It also shows how to create objects in Python, +hold onto reference counted smart pointers to them from +a Qt application, and invoke methods on them via +the PythonQtObjectPtr interface. + + + diff --git a/examples/CPPPyWrapperExample/eyed3tagger.py b/examples/CPPPyWrapperExample/eyed3tagger.py new file mode 100644 index 0000000..78e522e --- /dev/null +++ b/examples/CPPPyWrapperExample/eyed3tagger.py @@ -0,0 +1,10 @@ +class EyeD3Tagger(): + def __init__(self, fileName = None): + if not fileName is None: + self.setFileName(fileName) + + def fileName(self): + return self.fn + + def setFileName(self, fileName): + self.fn = fileName diff --git a/src/PythonQtObjectPtr.cpp b/src/PythonQtObjectPtr.cpp index d424b52..5b66f65 100644 --- a/src/PythonQtObjectPtr.cpp +++ b/src/PythonQtObjectPtr.cpp @@ -82,3 +82,15 @@ QVariant PythonQtObjectPtr::call(const QString& callable, const QVariantList& ar return PythonQt::self()->call(_object, callable, args); } +bool PythonQtObjectPtr::fromVariant(const QVariant& variant) +{ + if (!variant.isNull()) { + setObject(qVariantValue(variant)); + return true; + } + else { + setObject(0); + return false; + } + +} diff --git a/src/PythonQtObjectPtr.h b/src/PythonQtObjectPtr.h index 5a15859..49c2238 100644 --- a/src/PythonQtObjectPtr.h +++ b/src/PythonQtObjectPtr.h @@ -55,13 +55,21 @@ public: 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) { _object = o; if (o) Py_INCREF(_object); } ~PythonQtObjectPtr() { if (_object) Py_DECREF(_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. + bool fromVariant(const QVariant& variant); + PythonQtObjectPtr &operator=(const PythonQtObjectPtr &p) { setObject(p.object()); return *this; @@ -72,6 +80,13 @@ public: return *this; } + + PythonQtObjectPtr &operator=(const QVariant& variant) { + fromVariant(variant); + return *this; + } + + bool operator==( const PythonQtObjectPtr &p ) const { return object() == p.object(); } @@ -133,6 +148,8 @@ public: //! 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); + + protected: