MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PythonProcess.hpp
1 #ifndef PYTHONPROCESS_HPP
2 #define PYTHONPROCESS_HPP
3 
4 #include <Process.hpp>
5 
6 #if defined(WIN64) && defined(__GNUC__)
7 # define Py_InitModule4 Py_InitModule4_64
8 #endif
9 #include <Python.h>
10 #include <string>
11 
12 namespace mgx { namespace process
13 {
14  class PythonProcess;
15 
16  struct mgxPython_EXPORT mgx_Factory {
17  QString type;
18  PythonProcess* process;
19  };
20 
21  struct mgxPython_EXPORT mgx_Factory_Python {
22  PyObject_HEAD;
23  mgx_Factory intern;
24  PyObject* fact_dict;
25  };
26 
27  struct mgxPython_EXPORT mgx_Process {
28  QString type;
29  QString name;
30  int numParms;
31  PythonProcess* process;
32  };
33 
34  struct mgxPython_EXPORT mgx_Process_Python {
35  PyObject_HEAD;
36  PyObject* descr;
37  mgx_Process intern;
38  };
39 
40  extern mgxPython_EXPORT PyTypeObject factory_type;
41  extern mgxPython_EXPORT PyTypeObject process_type;
42 
50  class mgxPython_EXPORT PythonProcess : public GlobalProcess {
51  public:
52  PythonProcess(const GlobalProcess& process) : Process(process), GlobalProcess(process) {}
53 
54  bool initialize(QStringList& parms, QWidget* parent);
55 
56  bool operator()(const QStringList& parms)
57  {
58  return (*this)(parms[0]);
59  }
60 
61  bool operator()(QString filename);
62 
63  QString name() const { return "Python Script"; }
64  QString folder() const { return "Python"; }
65  QString description() const { return "Run python script"; }
66  QStringList parmNames() const { return QStringList() << "Script"; }
67  QStringList parmDescs() const { return QStringList() << "Script"; }
68  QStringList parmDefaults() const { return QStringList() << ""; }
69  QIcon icon() const { return QIcon(":/images/Python.png"); }
70 
71  mgx_Process_Python* createProcess(const QString& type, const QString& name);
72 
73  protected:
74  bool initPython(const QString& filename);
75  bool finalizePython();
76  bool addFactory(char* name);
77  bool removeFactory(char* name);
78  QString getTraceBack(PyObject* tb, int limit);
79 
80  PyObject* module, *main, *main_dict;
81  };
82 
83 }}
84 #endif
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: PythonProcess.hpp:56
AttribBase(const QString &name) const QString & name()
Default constructor of named attribute.
Definition: Attributes.hpp:54
Definition: PythonProcess.hpp:16
QString folder() const
Folder in which to place the process.
Definition: PythonProcess.hpp:64
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: PythonProcess.hpp:69
Definition: PythonProcess.hpp:27
Definition: PythonProcess.hpp:34
QStringList parmDescs() const
List of parameters descriptions.
Definition: PythonProcess.hpp:67
This process evaluate a Python script from which other processes can be called.
Definition: PythonProcess.hpp:50
QStringList parmDefaults() const
List of default parms.
Definition: PythonProcess.hpp:68
Definition: PythonProcess.hpp:21
QStringList parmNames() const
List of named parameters.
Definition: PythonProcess.hpp:66
File containing the definition of a Process.
QString name() const
Returns the name of the process.
Definition: PythonProcess.hpp:63
This is the main process class, the one all process inherit from.
Definition: Process.hpp:248
Global processes have full mutable access to all properties of the process.
Definition: Process.hpp:894
QString description() const
Returns a description of the process for the GUI.
Definition: PythonProcess.hpp:65