Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/pythonextension_p.h
00001 /**********************************************************************
00002   PythonExtension - PythonExtension 
00003 
00004   Copyright (C) 2008 by Donald Ephraim Curtis
00005   Copyright (C) 2008,2009 by Tim Vandermeersch
00006 
00007   This file is part of the Avogadro molecular editor project.
00008   For more information, see <http://avogadro.openmolecules.net/>
00009 
00010   Avogadro is free software; you can redistribute it and/or modify
00011   it under the terms of the GNU General Public License as published by
00012   the Free Software Foundation; either version 2 of the License, or
00013   (at your option) any later version.
00014 
00015   Avogadro is distributed in the hope that it will be useful,
00016   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018   GNU General Public License for more details.
00019 
00020   You should have received a copy of the GNU General Public License
00021   along with this program; if not, write to the Free Software
00022   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00023   02110-1301, USA.
00024  ***********************************************************************/
00025 
00026 #ifndef PYTHONEXTENSION_H
00027 #define PYTHONEXTENSION_H
00028 
00029 #include <avogadro/extension.h>
00030 #include <avogadro/primitive.h>
00031 #include <avogadro/glwidget.h>
00032 #include <boost/python.hpp>
00033 
00034 #include <QWidget>
00035 #include <QList>
00036 #include <QDir>
00037 #include <QString>
00038 #include <QDateTime>
00039 #include <QFileInfo>
00040 #include <QHash>
00041 
00042 namespace Avogadro {
00043 
00044   class PythonScript;
00045 
00046   class PythonExtension : public Extension
00047   {
00048     Q_OBJECT
00049 
00050     public:
00052       explicit PythonExtension(QObject *parent = 0, const QString &filename = QString(""));
00054       virtual ~PythonExtension();
00055 
00057 
00058       QString identifier() const;
00059       QString name() const;
00060       QString description() const;
00061       QList<QAction *> actions() const;
00062       QString menuPath(QAction *action) const;
00063       QUndoCommand* performAction(QAction *action, GLWidget *widget);
00064       QDockWidget* dockWidget();
00065       void writeSettings(QSettings &settings) const;
00066       void readSettings(QSettings &settings);
00068 
00069     public Q_SLOTS:
00070       void dockWidgetDestroyed();
00071       bool paint(GLWidget *widget);
00072 
00073     private:
00074       void loadScript(const QString &filename);
00075 
00076       PythonScript          *m_script;
00077       boost::python::object  m_instance;
00078       QDockWidget           *m_dockWidget;
00079       QString                m_identifier;
00080   };
00081 
00082   class PythonExtensionFactory : public QObject, public PluginFactory
00083   {
00084     Q_OBJECT
00085     Q_INTERFACES(Avogadro::PluginFactory)
00086 
00087     public:
00088       PythonExtensionFactory(const QString &filename) : m_filename(filename)
00089       {
00090         PythonExtension extension(0, filename);
00091         m_identifier = extension.identifier();
00092         m_name = extension.name();
00093         m_desc = extension.description();
00094       }
00095       Plugin* createInstance(QObject *parent = 0)
00096       {
00097         return new PythonExtension(parent, m_filename);
00098       }
00099       Plugin::Type type() const { return Plugin::ExtensionType; }
00100       QString identifier() const { return m_identifier; }
00101       QString name() const { return m_name; }
00102       QString description() const { return m_desc; }
00103     private:
00104       QString m_filename;
00105       QString m_identifier, m_name, m_desc;
00106   };
00107 
00108 } // end namespace Avogadro
00109 
00110 #endif