The Interpreter class This class manage the python interpreter and hold a lot helper functions for handling python stuff. More...
#include <Interpreter.h>
Public Member Functions | |
InterpreterSingleton () | |
~InterpreterSingleton () | |
execution methods | |
std::string | runString (const char *psCmd) |
Run a statement on the python interpreter and gives back a string with the representation of the result. More... | |
std::string | runStringWithKey (const char *psCmd, const char *key, const char *key_initial_value="") |
Run a statement on the python interpreter with a key for exchanging strings. More... | |
Py::Object | runStringObject (const char *sCmd) |
Run a statement on the python interpreter and return back the result object. More... | |
void | runInteractiveString (const char *psCmd) |
Run a statement on the python interpreter and gives back a string with the representation of the result. More... | |
void | runFile (const char *pxFileName, bool local) |
Run file (script) on the python interpreter. More... | |
void | runStringArg (const char *psCom,...) |
Run a statement with arguments on the python interpreter. More... | |
void | runMethodVoid (PyObject *pobject, const char *method) |
runs a python object method with no return value and no arguments More... | |
PyObject * | runMethodObject (PyObject *pobject, const char *method) |
runs a python object method which returns a arbitrary object More... | |
void | runMethod (PyObject *pobject, const char *method, const char *resfmt=nullptr, void *cresult=nullptr, const char *argfmt="()",...) |
runs a python method with arbitrary params More... | |
Cleanup | |
int | cleanup (void(*func)()) |
Register a cleanup function to be called by finalize(). More... | |
void | finalize () |
This calls the registered cleanup functions. More... | |
void | systemExit () |
This shuts down the application. More... | |
external wrapper libs | |
here we can access external dynamically loaded wrapper libs done e.g. by SWIG or SIP | |
PyObject * | createSWIGPointerObj (const char *Modole, const char *TypeName, void *Pointer, int own) |
generate a SWIG object More... | |
bool | convertSWIGPointerObj (const char *Module, const char *TypeName, PyObject *obj, void **ptr, int flags) |
void | cleanupSWIG (const char *TypeName) |
PyTypeObject * | getSWIGPointerTypeObj (const char *Module, const char *TypeName) |
methods for debugging facility | |
void | dbgObserveFile (const char *sFileName="") |
sets the file name which should be debugged More... | |
void | dbgSetBreakPoint (unsigned int uiLineNumber) |
sets a break point to a special line number in the current file More... | |
void | dbgUnsetBreakPoint (unsigned int uiLineNumber) |
unsets a break point to a special line number in the current file More... | |
void | dbgStep () |
One step further. More... | |
Module handling | |
bool | loadModule (const char *psModName) |
void | addPythonPath (const char *Path) |
Add an additional python path. More... | |
PyObject * | addModule (Py::ExtensionModuleBase *) |
Add a module and return a PyObject to it. More... | |
void | cleanupModules () |
Clean-up registered modules. More... | |
static void | addType (PyTypeObject *Type, PyObject *Module, const char *Name) |
startup and singletons | |
const char * | init (int argc, char *argv[]) |
init the interpreter and returns the module search path More... | |
int | runCommandLine (const char *prompt) |
void | replaceStdOutput () |
static InterpreterSingleton & | Instance () |
static void | Destruct () |
static helper functions | |
PyObject * | getValue (const char *key, const char *result_var) |
static const std::string | strToPython (const char *Str) |
replaces all char with escapes for usage in python console More... | |
static const std::string | strToPython (const std::string &Str) |
The Interpreter class This class manage the python interpreter and hold a lot helper functions for handling python stuff.
InterpreterSingleton::InterpreterSingleton | ( | ) |
Referenced by Instance().
InterpreterSingleton::~InterpreterSingleton | ( | ) |
PyObject * InterpreterSingleton::addModule | ( | Py::ExtensionModuleBase * | mod | ) |
Add a module and return a PyObject to it.
Referenced by Gui::PythonDebugModule::init_module(), Cloud::initModule(), CloudGui::initModule(), DraftUtils::initModule(), Drawing::initModule(), DrawingGui::initModule(), Fem::initModule(), FemGui::initModule(), Image::initModule(), ImageGui::initModule(), Import::initModule(), ImportGui::initModule(), Inspection::initModule(), InspectionGui::initModule(), Measure::initModule(), Mesh::initModule(), MeshGui::initModule(), MeshPart::initModule(), MeshPartGui::initModule(), Part::initModule(), PartGui::initModule(), PartDesign::initModule(), PartDesignGui::initModule(), Path::initModule(), PathGui::initModule(), PathSimulator::initModule(), Points::initModule(), PointsGui::initModule(), Raytracing::initModule(), RaytracingGui::initModule(), Reen::initModule(), ReverseEngineeringGui::initModule(), Robot::initModule(), RobotGui::initModule(), SketcherGui::initModule(), Spreadsheet::initModule(), SpreadsheetGui::initModule(), Start::initModule(), StartGui::initModule(), Surface::initModule(), SurfaceGui::initModule(), TechDraw::initModule(), TechDrawGui::initModule(), TestGui::initModule(), Web::initModule(), and WebGui::initModule().
void InterpreterSingleton::addPythonPath | ( | const char * | Path | ) |
Add an additional python path.
Referenced by App::Application::processFiles().
|
static |
References Base::getTypeAsObject().
Referenced by Gui::Application::Application(), and Fem::SMESH_HypothesisPy< T >::init_type().
int InterpreterSingleton::cleanup | ( | void(*)() | func | ) |
Register a cleanup function to be called by finalize().
The cleanup function will be called with no arguments and should return no value. At most 32 cleanup functions can be registered. When the registration is successful 0 is returned; on failure -1 is returned. The cleanup function registered last is called first. Each cleanup function will be called at most once. Since Python's internal finalization will have completed before the cleanup function, no Python APIs should be called by func.
Referenced by PathPythonGui.simple_edit_panel.SimpleEditPanel::abort(), PathScripts.PathDressupPathBoundaryGui.TaskPanel::abort(), PathScripts.PathDressupTagGui.PathDressupTagTaskPanel::abort(), PathScripts.PathDressupDogbone.TaskPanel::accept(), PathScripts.PathDressupPathBoundaryGui.TaskPanel::accept(), PathScripts.PathDressupTagGui.PathDressupTagTaskPanel::accept(), PathScripts.PathJobGui.TaskPanel::accept(), PathScripts.PathOpGui.TaskPanel::accept(), PathScripts.PathDressupDogbone.TaskPanel::reject(), PathScripts.PathDressupPathBoundaryGui.TaskPanel::reject(), PathScripts.PathDressupTagGui.PathDressupTagTaskPanel::reject(), PathScripts.PathJobGui.TaskPanel::reject(), and PathScripts.PathOpGui.TaskPanel::reject().
void InterpreterSingleton::cleanupModules | ( | ) |
Clean-up registered modules.
Referenced by finalize().
void InterpreterSingleton::cleanupSWIG | ( | const char * | TypeName | ) |
References Swig_python::cleanupSWIG_T().
Referenced by Gui::Application::~Application().
bool InterpreterSingleton::convertSWIGPointerObj | ( | const char * | Module, |
const char * | TypeName, | ||
PyObject * | obj, | ||
void ** | ptr, | ||
int | flags | ||
) |
References Swig_python::convertSWIGPointerObj_T().
Referenced by Gui::View3DInventorPy::addDraggerCallback(), Gui::View3DInventorPy::addEventCallbackPivy(), Gui::View3DInventorPy::dumpNode(), Gui::FreeCADGui_exportSubgraph(), Gui::ViewProviderPythonFeatureImp::getDetail(), Gui::ViewProviderPythonFeatureImp::getDetailPath(), Gui::View3DInventorPy::removeDraggerCallback(), Gui::View3DInventorPy::removeEventCallbackPivy(), Gui::SoQtOffscreenRendererPy::render(), Gui::Application::sCoinRemoveAllChildren(), Gui::View3DInventorViewerPy::setSceneGraph(), and Gui::View3DInventorViewerPy::setupEditingRoot().
PyObject * InterpreterSingleton::createSWIGPointerObj | ( | const char * | Modole, |
const char * | TypeName, | ||
void * | Pointer, | ||
int | own | ||
) |
generate a SWIG object
References Swig_python::createSWIGPointerObj_T().
Referenced by Gui::FreeCADGui_subgraphFromObject(), Gui::View3DInventorPy::getCameraNode(), Gui::ViewProviderPythonFeatureImp::getDetailPath(), Gui::ViewProviderPythonFeatureImp::getElement(), Gui::ViewProviderPythonFeatureImp::getElementPicked(), Gui::View3DInventorPy::getSceneGraph(), Gui::View3DInventorViewerPy::getSceneGraph(), Gui::View3DInventorViewerPy::getSoEventManager(), and Gui::View3DInventorViewerPy::getSoRenderManager().
void InterpreterSingleton::dbgObserveFile | ( | const char * | sFileName = "" | ) |
sets the file name which should be debugged
void InterpreterSingleton::dbgSetBreakPoint | ( | unsigned int | uiLineNumber | ) |
sets a break point to a special line number in the current file
void InterpreterSingleton::dbgStep | ( | ) |
One step further.
void InterpreterSingleton::dbgUnsetBreakPoint | ( | unsigned int | uiLineNumber | ) |
unsets a break point to a special line number in the current file
|
static |
void InterpreterSingleton::finalize | ( | ) |
This calls the registered cleanup functions.
References cleanupModules().
Referenced by App::Application::destruct(), and draftguitools.gui_trackers.ghostTracker::remove().
PyTypeObject * InterpreterSingleton::getSWIGPointerTypeObj | ( | const char * | Module, |
const char * | TypeName | ||
) |
References Swig_python::getSWIGPointerTypeObj_T().
PyObject * InterpreterSingleton::getValue | ( | const char * | key, |
const char * | result_var | ||
) |
const char * InterpreterSingleton::init | ( | int | argc, |
char * | argv[] | ||
) |
init the interpreter and returns the module search path
References PythonStdOutput::init_type().
Referenced by DocumentObject.DocumentObject::onChanged().
|
static |
References InterpreterSingleton().
Referenced by Base::Interpreter().
bool InterpreterSingleton::loadModule | ( | const char * | psModName | ) |
void InterpreterSingleton::replaceStdOutput | ( | ) |
int InterpreterSingleton::runCommandLine | ( | const char * | prompt | ) |
Referenced by StdCmdCommandLine::activated(), and App::Application::runApplication().
void InterpreterSingleton::runFile | ( | const char * | pxFileName, |
bool | local | ||
) |
Run file (script) on the python interpreter.
References Base::FileInfo::toStdWString().
Referenced by Gui::PreferencePack::apply(), TechDraw::DrawParametricTemplate::execute(), App::Application::processFiles(), and Gui::MacroManager::run().
void InterpreterSingleton::runInteractiveString | ( | const char * | psCmd | ) |
Run a statement on the python interpreter and gives back a string with the representation of the result.
References Base::Exception::setMessage().
void InterpreterSingleton::runMethod | ( | PyObject * | pobject, |
const char * | method, | ||
const char * | resfmt = nullptr , |
||
void * | cresult = nullptr , |
||
const char * | argfmt = "()" , |
||
... | |||
) |
runs a python method with arbitrary params
Referenced by Gui::PythonCommand::activated().
runs a python object method which returns a arbitrary object
Referenced by Gui::PythonCommand::getHelpUrl(), Gui::PythonCommand::PythonCommand(), and Gui::PythonGroupCommand::PythonGroupCommand().
void InterpreterSingleton::runMethodVoid | ( | PyObject * | pobject, |
const char * | method | ||
) |
runs a python object method with no return value and no arguments
Runs a member method of an object with no parameter and no return value void (void).
There are other methods to run with returns
Referenced by Gui::PythonCommand::activated().
std::string InterpreterSingleton::runString | ( | const char * | psCmd | ) |
Run a statement on the python interpreter and gives back a string with the representation of the result.
References Base::PyException::ThrowException().
Referenced by Gui::Command::addModule(), TechDraw::DrawViewArch::execute(), TechDraw::DrawViewDraft::execute(), StartGui::Workbench::loadStartPage(), TestGui::UnitTestDialog::on_startButton_clicked(), DraftUtils::DraftDxfRead::OnReadDimension(), Import::ImpExpDxfRead::OnReadDimension(), Gui::GestureNavigationStyle::onRollGesture(), App::Application::processCmdLineFiles(), Sandbox::PythonThread::run(), App::Application::runApplication(), Gui::Application::runInitGuiScript(), runStringArg(), Gui::Application::setActiveDocument(), and Gui::Application::sOpen().
void InterpreterSingleton::runStringArg | ( | const char * | psCom, |
... | |||
) |
Run a statement with arguments on the python interpreter.
References runString().
Referenced by TechDraw::DrawViewArch::execute(), TechDraw::DrawViewDraft::execute(), TechDraw::DrawDimHelper::makeDistDim(), TechDraw::DrawDimHelper::makeExtentDim(), DraftUtils::DraftDxfRead::OnReadDimension(), Import::ImpExpDxfRead::OnReadDimension(), App::Application::processCmdLineFiles(), App::Application::processFiles(), TechDraw::DrawViewCollection::unsetupObject(), TechDraw::DrawPage::unsetupObject(), and TechDraw::DrawViewPart::unsetupObject().
Py::Object InterpreterSingleton::runStringObject | ( | const char * | sCmd | ) |
Run a statement on the python interpreter and return back the result object.
std::string InterpreterSingleton::runStringWithKey | ( | const char * | psCmd, |
const char * | key, | ||
const char * | key_initial_value = "" |
||
) |
Run a statement on the python interpreter with a key for exchanging strings.
runStringWithKey(psCmd, key, key_initial_value) psCmd is python script to run key is the name of a python string variable the script will have read/write access to during script execution.
It will be our return value. key_initial_value is the initial value c++ will set before calling the script If the script runs successfully it will be able to change the value of key as the return value, but if there is a runtime error key will not be changed even if the error occurs after changing it inside the script.
References Base::PyException::ThrowException().
|
static |
replaces all char with escapes for usage in python console
Referenced by Gui::PropertyEditor::PropertyEnumItem::setValue(), Gui::PropertyEditor::PropertyStringListItem::setValue(), and Gui::Command::strToPython().
|
static |
References strToPython().
Referenced by strToPython().
void InterpreterSingleton::systemExit | ( | ) |
This shuts down the application.