embeddedpyqt / src / embpyqt / embeddedpyqt.cpp

#include "embeddedpyqt.h"
#include "pythonize.h"
#include <QApplication>
#include <QVariant>
#include <QPushButton>
#include <qdebug.h>


EmbeddedPyQt *EmbeddedPyQt::_instance = 0;


EmbeddedPyQt::EmbeddedPyQt(QObject *parent) :
    QObject(parent)
{
    EmbeddedPyQt::_instance = this;
    setObjectName("embeddedPyQt");
    QApplication::instance()->setProperty("embedded_pyqt",
                                          qVariantFromValue((QObject*)this));
    python = new Pythonize();
    Q_ASSERT(python);
}


void EmbeddedPyQt::init(const QString &filename) {
    char *cfn = (char*)filename.toLocal8Bit().constData();
    python->runScript(cfn);
    //python->appendToSysPath("");
    //python->runString("import embeddedpyqt");
}


void EmbeddedPyQt::deleteLater() {
    Q_ASSERT(python);
    QApplication::instance()->setProperty("embedded_pyqt",
                                          qVariantFromValue(NULL));
    delete(python);
}


void EmbeddedPyQt::raiseException(const QString &type, const QString &message) {
    QApplication::instance()->setProperty("embedded_pyqt_exception_type",
                                         qVariantFromValue(type));
    QApplication::instance()->setProperty("embedded_pyqt_exception_msg",
                                         qVariantFromValue(message));
    const char *cmsg = message.toLocal8Bit().constData();
    python->raiseException(cmsg);
}


void EmbeddedPyQt::clearException() {
    raiseException(NULL, NULL);
}

void* EmbeddedPyQt::metaObjectByName(const QString &name) {
    return (void*)classes[name];
}

QObject* EmbeddedPyQt::objectByName(const QString &name) {
    return (QObject*)objects[name];
}


QStringList EmbeddedPyQt::availableClasses() {
    return classes.keys();
}


QStringList EmbeddedPyQt::availableObjects() {
    return objects.keys();
}


void EmbeddedPyQt::registerMetaObject(const QMetaObject &mo) {
    classes[mo.className()] = &mo;
}


void EmbeddedPyQt::registerObject(const QObject &obj) {
    //connect(obj, SIGNAL(destroyed()), unregister_objec);
    objects[obj.objectName()] = &obj;
}


void EmbeddedPyQt::execute(const QString &command, bool globalContext) {
    emit executionRequested(command, globalContext);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.