diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/Manual.dox b/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/Manual.dox deleted file mode 100644 index 343ef00178..0000000000 --- a/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/Manual.dox +++ /dev/null @@ -1,17 +0,0 @@ -/** -\page org_mitk_example_gui_pythonexample The Python Example - -\imageMacro{icon.png,"Icon of Python Example",2.00} - -\tableofcontents - -\section org_mitk_example_gui_pythonexampleOverview Overview -Describe the features of your awesome plugin here -
PythonService
and the QtPythonService
.
+The two implementations will be described in the following sections.
+
+\section python_sec2 The QtPythonService
+The QtPythonService
is a service implementation which is based on CTK and PythonQt.
+
+\warning The QtPythonService
is the legacy implementation of the Python Module. There might be issues especially regarding multithreading.
+The implementation might be deprecated in nearer future. It is therefore recommended to use the \ref python_sec3 unless you need Data Types, that are not yet supported by the PythonService
.
+
+\subsection qtpython_build Build instructions
+
+To build MITK with the QtPythonService
, the following CMake build options have to be enabled:
MITK_USE_Python3
QtPythonService
wrapping:
PythonService
is a service implementation that uses the Python/C API to execute Python Code. Additionally, SWIG is used to wrap some MITK datatypes in python.
+
+\subsection python_build Build instructions
+
+To build MITK with the QtPythonService
, the following CMake build options have to be enabled:
+MITK_USE_Python3
+ MITK_USE_SWIG
+ WRAP_DEFAULT
+ WRAP_PYTHON
+PythonService
, the following code is necessary:
+
+\code{.cpp}
+us::ModuleContext *context = us::GetModuleContext();
+std::string filter = "(Name=PythonService)";
+auto m_PythonServiceRefs = context->GetServiceReferencesPythonService
are described.
+
+\subsubsection python_executing_code Executing python code
+Python code can be executed in two ways:
+Execute(const std::string &pythonCommand, int commandType)
, code can be executed in form of a C++ string. The variable commandType
can have the following values:
+ IPythonService::SINGLE_LINE_COMMAND
for single statements
+ IPythonService::MULTI_LINE_COMMAND
for larger code snippets
+ IPythonService::EVAL_COMMAND
for isolated expressions, e.g. calculations.
+ commandType
is given, IPythonService::MULTI_LINE_COMMAND
is the default.
+ ExecuteScript(const std::string &pythonScript)
, whole python scripts can be executed. pythonScript
is the path to the script which should be executed.
+ If this file is located within the MITK sourcecode, the path can be determined by the method FindFile(const char *filename, const char *pathInSourceDir)
which is implemented in the class mitk::StandardFileLocations
. The following code shows an example of a script to be executed:
+ \code{.cpp}
+ std::string pythonFileName = "hello.py";
+ std::string fileName = mitk::StandardFileLocations::GetInstance()->FindFile( pythonFileName.c_str(), "Examples/Plugins/org.mitk.example.gui.pythonexample/resources");
+ m_PythonService->ExecuteScript(fileName);
+ \endcode
+GetVariableStack()
returns all variables from the python context. The variables are returned as a list of the type PythonVariable
. This contains for all variables the name, type and value as string format.
+ DoesVariableExist(const std::string& name)
returns a boolean, whether a variable with a given name
exists in the current python context.
+ GetVariable (const std::string& name)
returns the value of a python variable with the given name
as a string.
+PythonService
, images can be transferred from C++ to the python context.
+\note Currently, MITK images can be transferred and can be used in the python context either as MITK image as well or as SimpleITK image. If you want to use the MITK image data structure in the python context, you need to import pyMITK
in your script.
+
+\subsubsection python_images_mitk_python Transfer images from C++ to python
+To transfer images from C++ to python, the following methods are provided:
+CopyToPythonAsSimpleItkImage(mitk::Image::Pointer image, const std::string &stdvarName)
to transfer a MITK image to python which should be used as SimpleITK image in the python context.
+ CopyMITKImageToPython(mitk::Image::Pointer &image, const std::string &stdvarName)
to transfer a MITK image to python which should be used as MITK image in the python context as well.
+image
defines the image which should be transferred and stdvarName
the name of the image variable in the python context.
+
+\subsubsection python_images_python_mitk Transfer Images from python to C++
+To transfer images from python to C++, the following methods are provided:
+CopySimpleItkImageFromPython(const std::string &stdvarName)
for transferring a SimpleITK image from the python context to a MITK image in C++.
+ CopyMITKImageFromPython(const std::string &stdvarName)
for transferring a MITK image from the python context to a MITK image in C++.
+stdvarName
is the variable name of the image in the python context.
+
+\subsubsection python_multiple_images Transferring multiple images
+\note Multiple images can currently only be transferred from the python context to C++ and only, if they are provided as a list of MITK images in the python context.
+
+Sometimes, multiple images should be transferred from python to C++, e.g. when you have a multilabel segmentation and want to return the result as single images.
+If the images are stored in a list, this list can be transferred to C++, where it will be a std::vector
of the type mitk::Image::Pointer
.
+Therefore, the method CopyListOfMITKImagesFromPython(const std::string, &listVarName)
exists. listVarName
ist the name of the list variable of images in python, that should be transferred.
+
+\subsection python_observer Inform observer
+If a class should be notified as soon as a python command gets executed, the interface PythonCommandObserver
has to be implemented.
+Within this, only the method CommandExecuted(const std::string& pythonCommand)
has to be implemented, which is called as soon as the python service executes a command.
+To register the observer, the method AddPythonCommandObserver(PythonCommandObserver* observer)
has to be called with the implemented observer class as parameter.
+Analogously, the observer can be removed with the method RemovePythonCommandObserver(PythonCommandObserver* observer)
+
+With the method GetNumberOfObserver()
, the number of currently registered observers can be determined.
+
+*/
\ No newline at end of file