void PythonExtension::loadScript(const QString &filename) { QFileInfo info(filename); initializePython(info.canonicalPath()); PythonThread pt; PythonScript *script = new PythonScript(filename); m_identifier = script->identifier(); if (script->module()) { // make sure there is an Extension class defined if (PyObject_HasAttrString(script->module().ptr(), "Extension")) { try { prepareToCatchError(); m_instance = script->module().attr("Extension")(); } catch (error_already_set const &) { catchError(); return; } // connect signal(s) if (PyObject_HasAttrString(m_instance.ptr(), "__pyqtSignals__")) { QObject *obj = extract<QObject*>(m_instance); connect(obj, SIGNAL(message(const QString&)), this, SIGNAL(message(const QString&))); } m_script = script; } else { delete script;
void PythonEngine::loadScript(const QString &filename) { QFileInfo info(filename); initializePython(info.canonicalPath()); PythonThread pt; PythonScript *script = new PythonScript(filename); m_identifier = script->identifier(); if(script->module()) { // make sure there is an Engine class defined if (PyObject_HasAttrString(script->module().ptr(), "Engine")) { try { prepareToCatchError(); // instatiate the new Engine m_instance = script->module().attr("Engine")(); } catch (error_already_set const &) { catchError(); return; } m_script = script; } else { delete script; PythonError::instance()->append(tr("PythonEngine: checking ") + filename + "..."); PythonError::instance()->append(tr(" - script has no 'Engine' class defined")); } } else { delete script; PythonError::instance()->append(tr("PythonEngine: checking ") + filename + "..."); PythonError::instance()->append(tr(" - no module")); } }
void PythonTool::loadScript(const QString &filename) { QFileInfo info(filename); initializePython(info.canonicalPath()); PythonThread pt; PythonScript *script = new PythonScript(filename); m_identifier = script->identifier(); if(script->module()) { // make sure there is a Tool class defined if (PyObject_HasAttrString(script->module().ptr(), "Tool")) { try { prepareToCatchError(); // instantiate the new tool m_instance = script->module().attr("Tool")(); // if we have a settings widget already, add the python content... if (m_settingsWidget) { if (PyObject_HasAttrString(m_instance.ptr(), "settingsWidget")) { QWidget *widget = extract<QWidget*>(m_instance.attr("settingsWidget")()); if (widget) m_settingsWidget->layout()->addWidget(widget); } } } catch (error_already_set const &) { catchError(); return; } m_script = script; } else { delete script; PythonError::instance()->append(tr("PythonTool: checking ") + filename + "..."); PythonError::instance()->append(tr(" - script has no 'Tool' class defined")); } } else { delete script; PythonError::instance()->append(tr("PythonTool: checking ") + filename + "..."); PythonError::instance()->append(tr(" - no module")); } }