23 #ifndef PYTHONENGINE_H
24 #define PYTHONENGINE_H
35 #include "pythonJedi.h"
37 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION //see comment in pythonNpDataObject.cpp
42 #if (defined _DEBUG) && (defined WIN32)
44 #include "pythonWrapper.h"
46 #include "numpy/arrayobject.h"
49 #include "pythonWrapper.h"
51 #include "numpy/arrayobject.h"
58 #include "pythonItom.h"
59 #include "pythonProxy.h"
60 #include "pythonStream.h"
61 #include "pythonCommon.h"
62 #include "pythonJediRunner.h"
64 #include "../models/breakPointModel.h"
65 #include "../../common/sharedStructuresQt.h"
66 #include "../../common/addInInterface.h"
67 #include "../../common/functionCancellationAndObserver.h"
68 #include "../codeEditor/codeCheckerItem.h"
69 #include "../global.h"
71 #include "pythonWorkspace.h"
73 #include <qstringlist.h>
102 PyObject* getArguments()
const {
return m_argument; }
103 bool isValid()
const {
return (m_proxyObject != NULL); }
105 void setHandle(
const size_t &handle);
106 size_t getHandle()
const {
return m_handle; }
109 PyObject *m_argument;
123 Q_INVOKABLE
ito::RetVal scanAndRunAutostartFolder(QString currentDirAfterScan = QString() );
127 inline ito::BreakPointModel *getBreakPointModel()
const {
return bpModel; }
128 inline bool isPythonBusy()
const {
return m_pythonState != ito::pyStateIdle; }
129 inline bool isPythonDebugging()
const {
return (m_pythonState == ito::pyStateDebuggingWaitingButBusy || m_pythonState == ito::pyStateDebugging || m_pythonState == ito::pyStateDebuggingWaiting); }
130 inline bool isPythonDebuggingAndWaiting()
const {
return m_pythonState == ito::pyStateDebuggingWaiting; }
133 void printPythonErrorWithoutTraceback();
134 void pythonDebugFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
135 void pythonRunFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
137 inline bool pySyntaxCheckAvailable()
const {
return (m_pyModCodeChecker != NULL); }
138 bool tryToLoadJediIfNotYetDone();
139 QList<int> parseAndSplitCommandInMainComponents(
const char *str, QByteArray &encoding)
const;
155 static bool isInterruptQueued();
165 ito::RetVal runPyFile(
const QString &pythonFileName);
170 ito::RetVal runFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
172 ito::RetVal modifyTracebackDepth(
int NrOfLevelsToPopAtFront = -1,
bool showTraceback =
true);
174 PyObject* setPyErrFromException(
const std::exception &exc);
176 void connectNotify(
const QMetaMethod &signal);
178 enum DebuggerErrorCode
181 DbgErrorInvalidBp = 1,
199 PyObject *getPyObjectByFullName(
bool globalNotLocal,
const QStringList &fullNameSplittedByDelimiter, QString *validVariableName = NULL);
200 PyObject *getPyObjectByFullName(
bool globalNotLocal,
const QString &fullName, QString *validVariableName = NULL);
202 void setGlobalDictionary(PyObject* mainDict = NULL);
203 void setLocalDictionary(PyObject* localDict);
205 void emitPythonDictionary(DictUpdateFlag globalDict, DictUpdateFlag localDict,
bool lockGIL);
207 ito::RetVal pickleDictionary(PyObject *dict,
const QString &filename);
214 void pythonDebugString(QString cmd);
217 void enqueueDbgCmd(ito::tPythonDbgCmd dbgCmd);
218 ito::tPythonDbgCmd dequeueDbgCmd();
219 bool DbgCommandsAvailable();
220 void clearDbgCmdLoop();
226 ito::RetVal pythonEditBreakpoint(
const int pyBpNumber,
const BreakPointItem &newBreakpoint);
227 ito::RetVal pythonDeleteBreakpoint(
const int pyBpNumber);
232 static int queuedInterrupt(
void *
arg);
236 QVariantMap checkCodeCheckerRequirements();
241 bool includeItomModuleBeforeCheck;
251 QMutex pythonStateChangeMutex;
252 QDesktopWidget *m_pDesktopWidget;
253 QQueue<ito::tPythonDbgCmd> debugCommandQueue;
254 ito::tPythonDbgCmd debugCommand;
256 ito::tPythonState m_pythonState;
258 ito::BreakPointModel *bpModel;
269 PyObject *m_pyModCodeChecker;
273 QSharedPointer<PythonJediRunner> m_jediRunner;
275 Qt::HANDLE m_pythonThreadId;
277 PyObject *dictUnicode;
278 PyObject *slotsUnicode;
280 QSet<ito::PyWorkspaceContainer*> m_mainWorkspaceContainer;
281 QSet<ito::PyWorkspaceContainer*> m_localWorkspaceContainer;
283 size_t m_pyFuncWeakRefAutoInc;
294 QString m_includeItomImportString;
296 wchar_t *m_pUserDefinedPythonHome;
298 QList<QWeakPointer<ito::FunctionCancellationAndObserver> > m_activeFunctionCancellations;
302 PyObject *modAutoReload;
303 PyObject *classAutoReload;
306 bool checkStringExec;
313 static PyMethodDef PyMethodItomDbg[];
314 static PyModuleDef PyModuleItomDbg;
315 static PyObject* PyInitItomDbg(
void);
322 static QMutex instantiated;
323 static QMutex instancePtrProtection;
324 static QString fctHashPrefix;
328 QAtomicInt m_interruptCounter;
335 void pythonDebugPositionChanged(QString filename,
int lineNo);
336 void pythonStateChanged(tPythonTransitions pyTransition,
bool immediate);
339 void pythonCurrentDirChanged();
340 void updateCallStack(QStringList filenames, IntList lines, QStringList methods);
341 void deleteCallStack();
343 void pythonSetCursor(
const Qt::CursorShape cursor);
344 void pythonResetCursor();
345 void pythonAutoReloadChanged(
bool enabled,
bool checkFile,
bool checkCmd,
bool checkFct);
346 void clearCommandLine();
347 void startInputCommandLine(QSharedPointer<QByteArray> buffer,
ItomSharedSemaphore *semaphore);
350 void pythonExecStringFromCommandLine(QString cmd);
351 void pythonRunFile(QString filename);
352 void pythonDebugFile(QString filename);
353 void pythonRunStringOrFunction(QString cmdOrFctHash);
354 void pythonDebugStringOrFunction(QString cmdOrFctHash);
355 void pythonInterruptExecutionThreadSafe(
bool *interruptActuatorsAndTimers = NULL);
356 void pythonDebugCommand(tPythonDbgCmd cmd);
358 void setAutoReloader(
bool enabled,
bool checkFile,
bool checkCmd,
bool checkFct);
362 void propertiesChanged();
364 void pythonCodeCheck(
const QString &code,
const QString &filename,
bool fileSaved, QPointer<QObject> sender, QByteArray callbackFctName);
368 void breakPointDeleted(QString filename,
int lineNo,
int pyBpNumber);
373 bool renameVariable(
bool globalNotLocal,
const QString &oldFullItemName, QString newKey,
ItomSharedSemaphore *semaphore = NULL);
374 bool deleteVariable(
bool globalNotLocal,
const QStringList &fullItemNames,
ItomSharedSemaphore *semaphore = NULL);
382 ito::RetVal getSysModules(QSharedPointer<QStringList> modNames, QSharedPointer<QStringList> modFilenames, QSharedPointer<IntList> modTypes,
ItomSharedSemaphore *semaphore = NULL);
385 void registerWorkspaceContainer(
PyWorkspaceContainer *container,
bool registerNotUnregister,
bool globalNotLocal);
390 ito::RetVal putParamsToWorkspace(
bool globalNotLocal,
const QStringList &names,
const QVector<SharedParamBasePointer > &values,
ItomSharedSemaphore *semaphore = NULL);
391 ito::RetVal getVarnamesListInWorkspace(
bool globalNotLocal,
const QString &find, QSharedPointer<QStringList> varnameList,
ItomSharedSemaphore *semaphore );
392 ito::RetVal getParamsFromWorkspace(
bool globalNotLocal,
const QStringList &names, QVector<int> paramBaseTypes, QSharedPointer<SharedParamBasePointerVector > values,
ItomSharedSemaphore *semaphore = NULL);
CodeCheckerMessageType
Definition: pythonCommon.h:92
static PyObject * PyDbgCommandLoop(PyObject *pSelf, PyObject *pArgs)
Definition: pythonEngine.cpp:4090
ito::RetVal debugFile(const QString &pythonFileName)
Definition: pythonEngine.cpp:1946
PyMethodDef * PythonAdditionalModuleITOM
decides if itom is automatically included in every source file before it is handed to the syntax chec...
Definition: pythonEngine.h:288
Definition: pythonItom.h:52
DataObject arg(const DataObject &dObj)
high-level value which calculates the argument value of each element of the input source data object ...
Definition: dataobj.cpp:10131
void enqueueJediCalltipRequest(const ito::JediCalltipRequest &request)
thread-safe method (can be called from any thread) to enqueue a jedi calltip request ...
Definition: pythonEngine.cpp:2178
Definition: pythonEngine.h:114
QHash< size_t, FuncWeakRef > m_pyFuncWeakRefHashes
hash table containing weak reference to callable python methods or functions and as second...
Definition: pythonEngine.h:282
void enqueueJediCompletionRequest(const ito::JediCompletionRequest &request)
thread-safe method (can be called from any thread) to enqueue a jedi calltip request ...
Definition: pythonEngine.cpp:2196
PyObject * getGlobalDictionary() const
Definition: pythonEngine.h:136
static PythonEngine * getInstanceInternal()
Definition: pythonEngine.cpp:156
PyObject * itomDbgModule
debugger module
Definition: pythonEngine.h:264
Class for managing status values (like errors or warning)
Definition: retVal.h:54
ito::RetVal checkVarnamesInWorkspace(bool globalNotLocal, const QStringList &names, QSharedPointer< IntList > existing, ItomSharedSemaphore *semaphore=NULL)
Definition: pythonEngine.cpp:5034
Base class for all plugins.
Definition: addInInterface.h:385
ito::RetVal debugString(const QString &command)
Definition: pythonEngine.cpp:2056
CodeCheckerMode
< mode that can be chosen for the code checker
Definition: pythonCommon.h:83
Definition: pythonProxy.h:48
Definition: pythonJedi.h:94
void pythonCodeCheck(const QString &code, const QString &filename, bool fileSaved, QPointer< QObject > sender, QByteArray callbackFctName)
these slots are only connected if python in debug-mode; while waiting these slots will be treated due...
Definition: pythonEngine.cpp:2228
Definition: pythonEngine.h:238
Definition: apiFunctionsGraph.cpp:39
Definition: pythonEngine.h:300
bool m_pyModCodeCheckerHasFlake8
true if m_pyModCodeChecker could be loaded and pretends to have the syntax and style check feature (p...
Definition: pythonEngine.h:271
void submitAllBreakpointsToDebugger()
< submits all breakpoints to the debugger. This should be called before code is debugged.
Definition: pythonEngine.cpp:2403
ito::RetVal unpickleDictionary(PyObject *destinationDict, const QString &filename, bool overwrite)
runs the given Python string command
Definition: pythonEngine.cpp:6260
PyObject * m_pLocalDictionary
local dictionary of python [borrowed], usually NULL unless if debugger is in "interaction-mode", then m_pGlobalDictionary is equal to the local dictionary of the current frame
Definition: pythonEngine.h:262
This class can be passed to a long running method (e.g. as QSharedPointer instance) for two reasons: ...
Definition: functionCancellationAndObserver.h:56
ito::RetVal debugFunction(PyObject *callable, PyObject *argTuple, bool gilExternal=false)
Definition: pythonEngine.cpp:1833
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:265
ito::RetVal pythonAddBreakpoint(const BreakPointItem &breakpoint, int &pyBpNumber)
Definition: pythonEngine.cpp:2452
bool m_pyModCodeCheckerHasPyFlakes
true if m_pyModCodeChecker could be loaded and pretends to have the syntax check feature (package: py...
Definition: pythonEngine.h:270
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:267
bool m_includeItomImportBeforeCodeAnalysis
string that is prepended to each script before syntax check (if m_includeItomImportBeforeCodeAnalysis...
Definition: pythonEngine.h:291
ito::RetVal saveMatlabSingleParam(QString filename, QSharedPointer< ito::Param > value, const QString &valueName, ItomSharedSemaphore *semaphore=NULL)
Definition: pythonEngine.cpp:4766
bool m_executeInternalPythonCodeInDebugMode
if true, button events, user interface connections to python methods... will be executed by debugger ...
Definition: pythonEngine.h:287
QByteArray furtherPropertiesJson
these parameters are parsed from a QVariantMap to json and will be passed to itomSyntaxCheck.py
Definition: pythonEngine.h:243
void enqueueGoToAssignmentRequest(const ito::JediAssignmentRequest &request)
thread-safe method (can be called from any thread) to enqueue a jedi get-help request ...
Definition: pythonEngine.cpp:2205
void addFunctionCancellationAndObserver(QWeakPointer< ito::FunctionCancellationAndObserver > observer)
will remove the given observer from the list of function cancellations and observers. Even if observer is NULL, the list of current observers will be cleanup from deleted instances
Definition: pythonEngine.cpp:3969
PyObject * itomModule
itom module [new ref]
Definition: pythonEngine.h:266
Qt::HANDLE getPythonThreadId() const
thread-safe method (can be called from any thread) to enqueue a jedi completion request ...
Definition: pythonEngine.h:141
void pythonRunString(QString cmd)
debugs the given Python string command
Definition: pythonEngine.cpp:2835
Q_INVOKABLE void pythonSetup(ito::RetVal *retValue, QSharedPointer< QVariantMap > infoMessages)
Definition: pythonEngine.cpp:313
Definition: pythonJedi.h:123
Definition: pythonJedi.h:64
PyObject * m_pMainDictionary
main dictionary of python [borrowed]
Definition: pythonEngine.h:261
void setAutoReloader(bool enabled, bool checkFile, bool checkCmd, bool checkFct)
Definition: pythonEngine.cpp:1376
Definition: pythonEngine.h:92
Definition: pythonJedi.h:34
PyObject * getAndCheckIdentifier(const QString &identifier, ito::RetVal &retval) const
get the unicode object from identifier and checks if it is a valid python identifier (variable name)...
Definition: pythonEngine.cpp:5650
QString m_pythonExecutable
absolute path to the python executable
Definition: pythonEngine.h:285
PyObject * m_pGlobalDictionary
global dictionary of python [borrowed], equals to m_pMainDictionary unless if debugger is in "interac...
Definition: pythonEngine.h:263
Definition: pythonWorkspace.h:99
PyObject * mainModule
main module of python (builtin) [borrowed]
Definition: pythonEngine.h:260
ito::RetVal pythonStateTransition(tPythonTransitions transition, bool immediate=true)
< signals a state change of the Python interpreter
Definition: pythonEngine.cpp:3230
PythonCommon::CodeCheckerMessageType minVisibleMessageTypeLevel
minimum message class that should be shown in editor margin
Definition: pythonEngine.h:242
static const PythonEngine * getInstance()
add a new function cancellation / observer. Each valid observer on the list will be requested to be c...
Definition: pythonEngine.cpp:148
AutoReload m_autoReload
debugger functionality
Definition: pythonEngine.h:310
item of BreakPointModel
Definition: breakPointModel.h:42
ito::RetVal pickleSingleParam(QString filename, QSharedPointer< ito::Param > value, const QString &valueName, ItomSharedSemaphore *semaphore=NULL)
Definition: pythonEngine.cpp:5920