MeVisLab Scripting Reference
Python

Introduction

MeVisLab supports Python for scripting using PythonQt (see http://pythonqt.sourceforge.net for details). See http://www.python.org for details on the language. For details on the mapping of datatypes from Qt to Python and vice versa, see the PythonQt website.

MeVisLab adds a module called "mevis" to the Python interpreter, which can be used to access MeVisLab's global MLAB, MLABFileDialog, MLABFileManager, ... objects.

from mevis import *
MLAB.log("test")
void log(const QString &text)
Logs the given text to the console.

For an example of Python usage in MeVisLab, have a look at the TestPython module in MeVisLab.

Python modules

MeVisLab comes with the complete Python standard modules. When you create MeVisLab MacroModules, you can implement your Python code by adding "source" tags to the "Commands" section.

Commands {
source = $(LOCAL)/YourModuleName.py
...
}

We recommend that you only create one Python file per module and implement everything else as Python modules/packages. To make your module aware of python modules that you have created, you can use the "importPath" tag. We recommend to put all related python modules and packages into one subdirectory and to add the path to the importPath:

Commands {
source = $(LOCAL)/YourModuleName.py
importPath = $(LOCAL)/../../Wherever/YourSharedPythonModules
importPath = $(LOCAL)/LocalSharedPythonModules
}

Then you can just do

import YourPythonModule

to import your own Python modules in the script code of your MacroModule. You can as well add "importPath = $(LOCAL)" to the path to make everything in that directory available to the python import mechanism, but this might be confusing, because you could import the py file of your MacroModule by error.

Alternatively, you can place your Python modules/packages into the YourPackage/Modules/Scripts/python directory. This makes your modules/packages available to all MeVisLab modules that make use of python, since YourPackage/Modules/Scripts/python is added to the sys.path of the Python interpreter.

NumPy Module

MeVisLab is shipped with the NumPy library (see http://numpy.scipy.org/). NumPy's ndarray class is used to make ML subimages available to Python.

Python Image Processing

MeVisLab allows to implement ML image processing modules in Python. For details, see Python Image Processing.

Python Qt Binding

MeVisLab offers an (almost) complete binding to the Qt framework. For details, see Python Qt Binding.

Python Object Wrappers

MeVisLab offers PythonQt wrappers to access C++ objects in Python scripting. For details, see Object Wrappers.

Python C-Extensions

MeVisLab supports adding user Python C-Extensions. The MeVisLab SDK ships the python include files and libraries to link against our python version. To link against our Python version, add CONFIG += python to your profile. NOTE: Compiling your own C-Extensions might still cost some extra effort, since the c extensions do not follow the normal shared library naming convention (*.pyd on Windows, *.so on Linux/Mac OS X without a lib prefix). If you want to add your own C-Extensions, ask on the MeVisLab forum and you will get assistance. Python C-Extensions can be located in your Package at YourPackage/Modules/Scripts/python or a subdir of that directory (which is a package effectively).

Debugging

MATE (the text editor that comes with MeVisLab) features a built-in Python debugger which requires no additional setup. In addition to this, MeVisLab supports remote debugging of Python code.