itom  4.1.0
pythonCommon.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PYTHONCOMMON_H
24 #define PYTHONCOMMON_H
25 
26 #ifndef NPY_1_7_API_VERSION
27  #define NPY_1_7_API_VERSION 0x00000007
28 #endif
29 #ifndef NPY_1_8_API_VERSION
30  #define NPY_1_8_API_VERSION 0x00000008
31 #endif
32 
33 #ifndef Q_MOC_RUN
34  /* includes */
35  //python
36  // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3
37  #if (defined _DEBUG) && (defined WIN32)
38  #undef _DEBUG
39  #include "python/pythonWrapper.h"
40  #define _DEBUG
41  #else
42  #include "python/pythonWrapper.h"
43  #endif
44 #endif
45 
46 #include "../../common/sharedStructures.h"
47 
48 #include <qvector.h>
49 #include <qvariant.h>
50 
51 namespace ito
52 {
53 
54  ito::RetVal checkAndSetParamVal(PyObject *tempObj, ito::Param *param, int *set);
55  ito::RetVal checkAndSetParamVal(PyObject *pyObj, const ito::Param *defaultParam, ito::ParamBase &outParam, int *set);
57  PyObject* printOutParams(const QVector<ito::Param> *params, bool asErr, bool addInfos, const int num, bool printToStdStream = true);
58  PyObject *parseParamMetaAsDict(const ito::ParamMeta *meta);
59  void errOutInitParams(const QVector<ito::Param> *params, const int num, const char *reason);
60  ito::RetVal parseInitParams(const QVector<ito::Param> *defaultParamListMand, const QVector<ito::Param> *defaultParamListOpt, PyObject *args, PyObject *kwds, QVector<ito::ParamBase> &paramListMandOut, QVector<ito::ParamBase> &paramListOptOut);
61  ito::RetVal copyParamVector(const QVector<ito::ParamBase> *paramVecIn, QVector<ito::ParamBase> &paramVecOut);
62  ito::RetVal copyParamVector(const QVector<ito::Param> *paramVecIn, QVector<ito::Param> &paramVecOut);
63  ito::RetVal copyParamVector(const QVector<ito::Param> *paramVecIn, QVector<ito::ParamBase> &paramVecOut);
64  ito::RetVal createEmptyParamBaseFromParamVector(const QVector<ito::Param> *paramVecIn, QVector<ito::ParamBase> &paramVecOut);
65 
67  ito::RetVal findAndDeleteReservedInitKeyWords(PyObject *kwds, bool * enableAutoLoadParams);
68 
69  PyObject* buildFilterOutputValues(QVector<QVariant> *outVals, ito::RetVal &retValue);
70 
72  {
73  public:
74 
76  /*
77  The values must only be changed in accordance to the
78  argument 'mode' of the method 'check' of the python
79  module itomSyntaxCheck.py (itom-packages subfolder).
80 
81  @seealso WidgetPropEditorCodeCheckers
82  */
84  {
89  };
90 
93  {
94  TypeInfo = 0,
96  TypeError = 2
97  };
98 
99  enum tErrMsg
100  {
101  noMsg = 0,
102  loadPlugin = 1,
103  execFunc = 2,
104  invokeFunc = 3,
105  getProperty = 4,
106  runFunc = 5
107  };
108 
109  static bool transformRetValToPyException(ito::RetVal &retVal, PyObject *exceptionIfError = PyExc_RuntimeError, PyObject *exceptionIfWarning = PyExc_RuntimeWarning);
110  static bool setReturnValueMessage(ito::RetVal &retVal, const QString &objName, const tErrMsg &errorMSG, PyObject *exceptionIfError = PyExc_RuntimeError, PyObject *exceptionIfWarning = PyExc_RuntimeWarning);
111  static bool setReturnValueMessage(ito::RetVal &retVal, const char *objName, const tErrMsg &errorMSG, PyObject *exceptionIfError = PyExc_RuntimeError, PyObject *exceptionIfWarning = PyExc_RuntimeWarning);
112  static ito::RetVal checkForPyExceptions(bool clearError = true);
113  };
114 
115 } //end namespace ito
116 
117 #endif
CodeCheckerMessageType
Definition: pythonCommon.h:92
ito::RetVal createEmptyParamBaseFromParamVector(const QVector< ito::Param > *paramVecIn, QVector< ito::ParamBase > &paramVecOut)
This function searches for reserves Keywords (e.g. autoLoadParams) sets the corresponding bool parame...
chose Flake8 if flake8 is available, else chose PyFlakes if pyflakes is available, else No Checker
Definition: pythonCommon.h:88
Class for managing status values (like errors or warning)
Definition: retVal.h:54
class for parameter handling e.g. to pass paramters to plugins
Definition: param.h:283
CodeCheckerMode
< mode that can be chosen for the code checker
Definition: pythonCommon.h:83
the assigned message is displayed as information (blue dot)
Definition: pythonCommon.h:94
void errOutInitParams(const QVector< ito::Param > *params, const int num, const char *reason)
Definition: pythonCommon.cpp:993
no code checker active
Definition: pythonCommon.h:85
the assigned message is displayed as error (bug symbol)
Definition: pythonCommon.h:96
ito::RetVal checkAndSetParamVal(PyObject *tempObj, ito::Param *param, int *set)
Definition: pythonCommon.cpp:53
Definition: apiFunctionsGraph.cpp:39
the assigned message is displayed as warning (orange dot)
Definition: pythonCommon.h:95
syntax error and further static code analysis based on PyFlakes
Definition: pythonCommon.h:86
extended code checks (syntax, style, doc style, complexity...) based on Flake8
Definition: pythonCommon.h:87
ito::RetVal copyParamVector(const QVector< ito::ParamBase > *paramVecIn, QVector< ito::ParamBase > &paramVecOut)
Definition: pythonCommon.cpp:1331
ito::RetVal findAndDeleteReservedInitKeyWords(PyObject *kwds, bool *enableAutoLoadParams)
Definition: pythonCommon.cpp:1394
Definition: pythonCommon.h:71
Base class for all meta-information classes.
Definition: paramMeta.h:59
Definition: param.h:67