23 #ifndef PYTHONENGINE_H 24 #define PYTHONENGINE_H 35 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION //see comment in pythonNpDataObject.cpp 40 #if (defined _DEBUG) && (defined WIN32) 42 #if (defined linux) | (defined CMAKE) 45 #include "numpy/arrayobject.h" 46 #elif (defined __APPLE__) | (defined CMAKE) 49 #include "numpy/arrayobject.h" 53 #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" 60 #include "numpy/arrayobject.h" 61 #elif (defined __APPLE__) 64 #include "numpy/arrayobject.h" 68 #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" 75 #include "pythonNpDataObject.h" 76 #include "pythonItom.h" 77 #include "pythonProxy.h" 78 #include "pythonStream.h" 80 #include "../models/breakPointModel.h" 81 #include "../../common/sharedStructuresQt.h" 82 #include "../../common/addInInterface.h" 83 #include "../global.h" 85 #include "pythonWorkspace.h" 87 #include <qstringlist.h> 100 class QDesktopWidget;
116 PyObject* getArguments()
const {
return m_argument; }
117 bool isValid()
const {
return (m_proxyObject != NULL); }
119 void setHandle(
const size_t &handle);
120 size_t getHandle()
const {
return m_handle; }
123 PyObject *m_argument;
136 Q_INVOKABLE
void pythonSetup(
ito::RetVal *retValue);
137 Q_INVOKABLE
ito::RetVal scanAndRunAutostartFolder(QString currentDirAfterScan = QString() );
141 inline ito::BreakPointModel *getBreakPointModel()
const {
return bpModel; }
142 inline bool isPythonBusy()
const {
return pythonState != ito::pyStateIdle; }
143 inline bool isPythonDebugging()
const {
return (pythonState == ito::pyStateDebuggingWaitingButBusy || pythonState == ito::pyStateDebugging || pythonState == ito::pyStateDebuggingWaiting); }
144 inline bool isPythonDebuggingAndWaiting()
const {
return pythonState == ito::pyStateDebuggingWaiting; }
145 inline bool execInternalCodeByDebugger()
const {
return m_executeInternalPythonCodeInDebugMode; }
146 inline void setExecInternalCodeByDebugger(
bool value) { m_executeInternalPythonCodeInDebugMode = value; }
148 void printPythonErrorWithoutTraceback();
149 void pythonDebugFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
150 void pythonRunFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
152 inline bool pySyntaxCheckAvailable()
const {
return (m_pyModSyntaxCheck != NULL); }
153 QList<int> parseAndSplitCommandInMainComponents(
const char *str, QByteArray &encoding)
const;
154 QString getPythonExecutable()
const {
return m_pythonExecutable; }
155 Qt::HANDLE getPythonThreadId()
const {
return m_pythonThreadId; }
157 static bool isInterruptQueued();
161 ito::RetVal runPyFile(
const QString &pythonFileName);
162 ito::RetVal debugFile(
const QString &pythonFileName);
165 ito::RetVal debugFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
166 ito::RetVal runFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
168 ito::RetVal modifyTracebackDepth(
int NrOfLevelsToPopAtFront = -1,
bool showTraceback =
true);
170 PyObject* setPyErrFromException(
const std::exception &exc);
172 #if QT_VERSION >= 0x050000 173 void connectNotify(
const QMetaMethod &signal);
175 void connectNotify(
const char* signal);
183 PyObject *getPyObjectByFullName(
bool globalNotLocal,
const QStringList &fullNameSplittedByDelimiter, QString *validVariableName = NULL);
184 PyObject *getPyObjectByFullName(
bool globalNotLocal,
const QString &fullName, QString *validVariableName = NULL);
186 void setGlobalDictionary(PyObject* mainDict = NULL);
187 void setLocalDictionary(PyObject* localDict);
189 void emitPythonDictionary(
bool emitGlobal,
bool emitLocal, PyObject* globalDict, PyObject* localDict);
191 ito::RetVal pickleDictionary(PyObject *dict,
const QString &filename);
192 ito::RetVal unpickleDictionary(PyObject *destinationDict,
const QString &filename,
bool overwrite);
195 void enqueueDbgCmd(ito::tPythonDbgCmd dbgCmd);
196 ito::tPythonDbgCmd dequeueDbgCmd();
197 bool DbgCommandsAvailable();
198 void clearDbgCmdLoop();
200 ito::RetVal pythonStateTransition(tPythonTransitions transition);
203 ito::RetVal pythonAddBreakpoint(
const QString &filename,
const int lineno,
const bool enabled,
const bool temporary,
const QString &condition,
const int ignoreCount,
int &pyBpNumber);
204 ito::RetVal pythonEditBreakpoint(
const int pyBpNumber,
const QString &filename,
const int lineno,
const bool enabled,
const bool temporary,
const QString &condition,
const int ignoreCount);
205 ito::RetVal pythonDeleteBreakpoint(
const int pyBpNumber);
209 static int queuedInterrupt(
void *state);
211 PyObject* getAndCheckIdentifier(
const QString &identifier,
ito::RetVal &retval)
const;
221 QMutex pythonStateChangeMutex;
222 QMutex dictChangeMutex;
223 QDesktopWidget *m_pDesktopWidget;
224 QQueue<ito::tPythonDbgCmd> debugCommandQueue;
225 ito::tPythonDbgCmd debugCommand;
227 ito::tPythonState pythonState;
229 ito::BreakPointModel *bpModel;
240 PyObject *m_pyModSyntaxCheck;
243 Qt::HANDLE m_pythonThreadId;
245 PyObject *dictUnicode;
247 QSet<ito::PyWorkspaceContainer*> m_mainWorkspaceContainer;
248 QSet<ito::PyWorkspaceContainer*> m_localWorkspaceContainer;
250 size_t m_pyFuncWeakRefAutoInc;
255 PyMethodDef* PythonAdditionalModuleITOM;
258 bool m_includeItomImportBeforeSyntaxCheck;
261 wchar_t *m_pUserDefinedPythonHome;
265 PyObject *modAutoReload;
266 PyObject *classAutoReload;
269 bool checkStringExec;
276 static PyMethodDef PyMethodItomDbg[];
277 static PyModuleDef PyModuleItomDbg;
278 static PyObject* PyInitItomDbg(
void);
279 static PyObject* PyDbgCommandLoop(PyObject *pSelf, PyObject *pArgs);
285 static QMutex instatiated;
286 static QMutex instancePtrProtection;
287 static QString fctHashPrefix;
291 QAtomicInt m_interruptCounter;
298 void pythonDebugPositionChanged(QString filename,
int lineNo);
299 void pythonStateChanged(tPythonTransitions pyTransition);
302 void pythonCurrentDirChanged();
303 void updateCallStack(QStringList filenames, IntList lines, QStringList methods);
304 void deleteCallStack();
306 void pythonSetCursor(
const Qt::CursorShape cursor);
307 void pythonResetCursor();
308 void pythonAutoReloadChanged(
bool enabled,
bool checkFile,
bool checkCmd,
bool checkFct);
309 void clearCommandLine();
310 void startInputCommandLine(QSharedPointer<QByteArray> buffer,
ItomSharedSemaphore *semaphore);
313 void pythonRunString(QString cmd);
314 void pythonDebugString(QString cmd);
315 void pythonExecStringFromCommandLine(QString cmd);
316 void pythonRunFile(QString filename);
317 void pythonDebugFile(QString filename);
318 void pythonRunStringOrFunction(QString cmdOrFctHash);
319 void pythonDebugStringOrFunction(QString cmdOrFctHash);
320 void pythonInterruptExecution();
321 void pythonDebugCommand(tPythonDbgCmd cmd);
323 void setAutoReloader(
bool enabled,
bool checkFile,
bool checkCmd,
bool checkFct);
327 void propertiesChanged();
329 void pythonSyntaxCheck(
const QString &code, QPointer<QObject> sender);
331 void pythonGenericSlot(PyObject* callable, PyObject *argumentTuple);
335 void breakPointDeleted(QString filename,
int lineNo,
int pyBpNumber);
340 bool renameVariable(
bool globalNotLocal,
const QString &oldFullItemName, QString newKey,
ItomSharedSemaphore *semaphore = NULL);
341 bool deleteVariable(
bool globalNotLocal,
const QStringList &fullItemNames,
ItomSharedSemaphore *semaphore = NULL);
343 ito::RetVal pickleSingleParam(QString filename, QSharedPointer<ito::Param> value,
const QString &valueName,
ItomSharedSemaphore *semaphore = NULL);
346 ito::RetVal saveMatlabSingleParam(QString filename, QSharedPointer<ito::Param> value,
const QString &valueName,
ItomSharedSemaphore *semaphore = NULL);
349 ito::RetVal getSysModules(QSharedPointer<QStringList> modNames, QSharedPointer<QStringList> modFilenames, QSharedPointer<IntList> modTypes,
ItomSharedSemaphore *semaphore = NULL);
352 void registerWorkspaceContainer(
PyWorkspaceContainer *container,
bool registerNotUnregister,
bool globalNotLocal);
356 ito::RetVal checkVarnamesInWorkspace(
bool globalNotLocal,
const QStringList &names, QSharedPointer<IntList> existing,
ItomSharedSemaphore *semaphore = NULL);
357 ito::RetVal putParamsToWorkspace(
bool globalNotLocal,
const QStringList &names,
const QVector<SharedParamBasePointer > &values,
ItomSharedSemaphore *semaphore = NULL);
358 ito::RetVal getVarnamesListInWorkspace(
bool globalNotLocal,
const QString &find, QSharedPointer<QStringList> varnameList,
ItomSharedSemaphore *semaphore );
359 ito::RetVal getParamsFromWorkspace(
bool globalNotLocal,
const QStringList &names, QVector<int> paramBaseTypes, QSharedPointer<SharedParamBasePointerVector > values,
ItomSharedSemaphore *semaphore = NULL);
Definition: pythonItom.h:52
Definition: pythonEngine.h:128
QHash< size_t, FuncWeakRef > m_pyFuncWeakRefHashes
hash table containing weak reference to callable python methods or functions and as second...
Definition: pythonEngine.h:249
PyObject * getGlobalDictionary() const
Definition: pythonEngine.h:151
PyObject * itomDbgModule
debugger module
Definition: pythonEngine.h:235
PyObject * mainDictionary
main dictionary of python [borrowed]
Definition: pythonEngine.h:232
Class for managing status values (like errors or warning)
Definition: retVal.h:54
Base class for all plugins.
Definition: addInInterface.h:356
Definition: pythonProxy.h:48
Definition: apiFunctionsGraph.cpp:39
Definition: pythonEngine.h:263
semaphore which can be used for asychronous thread communication. By using this class it is possible ...
Definition: sharedStructuresQt.h:57
PyObject * itomDbgInstance
debugger instance
Definition: pythonEngine.h:236
static class which implements a new python type. The members cout and cerr of the python system are s...
Definition: pythonStream.h:45
PyObject * itomFunctions
ito functions [additional python methods] [new ref]
Definition: pythonEngine.h:238
PyObject * getLocalDictionary()
Definition: pythonEngine.h:181
bool m_executeInternalPythonCodeInDebugMode
if true, button events, user interface connections to python methods... will be executed by debugger ...
Definition: pythonEngine.h:254
PyObject * localDictionary
local dictionary of python [borrowed], usually NULL unless if debugger is in "interaction-mode", then globalDictionary is equal to the local dictionary of the current frame
Definition: pythonEngine.h:233
PyObject * itomModule
itom module [new ref]
Definition: pythonEngine.h:237
Definition: pythonEngine.h:106
QString m_includeItomImportString
string that is prepended to each script before syntax check (if m_includeItomImportBeforeSyntaxCheck ...
Definition: pythonEngine.h:259
QString m_pythonExecutable
absolute path to the python executable
Definition: pythonEngine.h:252
PyObject * globalDictionary
global dictionary of python [borrowed], equals to mainDictionary unless if debugger is in "interactio...
Definition: pythonEngine.h:234
Definition: pythonWorkspace.h:115
PyObject * mainModule
main module of python (builtin) [borrowed]
Definition: pythonEngine.h:231
AutoReload m_autoReload
debugger functionality
Definition: pythonEngine.h:273
item of BreakPointModel
Definition: breakPointModel.h:43