Avogadro
1.1.0
|
00001 /********************************************************************** 00002 PythonTool - PythonTool Tool for Avogadro 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 PYTHONTOOL_H 00026 #define PYTHONTOOL_H 00027 00028 #include <avogadro/global.h> 00029 #include <avogadro/tool.h> 00030 #include <boost/python.hpp> 00031 00032 #include <QObject> 00033 #include <QAction> 00034 00035 namespace Avogadro { 00036 00037 class PythonScript; 00038 00039 class PythonTool : public Tool 00040 { 00041 Q_OBJECT 00042 00043 public: 00045 explicit PythonTool(QObject *parent = 0, const QString &filename = QString("")); 00047 virtual ~PythonTool(); 00048 00050 00051 QString identifier() const; 00052 QString name() const; 00053 QString description() const; 00054 QString settingsTitle() const; 00055 QUndoCommand* mouseEvent(const QString &what, GLWidget *widget, QMouseEvent *event); 00056 QUndoCommand* mousePressEvent(GLWidget *widget, QMouseEvent *event); 00057 QUndoCommand* mouseReleaseEvent(GLWidget *widget, QMouseEvent *event); 00058 QUndoCommand* mouseMoveEvent(GLWidget *widget, QMouseEvent *event); 00059 QUndoCommand* mouseDoubleClickEvent(GLWidget *widget, QMouseEvent *event); 00060 QUndoCommand* wheelEvent(GLWidget *widget, QWheelEvent *event); 00061 bool paint(GLWidget *widget); 00062 QWidget *settingsWidget(); 00063 void writeSettings(QSettings &settings) const; 00064 void readSettings(QSettings &settings); 00066 00067 private: 00068 void loadScript(const QString &filename); 00069 00070 PythonScript *m_script; 00071 boost::python::object m_instance; 00072 QWidget *m_settingsWidget; 00073 QString m_identifier; 00074 00075 private Q_SLOTS: 00076 void settingsWidgetDestroyed(); 00077 }; 00078 00079 class PythonToolFactory : public QObject, public PluginFactory 00080 { 00081 Q_OBJECT 00082 Q_INTERFACES(Avogadro::PluginFactory) 00083 00084 public: 00085 PythonToolFactory(const QString &filename) : m_filename(filename) 00086 { 00087 PythonTool tool(0, filename); 00088 m_identifier = tool.identifier(); 00089 m_name = tool.name(); 00090 m_desc = tool.description(); 00091 } 00092 Plugin *createInstance(QObject *parent = 0) 00093 { 00094 return new PythonTool(parent, m_filename); 00095 } 00096 Plugin::Type type() const { return Plugin::ToolType; } 00097 QString identifier() const { return m_identifier; } 00098 QString name() const { return m_name; } 00099 QString description() const { return m_desc; } 00100 private: 00101 QString m_filename; 00102 QString m_identifier, m_name, m_desc; 00103 }; 00104 00105 00106 00107 } // end namespace Avogadro 00108 00109 #endif