MorphoGraphX
PythonProcess.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef PYTHONPROCESS_HPP
12 #define PYTHONPROCESS_HPP
13 
14 #include <Process.hpp>
15 
16 #if defined(WIN64) && defined(__GNUC__)
17 # define Py_InitModule4 Py_InitModule4_64
18 #endif
19 #include <Python.h>
20 #include <string>
21 
22 namespace mgx { namespace process
23 {
24  class PythonProcess;
25 
26  struct mgxPython_EXPORT mgx_Factory {
27  QString type;
29  };
30 
31  struct mgxPython_EXPORT mgx_Factory_Python {
32  PyObject_HEAD;
33  mgx_Factory intern;
34  PyObject* fact_dict;
35  };
36 
37  struct mgxPython_EXPORT mgx_Process {
38  QString type;
39  QString name;
40  int numParms;
42  };
43 
44  struct mgxPython_EXPORT mgx_Process_Python {
45  PyObject_HEAD;
46  PyObject* descr;
47  mgx_Process intern;
48  };
49 
50  extern mgxPython_EXPORT PyTypeObject factory_type;
51  extern mgxPython_EXPORT PyTypeObject process_type;
52 
60  class mgxPython_EXPORT PythonProcess : public GlobalProcess {
61  public:
62  PythonProcess(const GlobalProcess& process) : Process(process), GlobalProcess(process) {}
63 
64  bool initialize(QStringList& parms, QWidget* parent);
65 
66  bool operator()(const QStringList& parms)
67  {
68  return (*this)(parms[0]);
69  }
70 
71  bool operator()(QString filename);
72 
73  QString name() const { return "Python Script"; }
74  QString folder() const { return "Python"; }
75  QString description() const { return "Run python script"; }
76  QStringList parmNames() const { return QStringList() << "Script"; }
77  QStringList parmDescs() const { return QStringList() << "Script"; }
78  QStringList parmDefaults() const { return QStringList() << ""; }
79  QIcon icon() const { return QIcon(":/images/Python.png"); }
80 
81  mgx_Process_Python* createProcess(const QString& type, const QString& name);
82 
83  protected:
84  bool initPython(const QString& filename);
85  bool finalizePython();
86  bool addFactory(char* name);
87  bool removeFactory(char* name);
88  QString getTraceBack(PyObject* tb, int limit);
89 
90  PyObject* module, *main, *main_dict;
91  };
92 
93 }}
94 #endif
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: PythonProcess.hpp:66
Definition: PythonProcess.hpp:26
QString folder() const
Folder in which to place the process.
Definition: PythonProcess.hpp:74
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: PythonProcess.hpp:79
Definition: PythonProcess.hpp:37
Definition: PythonProcess.hpp:44
QStringList parmDescs() const
List of parameters descriptions.
Definition: PythonProcess.hpp:77
This process evaluate a Python script from which other processes can be called.
Definition: PythonProcess.hpp:60
QStringList parmDefaults() const
List of default parms.
Definition: PythonProcess.hpp:78
Definition: PythonProcess.hpp:31
QStringList parmNames() const
List of named parameters.
Definition: PythonProcess.hpp:76
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
File containing the definition of a Process.
QString name() const
Returns the name of the process.
Definition: PythonProcess.hpp:73
This is the main process class, the one all process inherit from.
Definition: Process.hpp:258
Global processes have full mutable access to all properties of the process.
Definition: Process.hpp:904
This namespace contains all the classes needed to define processes.
QString description() const
Returns a description of the process for the GUI.
Definition: PythonProcess.hpp:75