Commit 31961900 authored by Pierre Kraemer's avatar Pierre Kraemer

add ability to load a Python script file

parent 6c8638bf
importPlugin = schnapps.loadPlugin("ImportSurface");
renderPlugin = schnapps.loadPlugin("Render");
renderVectorPlugin = schnapps.loadPlugin("RenderVector");
renderScalarPlugin = schnapps.loadPlugin("RenderScalar");
renderTopoSurfacePlugin = schnapps.loadPlugin("RenderTopoSurface");
differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface");
surfaceDeformationPlugin = schnapps.loadPlugin("SurfaceDeformation");
obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/midRes/cow_11k.off");
v = schnapps.getView("view_0");
schnapps.linkViewAndPlugin(v.getName(), renderPlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), renderVectorPlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), renderScalarPlugin.getName());
#schnapps.linkViewAndPlugin(v.getName(), renderTopoSurfacePlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), surfaceDeformationPlugin.getName());
schnapps.linkViewAndMap(v.getName(), obj.getName());
differentialPropertiesPlugin.computeNormal(obj.getName());
differentialPropertiesPlugin.computeCurvature(obj.getName());
importPlugin = schnapps.loadPlugin("ImportSurface");
renderPlugin = schnapps.loadPlugin("Render");
\ No newline at end of file
......@@ -33,6 +33,7 @@
</property>
<addaction name="actionShowHideDock"/>
<addaction name="actionShowHidePythonDock"/>
<addaction name="actionLoadPythonScript"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
......@@ -116,6 +117,14 @@
<string>Show/Hide Python Dock</string>
</property>
</action>
<action name="actionLoadPythonScript">
<property name="text">
<string>Load Python Script</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
</widget>
<resources>
<include location="../resources/resources.qrc"/>
......
......@@ -193,6 +193,7 @@ public slots:
void cb_showHideDock();
void cb_showHidePythonDock();
void cb_loadPythonScript();
void cb_showCamerasDialog();
void cb_showPluginsDialog();
......
......@@ -30,7 +30,7 @@ int main(int argc, char* argv[])
schnapps.show();
pythonContext.addObject("schnapps", &schnapps);
QFileInfo fi(app.applicationDirPath() + QString("/init.py"));
QFileInfo fi(app.applicationDirPath() + QString("/schnappsInit.py"));
if(fi.exists())
pythonContext.evalFile(fi.filePath());
......
......@@ -6,6 +6,7 @@
#include <QDockWidget>
#include <QPluginLoader>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QDir>
#include <QKeyEvent>
......@@ -66,6 +67,7 @@ Window::Window(const QString& appPath, PythonQtObjectPtr& pythonContext, PythonQ
m_pythonDock->setWidget(&m_pythonConsole);
connect(actionShowHidePythonDock, SIGNAL(triggered()), this, SLOT(cb_showHidePythonDock()));
connect(actionLoadPythonScript, SIGNAL(triggered()), this, SLOT(cb_loadPythonScript()));
m_centralLayout = new QVBoxLayout(centralwidget);
......@@ -453,7 +455,7 @@ void Window::registerPluginsDirectory(const QString& path)
Plugin* Window::loadPlugin(const QString& pluginName)
{
if (h_plugins.contains(pluginName))
return NULL;
return h_plugins[pluginName];
if (m_availablePlugins.contains(pluginName))
{
......@@ -492,13 +494,13 @@ Plugin* Window::loadPlugin(const QString& pluginName)
// if loading fails
else
{
std::cout << "loadPlugin: loader.instance() failed" << std::endl << loader.errorString().toStdString() << std::endl;
// std::cout << "loadPlugin: loader.instance() failed" << std::endl << loader.errorString().toStdString() << std::endl;
return NULL;
}
}
else
{
std::cout << "loadPlugin: plugin not found (" << pluginName.toStdString() << ")" << std::endl;
// std::cout << "loadPlugin: plugin not found (" << pluginName.toStdString() << ")" << std::endl;
return NULL;
}
}
......@@ -750,6 +752,14 @@ void Window::cb_showHidePythonDock()
m_pythonDock->setVisible(m_pythonDock->isHidden());
}
void Window::cb_loadPythonScript()
{
QString fileName = QFileDialog::getOpenFileName(this, "Load Python script", getAppPath(), "Python script (*.py)");
QFileInfo fi(fileName);
if(fi.exists())
m_pythonContext.evalFile(fi.filePath());
}
void Window::cb_showCamerasDialog()
{
m_camerasDialog->show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment