34#include "pythonJedi.h"
37 #include "pythonWrapper.h"
41 #if (defined _DEBUG) && (defined WIN32)
45 #if (PY_VERSION_HEX < 0x03070000)
50 #if (PY_VERSION_HEX < 0x03070000)
59#include "pythonItom.h"
60#include "pythonProxy.h"
61#include "pythonStream.h"
62#include "pythonCommon.h"
63#include "pythonJediRunner.h"
65#include "../models/breakPointModel.h"
66#include "../../common/sharedStructuresQt.h"
67#include "../../common/addInInterface.h"
68#include "../../common/functionCancellationAndObserver.h"
69#include "../codeEditor/codeCheckerItem.h"
72#include "pythonWorkspace.h"
74#include <qstringlist.h>
79#include <qelapsedtimer.h>
105 PyObject* getArguments()
const {
return m_argument; }
106 bool isValid()
const {
return (m_proxyObject != NULL); }
108 void setHandle(
const size_t &handle);
109 size_t getHandle()
const {
return m_handle; }
112 PyObject *m_argument;
127 Q_INVOKABLE
ito::RetVal scanAndRunAutostartFolder(QString currentDirAfterScan = QString() );
132 inline bool isPythonBusy()
const {
return m_pythonState != ito::pyStateIdle; }
133 inline bool isPythonDebugging()
const {
return (m_pythonState == ito::pyStateDebuggingWaitingButBusy || m_pythonState == ito::pyStateDebugging || m_pythonState == ito::pyStateDebuggingWaiting); }
134 inline bool isPythonDebuggingAndWaiting()
const {
return m_pythonState == ito::pyStateDebuggingWaiting; }
137 void printPythonErrorWithoutTraceback();
138 void pythonDebugFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
139 void pythonRunFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
141 inline bool pySyntaxCheckAvailable()
const {
return (m_pyModCodeChecker != NULL); }
142 bool tryToLoadJediIfNotYetDone();
170 static bool isInterruptQueued();
180 ito::RetVal runPyFile(
const QString &pythonFileName);
185 ito::RetVal runFunction(PyObject *callable, PyObject *argTuple,
bool gilExternal =
false);
187 ito::RetVal modifyTracebackDepth(
int NrOfLevelsToPopAtFront = -1,
bool showTraceback =
true);
189 PyObject* setPyErrFromException(
const std::exception &exc);
190 void startupInitPythonWorkspaceUpdateQueue();
191 ito::RetVal startupInitPythonHelpStreamConsumer(QSettings& settings);
194 void connectNotify(
const QMetaMethod &signal);
196 enum DebuggerErrorCode
199 DbgErrorInvalidBp = 1,
214 actionGlobal(DictNoAction),
215 actionLocal(DictNoAction),
217 timerElapsedSinceLastUpdate(
nullptr)
223 actionGlobal = DictNoAction;
224 actionLocal = DictNoAction;
225 timerElapsedSinceLastUpdate->stop();
235 QTimer *timerElapsedSinceLastUpdate;
237 DictUpdateFlag actionGlobal;
238 DictUpdateFlag actionLocal;
247 PyObject *getPyObjectByFullName(
bool globalNotLocal,
const QStringList &fullNameSplittedByDelimiter, QString *validVariableName = NULL);
248 PyObject *getPyObjectByFullName(
bool globalNotLocal,
const QString &fullName, QString *validVariableName = NULL);
250 void setGlobalDictionary(PyObject* mainDict = NULL);
251 void setLocalDictionary(PyObject* localDict);
253 void updatePythonWorkspaces(DictUpdateFlag globalDict, DictUpdateFlag localDict,
bool lockGIL,
bool delayExecution =
false);
255 ito::RetVal pickleDictionary(PyObject *dict,
const QString &filename);
262 void pythonDebugString(QString cmd);
264 QString modifyCommandStringInCaseOfSpecialComments(
const QString& command);
267 void enqueueDbgCmd(ito::tPythonDbgCmd dbgCmd);
268 ito::tPythonDbgCmd dequeueDbgCmd();
269 bool DbgCommandsAvailable();
270 void clearDbgCmdLoop();
277 ito::RetVal pythonDeleteBreakpoint(
const int pyBpNumber);
282 static int queuedInterrupt(
void *
arg);
286 QVariantMap checkCodeCheckerRequirements();
292 bool includeItomModuleBeforeCheck;
301 QMutex m_dbgCmdMutex;
302 QMutex m_pythonStateChangeMutex;
303 QQueue<ito::tPythonDbgCmd> m_debugCommandQueue;
305 ito::tPythonState m_pythonState;
318 PyObject *m_pyModCodeChecker;
322 QSharedPointer<PythonJediRunner> m_jediRunner;
323 Qt::HANDLE m_pythonThreadId;
324 PyObject *m_dictUnicode;
325 PyObject *m_slotsUnicode;
328 QSet<ito::PyWorkspaceContainer*> m_mainWorkspaceContainer;
329 QSet<ito::PyWorkspaceContainer*> m_localWorkspaceContainer;
331 size_t m_pyFuncWeakRefAutoInc;
342 QString m_includeItomImportString;
344 wchar_t *m_pUserDefinedPythonHome;
346 QList<QWeakPointer<ito::FunctionCancellationAndObserver> > m_activeFunctionCancellations;
350 PyObject *modAutoReload;
351 PyObject *classAutoReload;
354 bool checkStringExec;
363 static PyMethodDef PyMethodItomDbg[];
364 static PyModuleDef PyModuleItomDbg;
365 static PyObject* PyInitItomDbg(
void);
367 static PyObject* PyDbgClearBreakpoint(PyObject* pSelf, PyObject* pArgs);
370 static QMutex instancePtrProtection;
371 static QString fctHashPrefix;
374 QAtomicInt m_interruptCounter;
381 void pythonDebugPositionChanged(QString filename,
int lineNo);
382 void pythonStateChanged(tPythonTransitions pyTransition,
bool immediate);
385 void pythonCurrentDirChanged();
386 void updateCallStack(QStringList filenames, IntList lines, QStringList methods);
387 void deleteCallStack();
389 void pythonSetCursor(
const Qt::CursorShape cursor);
390 void pythonResetCursor();
391 void pythonAutoReloadChanged(
bool enabled,
bool checkFile,
bool checkCmd,
bool checkFct);
392 void clearCommandLine();
393 void interruptCommandInput();
394 void startInputCommandLine(QSharedPointer<QByteArray> buffer,
ItomSharedSemaphore *semaphore);
397 void processPythonWorkspaceUpdateQueue();
400 void pythonExecStringFromCommandLine(QString cmd);
401 void pythonRunFile(QString filename);
402 void pythonDebugFile(QString filename);
403 void pythonRunStringOrFunction(QString cmdOrFctHash);
404 void pythonDebugStringOrFunction(QString cmdOrFctHash);
405 void pythonInterruptExecutionThreadSafe(
bool *interruptActuatorsAndTimers = NULL);
406 void pythonDebugCommand(tPythonDbgCmd cmd);
408 void setAutoReloader(
bool enabled,
bool checkFile,
bool checkCmd,
bool checkFct);
412 void propertiesChanged();
414 void pythonCodeCheck(
const QString &code,
const QString &filename,
bool fileSaved, QPointer<QObject> sender, QByteArray callbackFctName);
418 void breakPointDeleted(QString filename,
int lineNo,
int pyBpNumber);
423 bool renameVariable(
bool globalNotLocal,
const QString &oldFullItemName, QString newKey,
ItomSharedSemaphore *semaphore = NULL);
424 bool deleteVariable(
bool globalNotLocal,
const QStringList &fullItemNames);
432 ito::RetVal getSysModules(QSharedPointer<QStringList> modNames, QSharedPointer<QStringList> modFilenames, QSharedPointer<IntList> modTypes,
ItomSharedSemaphore *semaphore = NULL);
435 void registerWorkspaceContainer(
PyWorkspaceContainer *container,
bool registerNotUnregister,
bool globalNotLocal);
440 ito::RetVal putParamsToWorkspace(
bool globalNotLocal,
const QStringList &names,
const QVector<SharedParamBasePointer > &values,
ItomSharedSemaphore *semaphore = NULL);
441 ito::RetVal getVarnamesListInWorkspace(
bool globalNotLocal,
const QString &find, QSharedPointer<QStringList> varnameList,
ItomSharedSemaphore *semaphore );
442 ito::RetVal getParamsFromWorkspace(
bool globalNotLocal,
const QStringList &names, QVector<int> paramBaseTypes, QSharedPointer<SharedParamBasePointerVector > values,
ItomSharedSemaphore *semaphore = NULL);
semaphore which can be used for asynchronous thread communication. By using this class it is possible...
Definition sharedStructuresQt.h:58
Base class for all plugins.
Definition addInInterface.h:386
model for management of all breakpoints. This model will be displayed by a viewer-widget in the main ...
Definition breakPointModel.h:69
Definition pythonEngine.h:96
This class can be passed to a long running method (e.g. as QSharedPointer instance) for two reasons:
Definition functionCancellationAndObserver.h:57
static class which implements a new python type. The members cout and cerr of the python system are s...
Definition pythonStream.h:38
Definition pythonWorkspace.h:92
CodeCheckerMode
< mode that can be chosen for the code checker
Definition pythonCommon.h:75
CodeCheckerMessageType
Definition pythonCommon.h:84
Definition pythonEngine.h:118
ito::RetVal pythonStateTransition(tPythonTransitions transition, bool immediate=true)
< signals a state change of the Python interpreter
Definition pythonEngine.cpp:3606
QHash< size_t, FuncWeakRef > m_pyFuncWeakRefHashes
hash table containing weak reference to callable python methods or functions and as second,...
Definition pythonEngine.h:330
void enqueueJediCompletionRequest(const ito::JediCompletionRequest &request)
thread-safe method (can be called from any thread) to enqueue a jedi calltip request
Definition pythonEngine.cpp:2542
PyObject * m_itomDbgInstance
debugger instance
Definition pythonEngine.h:314
void submitAllBreakpointsToDebugger()
< submits all breakpoints to the debugger. This should be called before code is debugged.
Definition pythonEngine.cpp:2758
bool m_pyModCodeCheckerHasPyFlakes
true if m_pyModCodeChecker could be loaded and pretends to have the syntax check feature (package: py...
Definition pythonEngine.h:319
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:6388
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:2560
static PythonEngine * getInstanceInternal()
Definition pythonEngine.cpp:162
ito::RetVal debugFile(const QString &pythonFileName)
Definition pythonEngine.cpp:2263
bool m_executeInternalPythonCodeInDebugMode
if true, button events, user interface connections to python methods... will be executed by debugger
Definition pythonEngine.h:335
ito::RetVal pythonAddBreakpoint(const BreakPointItem &breakpoint, int &pyBpNumber)
Definition pythonEngine.cpp:2807
void enqueueJediGetHelpRequest(const ito::JediGetHelpRequest &request)
thread-safe method (can be called from any thread) to enqueue a jedi rename request
Definition pythonEngine.cpp:2533
void addFunctionCancellationAndObserver(QWeakPointer< ito::FunctionCancellationAndObserver > observer)
will remove the given observer from the list of function cancellations and observers....
Definition pythonEngine.cpp:4603
PyObject * m_itomDbgModule
debugger module
Definition pythonEngine.h:313
QList< int > parseAndSplitCommandInMainComponents(const QString &str, QByteArray &encoding) const
< parses a (multiline) python string and returns the line numbers of the start of every major block.
Definition pythonEngine.cpp:1586
PyObject * m_pLocalDictionary
local dictionary of python [borrowed], usually NULL unless if debugger is in "interaction-mode",...
Definition pythonEngine.h:311
PyObject * m_mainModule
main module of python (builtin) [borrowed]
Definition pythonEngine.h:309
Qt::HANDLE getPythonThreadId() const
thread-safe method (can be called from any thread) to enqueue a jedi completion request
Definition pythonEngine.h:153
PyObject * getGlobalDictionary() const
Definition pythonEngine.h:140
PyObject * m_itomModule
itom module [new ref]
Definition pythonEngine.h:315
ito::RetVal startupAddModulesToItomModule()
Definition pythonEngine.cpp:942
ito::RetVal debugFunction(PyObject *callable, PyObject *argTuple, bool gilExternal=false)
Definition pythonEngine.cpp:2151
PyObject * m_itomFunctions
ito functions [additional python methods] [new ref]
Definition pythonEngine.h:316
void setAutoReloader(bool enabled, bool checkFile, bool checkCmd, bool checkFct)
Definition pythonEngine.cpp:1691
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:154
static PyObject * PyDbgCommandLoop(PyObject *pSelf, PyObject *pArgs)
Definition pythonEngine.cpp:4736
ito::RetVal startupLoadAndImportAdditionalModules(QSharedPointer< QVariantMap > &infoMessages)
Definition pythonEngine.cpp:784
PythonWorkspaceUpdateQueue m_pyWorkspaceUpdateQueue
debugger functionality
Definition pythonEngine.h:360
void pythonRunString(QString cmd)
debugs the given Python string command
Definition pythonEngine.cpp:3190
ito::RetVal saveMatlabSingleParam(QString filename, QSharedPointer< ito::Param > value, const QString &valueName, ItomSharedSemaphore *semaphore=NULL)
Definition pythonEngine.cpp:5504
ito::RetVal debugString(const QString &command)
Definition pythonEngine.cpp:2375
ito::RetVal pickleSingleParam(QString filename, QSharedPointer< ito::Param > value, const QString &valueName, ItomSharedSemaphore *semaphore=NULL)
Definition pythonEngine.cpp:6670
void enqueueJediCalltipRequest(const ito::JediCalltipRequest &request)
thread-safe method (can be called from any thread) to enqueue a jedi calltip request
Definition pythonEngine.cpp:2524
PyObject * m_pGlobalDictionary
global dictionary of python [borrowed], equals to m_pMainDictionary unless if debugger is in "interac...
Definition pythonEngine.h:312
bool m_includeItomImportBeforeCodeAnalysis
string that is prepended to each script before syntax check (if m_includeItomImportBeforeCodeAnalysis...
Definition pythonEngine.h:339
ito::RetVal checkVarnamesInWorkspace(bool globalNotLocal, const QStringList &names, QSharedPointer< IntList > existing, ItomSharedSemaphore *semaphore=NULL)
Definition pythonEngine.cpp:5773
ito::RetVal unpickleDictionary(PyObject *destinationDict, const QString &filename, bool overwrite, bool replaceKeyByValidPyIdentifier)
runs the given Python string command
Definition pythonEngine.cpp:7014
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:2581
Q_INVOKABLE void pythonSetup(ito::RetVal *retValue, QSharedPointer< QVariantMap > infoMessages)
Definition pythonEngine.cpp:314
QString m_pythonExecutable
absolute path to the python executable
Definition pythonEngine.h:333
bool m_pyModCodeCheckerHasFlake8
true if m_pyModCodeChecker could be loaded and pretends to have the syntax and style check feature (p...
Definition pythonEngine.h:320
PyObject * m_pMainDictionary
main dictionary of python [borrowed]
Definition pythonEngine.h:310
Definition pythonItom.h:45
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40
DataObject arg(const DataObject &dObj)
Definition dataobj.cpp:12926
item of BreakPointModel
Definition breakPointModel.h:43
Definition pythonJedi.h:103
Definition pythonJedi.h:36
Definition pythonJedi.h:70
Definition pythonJedi.h:130
Definition pythonJedi.h:154
Definition pythonEngine.h:349
Definition pythonEngine.h:290
PythonCommon::CodeCheckerMessageType minVisibleMessageTypeLevel
minimum message class that should be shown in editor margin
Definition pythonEngine.h:293
QByteArray furtherPropertiesJson
these parameters are parsed from a QVariantMap to json and will be passed to itomSyntaxCheck....
Definition pythonEngine.h:294
Definition pythonEngine.h:212
QTimer * timerElapsedSinceFirstAction
Definition pythonEngine.h:231
void reset()
Definition pythonEngine.h:221
Definition pythonProxy.h:41