From 72837eb4c23c3e69e3b3a75e27b643ec2e051df2 2010-03-10 20:28:04 From: florianlink Date: 2010-03-10 20:28:04 Subject: [PATCH] enabled shell injection and added data() for bytearray and addAction for QMenu/Bar and QToolBar, moved QByteArray to builtin classes git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@161 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/generator/shellgenerator.cpp b/generator/shellgenerator.cpp index 5ed5eda..c23b280 100644 --- a/generator/shellgenerator.cpp +++ b/generator/shellgenerator.cpp @@ -345,6 +345,7 @@ bool ShellGenerator::isBuiltIn(const QString& name) { builtIn.insert("QPixmap"); builtIn.insert("QBrush"); builtIn.insert("QBitArray"); + builtIn.insert("QByteArray"); builtIn.insert("QPalette"); builtIn.insert("QPen"); builtIn.insert("QIcon"); diff --git a/generator/shellheadergenerator.cpp b/generator/shellheadergenerator.cpp index 5305816..f2d6e22 100644 --- a/generator/shellheadergenerator.cpp +++ b/generator/shellheadergenerator.cpp @@ -293,10 +293,9 @@ void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c } } - // writeInjectedCode(s, meta_class); - - // s << endl << " QScriptValue __qtscript_self;" << endl; + writeInjectedCode(s, meta_class); + s << "};" << endl << endl << "#endif // " << include_block << endl; @@ -306,7 +305,7 @@ void ShellHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaC { CodeSnipList code_snips = meta_class->typeEntry()->codeSnips(); foreach (const CodeSnip &cs, code_snips) { - if (cs.language == TypeSystem::ShellDeclaration) { + if (cs.language == TypeSystem::PyWrapperDeclaration) { s << cs.code() << endl; } } diff --git a/generator/shellimplgenerator.cpp b/generator/shellimplgenerator.cpp index 5f28e0a..6b7c874 100644 --- a/generator/shellimplgenerator.cpp +++ b/generator/shellimplgenerator.cpp @@ -300,14 +300,16 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla s << " return result;" << endl; s << "}" << endl << endl; } - + + writeInjectedCode(s, meta_class); + } void ShellImplGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class) { CodeSnipList code_snips = meta_class->typeEntry()->codeSnips(); foreach (const CodeSnip &cs, code_snips) { - if (cs.language == TypeSystem::ShellCode) { + if (cs.language == TypeSystem::PyWrapperCode) { s << cs.code() << endl; } } diff --git a/generator/typesystem.cpp b/generator/typesystem.cpp index c3c1dbc..b91c443 100644 --- a/generator/typesystem.cpp +++ b/generator/typesystem.cpp @@ -1278,6 +1278,8 @@ bool Handler::startElement(const QString &, const QString &n, languageNames["destructor-function"] = TypeSystem::DestructorFunction; languageNames["constructors"] = TypeSystem::Constructors; languageNames["interface"] = TypeSystem::Interface; + languageNames["pywrap-cpp"] = TypeSystem::PyWrapperCode; + languageNames["pywrap-h"] = TypeSystem::PyWrapperDeclaration; } QString className = attributes["class"].toLower(); diff --git a/generator/typesystem.h b/generator/typesystem.h index 9220a72..4c05102 100644 --- a/generator/typesystem.h +++ b/generator/typesystem.h @@ -101,6 +101,8 @@ namespace TypeSystem { DestructorFunction = 0x0020, Constructors = 0x0040, Interface = 0x0080, + PyWrapperCode = 0x0100, + PyWrapperDeclaration = 0x0200, // masks All = TargetLangCode diff --git a/generator/typesystem_core-common.xml b/generator/typesystem_core-common.xml index 9ae2da0..150ec99 100644 --- a/generator/typesystem_core-common.xml +++ b/generator/typesystem_core-common.xml @@ -31,6 +31,8 @@ + + @@ -898,10 +900,8 @@ - - @@ -915,7 +915,6 @@ - diff --git a/generator/typesystem_core-qtscript.xml b/generator/typesystem_core-qtscript.xml index f6fac12..2d2049d 100644 --- a/generator/typesystem_core-qtscript.xml +++ b/generator/typesystem_core-qtscript.xml @@ -350,21 +350,23 @@ - + + PyObject* data(QByteArray* b) { + if (b->data()) { + return PyString_FromStringAndSize(b->data(), b->size()); + } else { + Py_INCREF(Py_None); + return Py_None; + } + } + + Q_DECLARE_METATYPE(QScriptValue) - - - - - - - - - + diff --git a/generator/typesystem_core.xml b/generator/typesystem_core.xml index d60245e..76a1852 100644 --- a/generator/typesystem_core.xml +++ b/generator/typesystem_core.xml @@ -63,6 +63,8 @@ + + @@ -1138,10 +1140,8 @@ - - @@ -1155,25 +1155,26 @@ - - + + PyObject* data(QByteArray* b) { + if (b->data()) { + return PyString_FromStringAndSize(b->data(), b->size()); + } else { + Py_INCREF(Py_None); + return Py_None; + } + } + + Q_DECLARE_METATYPE(QScriptValue) - - - - - - - - - + diff --git a/generator/typesystem_gui-common.xml b/generator/typesystem_gui-common.xml index 7249c63..89be8d4 100644 --- a/generator/typesystem_gui-common.xml +++ b/generator/typesystem_gui-common.xml @@ -1829,17 +1829,6 @@ - - - - - - - - - - - @@ -1858,47 +1847,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -4458,16 +4410,6 @@ - - - - - - - - - - diff --git a/generator/typesystem_gui-qtscript.xml b/generator/typesystem_gui-qtscript.xml index e613952..cc1dcee 100644 --- a/generator/typesystem_gui-qtscript.xml +++ b/generator/typesystem_gui-qtscript.xml @@ -553,6 +553,56 @@ + + + QAction* addAction (QMenu* menu, const QString & text, PyObject* callable, const QKeySequence & shortcut = 0) { + QAction* a = menu->addAction(text); + a->setShortcut(shortcut); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + + QAction* addAction (QMenu* menu, const QIcon& icon, const QString& text, PyObject* callable, const QKeySequence& shortcut = 0) + { + QAction* a = menu->addAction(text); + a->setIcon(icon); + a->setShortcut(shortcut); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + + + + + + QAction* addAction (QMenuBar* menu, const QString & text, PyObject* callable) + { + QAction* a = menu->addAction(text); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + + + + + + QAction* addAction (QToolBar* menu, const QString & text, PyObject* callable) + { + QAction* a = menu->addAction(text); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + + QAction* addAction (QToolBar* menu, const QIcon& icon, const QString& text, PyObject* callable) + { + QAction* a = menu->addAction(text); + a->setIcon(icon); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + + + diff --git a/generator/typesystem_gui.xml b/generator/typesystem_gui.xml index 96e6918..3f38e2c 100644 --- a/generator/typesystem_gui.xml +++ b/generator/typesystem_gui.xml @@ -2110,17 +2110,6 @@ - - - - - - - - - - - @@ -2139,47 +2128,28 @@ - - - - - - - - - - - + + + QAction* addAction (QMenu* menu, const QString & text, PyObject* callable, const QKeySequence & shortcut = 0) { + QAction* a = menu->addAction(text); + a->setShortcut(shortcut); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + + QAction* addAction (QMenu* menu, const QIcon& icon, const QString& text, PyObject* callable, const QKeySequence& shortcut = 0) + { + QAction* a = menu->addAction(text); + a->setIcon(icon); + a->setShortcut(shortcut); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2190,6 +2160,15 @@ + + + QAction* addAction (QMenuBar* menu, const QString & text, PyObject* callable) + { + QAction* a = menu->addAction(text); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + @@ -4874,16 +4853,6 @@ - - - - - - - - - - @@ -4902,6 +4871,23 @@ + + + QAction* addAction (QToolBar* menu, const QString & text, PyObject* callable) + { + QAction* a = menu->addAction(text); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } + + QAction* addAction (QToolBar* menu, const QIcon& icon, const QString& text, PyObject* callable) + { + QAction* a = menu->addAction(text); + a->setIcon(icon); + PythonQt::self()->addSignalHandler(a, SIGNAL(triggered(bool)), callable); + return a; + } +