MorphoGraphX  2.0-1-227
PythonProcess.hpp
Go to the documentation of this file.
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
23 {
24  class PythonProcess;
25 
26  struct mgxPython_EXPORT mgx_Factory
27  {
29  };
30 
31  struct mgxPython_EXPORT mgx_Factory_Python
32  {
35  PyObject* fact_dict;
36  };
37 
38  struct mgxPython_EXPORT mgx_Process
39  {
40  QString name;
41  int numParms;
43  };
44 
45  struct mgxPython_EXPORT mgx_Process_Python
46  {
48  PyObject* descr;
50  };
51 
52  extern mgxPython_EXPORT PyTypeObject factory_type;
53  extern mgxPython_EXPORT PyTypeObject process_type;
54 
62  class mgxPython_EXPORT PythonProcess : public Process
63  {
64  public:
65  PythonProcess(const Process& process) : Process(process)
66  {
67  setName("Misc/Python/Python Script");
68  setDesc("Run python script");
69  setIcon(QIcon(":/images/Python.png"));
70 
71  addParm("Script","Script to run","");
72  }
73 
74  bool initialize(QWidget* parent);
75 
76  bool run()
77  {
78  return run(parm("Script"));
79  }
80 
81  bool run(QString filename);
82 
83  mgx_Process_Python* createProcess(const QString& name);
84 
85  protected:
86  bool initPython(const QString& filename);
87  bool finalizePython();
88  bool addFactory(char* name);
89  bool removeFactory(char* name);
90  QString getTraceBack(PyObject* tb, int limit);
91 
92  PyObject* module, *main, *main_dict;
93  };
94 }
95 #endif
mgx::mgx_Process
Definition: PythonProcess.hpp:38
mgx::mgx_Process_Python::PyObject_HEAD
PyObject_HEAD
Definition: PythonProcess.hpp:47
mgx::PythonProcess::PythonProcess
PythonProcess(const Process &process)
Definition: PythonProcess.hpp:65
Process.hpp
mgx::mgx_Factory_Python
Definition: PythonProcess.hpp:31
mgx::mgx_Process::name
QString name
Definition: PythonProcess.hpp:40
mgx::mgx_Process_Python
Definition: PythonProcess.hpp:45
mgx::factory_type
mgxPython_EXPORT PyTypeObject factory_type
mgx::PythonProcess
Definition: PythonProcess.hpp:62
mgx::PythonProcess::module
PyObject * module
Definition: PythonProcess.hpp:92
mgx::mgx_Process_Python::descr
PyObject * descr
Definition: PythonProcess.hpp:48
mgx::mgx_Factory::process
PythonProcess * process
Definition: PythonProcess.hpp:28
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::mgx_Process::process
PythonProcess * process
Definition: PythonProcess.hpp:42
mgx::mgx_Factory_Python::PyObject_HEAD
PyObject_HEAD
Definition: PythonProcess.hpp:33
mgx::Process
Definition: Process.hpp:219
mgx::mgx_Factory_Python::intern
mgx_Factory intern
Definition: PythonProcess.hpp:34
mgx::PythonProcess::run
bool run()
Runs the process.
Definition: PythonProcess.hpp:76
mgx::mgx_Process_Python::intern
mgx_Process intern
Definition: PythonProcess.hpp:49
mgx::mgx_Factory
Definition: PythonProcess.hpp:26
mgx::mgx_Process::numParms
int numParms
Definition: PythonProcess.hpp:41
mgx::mgx_Factory_Python::fact_dict
PyObject * fact_dict
Definition: PythonProcess.hpp:35
mgx::process_type
mgxPython_EXPORT PyTypeObject process_type