Skip to content
Snippets Groups Projects
Commit f816d4df authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add ability to load python scripts instead of python module.

parent f978e0b1
No related branches found
No related tags found
No related merge requests found
......@@ -98,8 +98,10 @@ namespace gepetto {
/// class PythonQt.QtGui.QDockWidget
void loadModulePlugin(QString moduleName);
void unloadModulePlugin(QString moduleName);
void loadScriptPlugin(QString moduleName, QString fileName);
private:
void loadPlugin(QString moduleName, PythonQtObjectPtr module);
void unloadModulePlugin(PythonQtObjectPtr module);
void addSignalHandlersToPlugin(PythonQtObjectPtr plugin);
......
......@@ -95,9 +95,24 @@ namespace gepetto {
fd->deleteLater();
}
void PythonWidget::loadScriptPlugin(QString moduleName, QString fileName)
{
PythonQt* pqt = PythonQt::self();
PythonQtObjectPtr module = pqt->createModuleFromFile (moduleName, fileName);
if (pqt->handleError()) {
return;
}
if (module.isNull()) {
pqt->handleError();
qDebug() << "Enable to load module" << moduleName << "from script"
<< fileName;
return;
}
loadPlugin (moduleName, module);
}
void PythonWidget::loadModulePlugin(QString moduleName)
{
MainWindow* main = MainWindow::instance();
PythonQt* pqt = PythonQt::self();
PythonQtObjectPtr module = pqt->importModule (moduleName);
if (pqt->handleError()) {
......@@ -108,6 +123,13 @@ namespace gepetto {
qDebug() << "Enable to load module" << moduleName;
return;
}
loadPlugin (moduleName, module);
}
void PythonWidget::loadPlugin(QString moduleName, PythonQtObjectPtr module)
{
PythonQt* pqt = PythonQt::self();
MainWindow* main = MainWindow::instance();
module.addObject("windowsManager", main->osg().get());
QString var = "pluginInstance";
......
......@@ -176,8 +176,18 @@ namespace gepetto {
pluginManager_.initPlugin (name);
#if GEPETTO_GUI_HAS_PYTHONQT
PythonWidget* pw = mw->pythonWidget();
foreach (QString name, pyplugins_)
pw->loadModulePlugin (name);
foreach (QString name, pyplugins_) {
if (name.endsWith (".py")) {
QFileInfo fi (name);
QString moduleName = fi.baseName();
QString script;
if (fi.isAbsolute()) script = name;
else script = QDir::currentPath() + QDir::separator() + name;
qDebug() << "Loading" << script << "into module" << moduleName;
pw->loadScriptPlugin (moduleName, script);
} else
pw->loadModulePlugin (name);
}
#endif
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment