Commit 31961900 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

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 @@ ...@@ -33,6 +33,7 @@
</property> </property>
<addaction name="actionShowHideDock"/> <addaction name="actionShowHideDock"/>
<addaction name="actionShowHidePythonDock"/> <addaction name="actionShowHidePythonDock"/>
<addaction name="actionLoadPythonScript"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
...@@ -116,6 +117,14 @@ ...@@ -116,6 +117,14 @@
<string>Show/Hide Python Dock</string> <string>Show/Hide Python Dock</string>
</property> </property>
</action> </action>
<action name="actionLoadPythonScript">
<property name="text">
<string>Load Python Script</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="../resources/resources.qrc"/> <include location="../resources/resources.qrc"/>
......
...@@ -193,6 +193,7 @@ public slots: ...@@ -193,6 +193,7 @@ public slots:
void cb_showHideDock(); void cb_showHideDock();
void cb_showHidePythonDock(); void cb_showHidePythonDock();
void cb_loadPythonScript();
void cb_showCamerasDialog(); void cb_showCamerasDialog();
void cb_showPluginsDialog(); void cb_showPluginsDialog();
......
...@@ -30,7 +30,7 @@ int main(int argc, char* argv[]) ...@@ -30,7 +30,7 @@ int main(int argc, char* argv[])
schnapps.show(); schnapps.show();
pythonContext.addObject("schnapps", &schnapps); pythonContext.addObject("schnapps", &schnapps);
QFileInfo fi(app.applicationDirPath() + QString("/init.py")); QFileInfo fi(app.applicationDirPath() + QString("/schnappsInit.py"));
if(fi.exists()) if(fi.exists())
pythonContext.evalFile(fi.filePath()); pythonContext.evalFile(fi.filePath());
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <QDockWidget> #include <QDockWidget>
#include <QPluginLoader> #include <QPluginLoader>
#include <QFile> #include <QFile>
#include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QKeyEvent> #include <QKeyEvent>
...@@ -66,6 +67,7 @@ Window::Window(const QString& appPath, PythonQtObjectPtr& pythonContext, PythonQ ...@@ -66,6 +67,7 @@ Window::Window(const QString& appPath, PythonQtObjectPtr& pythonContext, PythonQ
m_pythonDock->setWidget(&m_pythonConsole); m_pythonDock->setWidget(&m_pythonConsole);
connect(actionShowHidePythonDock, SIGNAL(triggered()), this, SLOT(cb_showHidePythonDock())); connect(actionShowHidePythonDock, SIGNAL(triggered()), this, SLOT(cb_showHidePythonDock()));
connect(actionLoadPythonScript, SIGNAL(triggered()), this, SLOT(cb_loadPythonScript()));
m_centralLayout = new QVBoxLayout(centralwidget); m_centralLayout = new QVBoxLayout(centralwidget);
...@@ -453,7 +455,7 @@ void Window::registerPluginsDirectory(const QString& path) ...@@ -453,7 +455,7 @@ void Window::registerPluginsDirectory(const QString& path)
Plugin* Window::loadPlugin(const QString& pluginName) Plugin* Window::loadPlugin(const QString& pluginName)
{ {
if (h_plugins.contains(pluginName)) if (h_plugins.contains(pluginName))
return NULL; return h_plugins[pluginName];
if (m_availablePlugins.contains(pluginName)) if (m_availablePlugins.contains(pluginName))
{ {
...@@ -492,13 +494,13 @@ Plugin* Window::loadPlugin(const QString& pluginName) ...@@ -492,13 +494,13 @@ Plugin* Window::loadPlugin(const QString& pluginName)
// if loading fails // if loading fails
else 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; return NULL;
} }
} }
else else
{ {
std::cout << "loadPlugin: plugin not found (" << pluginName.toStdString() << ")" << std::endl; // std::cout << "loadPlugin: plugin not found (" << pluginName.toStdString() << ")" << std::endl;
return NULL; return NULL;
} }
} }
...@@ -750,6 +752,14 @@ void Window::cb_showHidePythonDock() ...@@ -750,6 +752,14 @@ void Window::cb_showHidePythonDock()
m_pythonDock->setVisible(m_pythonDock->isHidden()); 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() void Window::cb_showCamerasDialog()
{ {
m_camerasDialog->show(); 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