Avogadro
1.1.0
|
00001 /********************************************************************** 00002 PythonEngine - Allow python scripts to be used as engines. 00003 00004 Copyright (C) 2008,2009 Tim Vandermeersch 00005 00006 This file is part of the Avogadro molecular editor project. 00007 For more information, see <http://avogadro.openmolecules.net/> 00008 00009 Avogadro is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 Avogadro is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00022 02110-1301, USA. 00023 **********************************************************************/ 00024 00025 #ifndef PYTHONENGINE_H 00026 #define PYTHONENGINE_H 00027 00028 #include <avogadro/global.h> 00029 #include <avogadro/engine.h> 00030 #include <boost/python.hpp> 00031 00032 namespace Avogadro { 00033 00034 class PythonScript; 00035 00036 class PythonEngine : public Engine 00037 { 00038 Q_OBJECT 00039 00040 public: 00042 explicit PythonEngine(QObject *parent = 0, const QString &filename = QString()); 00044 ~PythonEngine(); 00046 Engine *clone() const; 00047 00048 00050 00051 QString identifier() const; 00052 QString name() const; 00053 QString description() const; 00054 Layers layers() const; 00055 double transparencyDepth() const; 00056 bool renderOpaque(PainterDevice *pd); 00057 QWidget* settingsWidget(); 00058 void writeSettings(QSettings &settings) const; 00059 void readSettings(QSettings &settings); 00061 00062 private: 00063 void loadScript(const QString &filename); 00064 00065 PythonScript *m_script; 00066 boost::python::object m_instance; 00067 QWidget *m_settingsWidget; 00068 QString m_identifier; 00069 private Q_SLOTS: 00070 void settingsWidgetDestroyed(); 00071 }; 00072 00074 class PythonEngineFactory : public QObject, public PluginFactory 00075 { 00076 Q_OBJECT 00077 Q_INTERFACES(Avogadro::PluginFactory) 00078 00079 public: 00080 PythonEngineFactory(const QString &filename) : m_filename(filename) 00081 { 00082 PythonEngine engine(0, filename); 00083 m_identifier = engine.identifier(); 00084 m_name = engine.name(); 00085 m_desc = engine.description(); 00086 } 00087 Plugin* createInstance(QObject *parent = 0) 00088 { 00089 return new PythonEngine(parent, m_filename); 00090 } 00091 Plugin::Type type() const { return Plugin::EngineType; } 00092 QString identifier() const { return m_identifier; } 00093 QString name() const { return m_name; } 00094 QString description() const { return m_desc; } 00095 private: 00096 QString m_filename; 00097 QString m_identifier, m_name, m_desc; 00098 }; 00099 00100 } // end namespace Avogadro 00101 00102 #endif