itom
Loading...
Searching...
No Matches
ito::PythonEngine Class Reference
Inheritance diagram for ito::PythonEngine:

Classes

struct  AutoReload
 
struct  CodeCheckerOptions
 
struct  PythonWorkspaceUpdateQueue
 

Public Slots

void pythonExecStringFromCommandLine (QString cmd)
 
void pythonRunFile (QString filename)
 
void pythonDebugFile (QString filename)
 
void pythonRunStringOrFunction (QString cmdOrFctHash)
 
void pythonDebugStringOrFunction (QString cmdOrFctHash)
 
void pythonInterruptExecutionThreadSafe (bool *interruptActuatorsAndTimers=NULL)
 
void pythonDebugCommand (tPythonDbgCmd cmd)
 
void setAutoReloader (bool enabled, bool checkFile, bool checkCmd, bool checkFct)
 
void readSettings ()
 
void propertiesChanged ()
 
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 to progressEvents-call in PythonEngine::PyDbgCommandLoop
 
void breakPointAdded (BreakPointItem bp, int row)
 
void breakPointDeleted (QString filename, int lineNo, int pyBpNumber)
 
void breakPointChanged (BreakPointItem oldBp, BreakPointItem newBp)
 
ito::RetVal setupBreakPointDebugConnections ()
 
ito::RetVal shutdownBreakPointDebugConnections ()
 
bool renameVariable (bool globalNotLocal, const QString &oldFullItemName, QString newKey, ItomSharedSemaphore *semaphore=NULL)
 
bool deleteVariable (bool globalNotLocal, const QStringList &fullItemNames)
 
ito::RetVal pickleVariables (bool globalNotLocal, QString filename, QStringList varNames, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal pickleSingleParam (QString filename, QSharedPointer< ito::Param > value, const QString &valueName, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal unpickleVariables (bool globalNotLocal, QString filename, QString packedVarName, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal saveMatlabVariables (bool globalNotLocal, QString filename, QStringList varNames, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal saveMatlabSingleParam (QString filename, QSharedPointer< ito::Param > value, const QString &valueName, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal loadMatlabVariables (bool globalNotLocal, QString filename, QString packedVarName, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal registerAddInInstance (QString varname, ito::AddInBase *instance, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal getSysModules (QSharedPointer< QStringList > modNames, QSharedPointer< QStringList > modFilenames, QSharedPointer< IntList > modTypes, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal reloadSysModules (QSharedPointer< QStringList > modNames, ItomSharedSemaphore *semaphore=NULL)
 
void registerWorkspaceContainer (PyWorkspaceContainer *container, bool registerNotUnregister, bool globalNotLocal)
 
void workspaceGetChildNode (PyWorkspaceContainer *container, QString fullNameParentItem)
 
void workspaceGetValueInformation (PyWorkspaceContainer *container, const QString &fullItemName, QSharedPointer< QString > extendedValue, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal checkVarnamesInWorkspace (bool globalNotLocal, const QStringList &names, QSharedPointer< IntList > existing, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal putParamsToWorkspace (bool globalNotLocal, const QStringList &names, const QVector< SharedParamBasePointer > &values, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal getVarnamesListInWorkspace (bool globalNotLocal, const QString &find, QSharedPointer< QStringList > varnameList, ItomSharedSemaphore *semaphore)
 
ito::RetVal getParamsFromWorkspace (bool globalNotLocal, const QStringList &names, QVector< int > paramBaseTypes, QSharedPointer< SharedParamBasePointerVector > values, ItomSharedSemaphore *semaphore=NULL)
 
ito::RetVal pythonGetClearAllValues ()
 
ito::RetVal pythonClearAll ()
 

Signals

void pythonDebugPositionChanged (QString filename, int lineNo)
 
void pythonStateChanged (tPythonTransitions pyTransition, bool immediate)
 
void pythonModifyLocalDict (PyObject *localDict, ItomSharedSemaphore *semaphore)
 
void pythonModifyGlobalDict (PyObject *globalDict, ItomSharedSemaphore *semaphore)
 
void pythonCurrentDirChanged ()
 
void updateCallStack (QStringList filenames, IntList lines, QStringList methods)
 
void deleteCallStack ()
 
void pythonSetCursor (const Qt::CursorShape cursor)
 
void pythonResetCursor ()
 
void pythonAutoReloadChanged (bool enabled, bool checkFile, bool checkCmd, bool checkFct)
 
void clearCommandLine ()
 
void interruptCommandInput ()
 
void startInputCommandLine (QSharedPointer< QByteArray > buffer, ItomSharedSemaphore *semaphore)
 

Public Member Functions

Q_INVOKABLE void pythonSetup (ito::RetVal *retValue, QSharedPointer< QVariantMap > infoMessages)
 
Q_INVOKABLE ito::RetVal scanAndRunAutostartFolder (QString currentDirAfterScan=QString())
 
Q_INVOKABLE ito::RetVal pythonShutdown (ItomSharedSemaphore *aimWait=NULL)
 
Q_INVOKABLE ito::RetVal stringEncodingChanged ()
 
ito::BreakPointModelgetBreakPointModel () const
 
bool isPythonBusy () const
 
bool isPythonDebugging () const
 
bool isPythonDebuggingAndWaiting () const
 
bool execInternalCodeByDebugger () const
 
void setExecInternalCodeByDebugger (bool value)
 
void printPythonErrorWithoutTraceback ()
 
void pythonDebugFunction (PyObject *callable, PyObject *argTuple, bool gilExternal=false)
 
void pythonRunFunction (PyObject *callable, PyObject *argTuple, bool gilExternal=false)
 
PyObject * getGlobalDictionary () const
 
bool pySyntaxCheckAvailable () const
 
bool tryToLoadJediIfNotYetDone ()
 
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.
 
QString getPythonExecutable () const
 
Qt::HANDLE getPythonThreadId () const
 thread-safe method (can be called from any thread) to enqueue a jedi completion request
 
void enqueueJediCompletionRequest (const ito::JediCompletionRequest &request)
 thread-safe method (can be called from any thread) to enqueue a jedi calltip request
 
void enqueueJediCalltipRequest (const ito::JediCalltipRequest &request)
 thread-safe method (can be called from any thread) to enqueue a jedi calltip request
 
void enqueueGoToAssignmentRequest (const ito::JediAssignmentRequest &request)
 thread-safe method (can be called from any thread) to enqueue a jedi get-help request
 
void enqueueJediGetHelpRequest (const ito::JediGetHelpRequest &request)
 thread-safe method (can be called from any thread) to enqueue a jedi rename request
 
void enqueueJediRenameRequest (const ito::JediRenameRequest &request)
 
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
 
void removeFunctionCancellationAndObserver (ito::FunctionCancellationAndObserver *observer=NULL)
 

Static Public Member Functions

static bool isInterruptQueued ()
 
static const PythonEnginegetInstance ()
 add a new function cancellation / observer. Each valid observer on the list will be requested to be cancelled if a script executed is interrupted
 

Protected Types

enum  DebuggerErrorCode { DbgErrorNo = 0 , DbgErrorInvalidBp = 1 , DbgErrorOther = 2 }
 

Protected Member Functions

ito::RetVal runPyFile (const QString &pythonFileName)
 
ito::RetVal debugFile (const QString &pythonFileName)
 
ito::RetVal runString (const QString &command)
 
ito::RetVal debugString (const QString &command)
 
ito::RetVal debugFunction (PyObject *callable, PyObject *argTuple, bool gilExternal=false)
 
ito::RetVal runFunction (PyObject *callable, PyObject *argTuple, bool gilExternal=false)
 
ito::RetVal modifyTracebackDepth (int NrOfLevelsToPopAtFront=-1, bool showTraceback=true)
 
PyObject * setPyErrFromException (const std::exception &exc)
 
void startupInitPythonWorkspaceUpdateQueue ()
 
ito::RetVal startupInitPythonHelpStreamConsumer (QSettings &settings)
 
ito::RetVal startupAddModulesToItomModule ()
 
ito::RetVal startupLoadAndImportAdditionalModules (QSharedPointer< QVariantMap > &infoMessages)
 
void connectNotify (const QMetaMethod &signal)
 

Private Types

enum  DictUpdateFlag { DictUpdate , DictReset , DictNoAction }
 

Private Slots

void processPythonWorkspaceUpdateQueue ()
 

Private Member Functions

PyObject * getLocalDictionary ()
 
PyObject * getPyObjectByFullName (bool globalNotLocal, const QStringList &fullNameSplittedByDelimiter, QString *validVariableName=NULL)
 
PyObject * getPyObjectByFullName (bool globalNotLocal, const QString &fullName, QString *validVariableName=NULL)
 
void setGlobalDictionary (PyObject *mainDict=NULL)
 
void setLocalDictionary (PyObject *localDict)
 
void updatePythonWorkspaces (DictUpdateFlag globalDict, DictUpdateFlag localDict, bool lockGIL, bool delayExecution=false)
 
ito::RetVal pickleDictionary (PyObject *dict, const QString &filename)
 
ito::RetVal unpickleDictionary (PyObject *destinationDict, const QString &filename, bool overwrite, bool replaceKeyByValidPyIdentifier)
 runs the given Python string command
 
void pythonRunString (QString cmd)
 debugs the given Python string command
 
void pythonDebugString (QString cmd)
 
QString modifyCommandStringInCaseOfSpecialComments (const QString &command)
 
void enqueueDbgCmd (ito::tPythonDbgCmd dbgCmd)
 
ito::tPythonDbgCmd dequeueDbgCmd ()
 
bool DbgCommandsAvailable ()
 
void clearDbgCmdLoop ()
 
ito::RetVal pythonStateTransition (tPythonTransitions transition, bool immediate=true)
 < signals a state change of the Python interpreter
 
ito::RetVal pythonAddBreakpoint (const BreakPointItem &breakpoint, int &pyBpNumber)
 
ito::RetVal pythonEditBreakpoint (const int pyBpNumber, const BreakPointItem &newBreakpoint)
 
ito::RetVal pythonDeleteBreakpoint (const int pyBpNumber)
 
void submitAllBreakpointsToDebugger ()
 < submits all breakpoints to the debugger. This should be called before code is debugged.
 
ito::RetVal autoReloaderCheck ()
 
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). This returns a new reference of the unicode object or NULL with a corresponding error message (python error flag is cleared)
 
QVariantMap checkCodeCheckerRequirements ()
 
ito::RetVal handlePythonSysExit ()
 

Static Private Member Functions

static PythonEnginegetInstanceInternal ()
 
static int queuedInterrupt (void *arg)
 
static PyObject * PyInitItomDbg (void)
 
static PyObject * PyDbgCommandLoop (PyObject *pSelf, PyObject *pArgs)
 
static PyObject * PyDbgClearBreakpoint (PyObject *pSelf, PyObject *pArgs)
 

Private Attributes

bool m_started
 
CodeCheckerOptions m_codeCheckerOptions
 
QMutex m_dbgCmdMutex
 
QMutex m_pythonStateChangeMutex
 
QQueue< ito::tPythonDbgCmd > m_debugCommandQueue
 
ito::tPythonState m_pythonState
 
ito::BreakPointModelm_bpModel
 
PyObject * m_mainModule
 main module of python (builtin) [borrowed]
 
PyObject * m_pMainDictionary
 main dictionary of python [borrowed]
 
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
 
PyObject * m_pGlobalDictionary
 global dictionary of python [borrowed], equals to m_pMainDictionary unless if debugger is in "interaction-mode", then m_pGlobalDictionary is equal to the global dictionary of the current frame
 
PyObject * m_itomDbgModule
 debugger module
 
PyObject * m_itomDbgInstance
 debugger instance
 
PyObject * m_itomModule
 itom module [new ref]
 
PyObject * m_itomFunctions
 ito functions [additional python methods] [new ref]
 
PyObject * m_pyModGC
 
PyObject * m_pyModCodeChecker
 
bool m_pyModCodeCheckerHasPyFlakes
 true if m_pyModCodeChecker could be loaded and pretends to have the syntax check feature (package: pyflakes)
 
bool m_pyModCodeCheckerHasFlake8
 true if m_pyModCodeChecker could be loaded and pretends to have the syntax and style check feature (package: flake8)
 
QSharedPointer< PythonJediRunnerm_jediRunner
 
Qt::HANDLE m_pythonThreadId
 
PyObject * m_dictUnicode
 
PyObject * m_slotsUnicode
 
QSet< ito::PyWorkspaceContainer * > m_mainWorkspaceContainer
 
QSet< ito::PyWorkspaceContainer * > m_localWorkspaceContainer
 
QHash< size_t, FuncWeakRefm_pyFuncWeakRefHashes
 hash table containing weak reference to callable python methods or functions and as second, optional PyObject* an tuple, passed as argument to that function. These functions are for example executed by menu-clicks in the main window.
 
size_t m_pyFuncWeakRefAutoInc
 
QString m_pythonExecutable
 absolute path to the python executable
 
bool m_executeInternalPythonCodeInDebugMode
 if true, button events, user interface connections to python methods... will be executed by debugger
 
bool m_includeItomImportBeforeCodeAnalysis
 string that is prepended to each script before syntax check (if m_includeItomImportBeforeCodeAnalysis is true)
 
QString m_includeItomImportString
 
wchar_t * m_pUserDefinedPythonHome
 
QList< QWeakPointer< ito::FunctionCancellationAndObserver > > m_activeFunctionCancellations
 
AutoReload m_autoReload
 
PythonWorkspaceUpdateQueue m_pyWorkspaceUpdateQueue
 debugger functionality
 
QAtomicInt m_interruptCounter
 

Static Private Attributes

static PyMethodDef PyMethodItomDbg []
 
static PyModuleDef PyModuleItomDbg
 
static QMutex instancePtrProtection
 
static QString fctHashPrefix = ":::itomfcthash:::"
 
static PythonEngineinstance = NULL
 

Friends

class ito::PythonItom
 
class ito::PyStream
 

Member Function Documentation

◆ checkVarnamesInWorkspace

ito::RetVal ito::PythonEngine::checkVarnamesInWorkspace ( bool globalNotLocal,
const QStringList & names,
QSharedPointer< IntList > existing,
ItomSharedSemaphore * semaphore = NULL )
slot

check if variable already exist in workspace, existing is 0 (non existing), 1 (existing, but can be overwritten), 2 (existing, not overwritable, e.g. function, method...)

◆ debugFile()

ito::RetVal ito::PythonEngine::debugFile ( const QString & pythonFileName)
protected

< first, clear all existing breakpoints

< setup connections for live-changes in breakpoints

< syntax error

< disconnect connections for live-changes in breakpoints

◆ debugFunction()

ito::RetVal ito::PythonEngine::debugFunction ( PyObject * callable,
PyObject * argTuple,
bool gilExternal = false )
protected

< setup connections for live-changes in breakpoints

< syntax error

< disconnect connections for live-changes in breakpoints

◆ debugString()

ito::RetVal ito::PythonEngine::debugString ( const QString & command)
protected

< first, clear all existing breakpoints

< setup connections for live-changes in breakpoints

< syntax error

< disconnect connections for live-changes in breakpoints

◆ getGlobalDictionary()

PyObject * ito::PythonEngine::getGlobalDictionary ( ) const
inline

returns reference to main dictionary (main workspace)

◆ getInstanceInternal()

PythonEngine * ito::PythonEngine::getInstanceInternal ( )
staticprivate

returns reference to local dictionary (workspace of method, which is handled right now). Is NULL if no method is executed right now.

◆ pickleSingleParam

ito::RetVal ito::PythonEngine::pickleSingleParam ( QString filename,
QSharedPointer< ito::Param > value,
const QString & valueName,
ItomSharedSemaphore * semaphore = NULL )
slot

save a single DataObject, PointCloud or PolygonMesh to an *.idc file using the python module 'pickle'.

Invoke this method by another thread (e.g. any GUI) to save a single object to an 'idc' file.

Parameters
filenameis the filename of the idc file
valueis the given DataObject, PointCloud or PolygonMesh in terms of ito::Param
valueNameis the name of the variable in the idc file
semaphoreis the control semaphore for an asynchronous call.

◆ PyDbgCommandLoop()

PyObject * ito::PythonEngine::PyDbgCommandLoop ( PyObject * pSelf,
PyObject * pArgs )
staticprivate

< check if key interrupt occurred

< do_quit instead of set_quit, since one member-variable is set in itoDebugger.py

◆ pythonAddBreakpoint()

ito::RetVal ito::PythonEngine::pythonAddBreakpoint ( const BreakPointItem & breakpoint,
int & pyBpNumber )
private

‍retNumber is new pyBpNumber, must now be added to BreakPointModel

◆ pythonCodeCheck

void ito::PythonEngine::pythonCodeCheck ( const QString & code,
const QString & filename,
bool fileSaved,
QPointer< QObject > sender,
QByteArray callbackFctName )
slot

these slots are only connected if python in debug-mode; while waiting these slots will be treated due to progressEvents-call in PythonEngine::PyDbgCommandLoop

public slot invoked by the scriptEditorWidget

This function calls the pyflakes or frosted python module. This module is able to check the syntax. It\B4s called from ScriptEditorWidget::triggerCodeChecker() and delivers the results by calling ScriptEditorWidget::codeCheckResultsReady(...).

Parameters
codeThis QString contains the code that the linter / code checker is supposed to check
filenameis the filename of the code (can also be an empty string if no filename is currently given)
fileSavedis true, if the code is equal to the given filename, else false
senderthis is a pointer to the object that called this method
Returns
no real return value. Results are returned by invoking ScriptEditorWidget::codeCheckResultsReady(...)

< this is the mode number, that is understood by the check method in itomSyntaxCheck.py

◆ pythonSetup()

void ito::PythonEngine::pythonSetup ( ito::RetVal * retValue,
QSharedPointer< QVariantMap > infoMessages )

< add all static, known function calls to python-module itomdbg

< prepare Python multithreading

◆ saveMatlabSingleParam

ito::RetVal ito::PythonEngine::saveMatlabSingleParam ( QString filename,
QSharedPointer< ito::Param > value,
const QString & valueName,
ItomSharedSemaphore * semaphore = NULL )
slot

save a single DataObject, PointCloud or PolygonMesh to a Matlab *.mat file using the python module 'scipy'.

Invoke this method by another thread (e.g. any GUI) to save a single object to an 'mat' file.

Parameters
filenameis the filename of the mat file
valueis the given DataObject, PointCloud or PolygonMesh in terms of ito::Param
valueNameis the name of the variable in the mat file
semaphoreis the control semaphore for an asynchronous call.

◆ setAutoReloader

void ito::PythonEngine::setAutoReloader ( bool enabled,
bool checkFile,
bool checkCmd,
bool checkFct )
slot

◆ startupAddModulesToItomModule()

ito::RetVal ito::PythonEngine::startupAddModulesToItomModule ( )
protected

< start python-type pythonStream, in order to redirect stdout and stderr

◆ startupLoadAndImportAdditionalModules()

ito::RetVal ito::PythonEngine::startupLoadAndImportAdditionalModules ( QSharedPointer< QVariantMap > & infoMessages)
protected

Member Data Documentation

◆ m_executeInternalPythonCodeInDebugMode

bool ito::PythonEngine::m_executeInternalPythonCodeInDebugMode
private

if true, button events, user interface connections to python methods... will be executed by debugger

decides if itom is automatically included in every source file before it is handed to the syntax checker

◆ PyMethodItomDbg

PyMethodDef ito::PythonEngine::PyMethodItomDbg
staticprivate
Initial value:
= {
{"pyDbgCommandLoop", PythonEngine::PyDbgCommandLoop, METH_VARARGS, "will be invoked if debugger stopped at the given filename and line"},
{"pyDbgClearBreakpoint", PythonEngine::PyDbgClearBreakpoint, METH_VARARGS, "will be invoked if debugger wants to remove a temporary breakpoint"},
{NULL, NULL, 0, NULL}
}
static PyObject * PyDbgCommandLoop(PyObject *pSelf, PyObject *pArgs)
Definition pythonEngine.cpp:4736

◆ PyModuleItomDbg

PyModuleDef ito::PythonEngine::PyModuleItomDbg
staticprivate
Initial value:
= {
PyModuleDef_HEAD_INIT, "itomDbgWrapper", NULL, -1, PythonEngine::PyMethodItomDbg,
NULL, NULL, NULL, NULL
}

The documentation for this class was generated from the following files: