MeVisLab Scripting Reference
|
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.
For an example of Python usage in MeVisLab, have a look at the TestPython module in MeVisLab.
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.
We recommend that you only create one Python file per module and implement everthing 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 to the importPath:
Then you can just do
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.
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.
Starting with MeVisLab 2.1, MeVisLab allows to implement ML image processing modules in Python. For details, see Python Image Processing.
Starting with MeVisLab 2.1, MeVisLab offers an (almost) complete binding to the Qt framework. For details, see Python Qt Binding.
Starting with MeVisLab 2.1, MeVisLab offers PythonQt wrappers to access C++ objects in Python scripting. For details, see Object Wrappers.
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 againt 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. Starting with MeVisLab 2.1, Python C-Extensions can be located anywhere, so the best place is YourPackage/Modules/Scripts/python or a subdir of that directory (which is a package effectively).
Starting with the MeVisLab 2.2 release, 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. This has been tested with two publically available Python Remote Debuggers. The following describes how to configure MeVisLab for those debuggers:
Winpdb is a nice open-source cross-plattform Python debugger. The following describes how to use it to debug Python code inside of MeVisLab. It is recommended if you only need a debugger and not a complete programming environment for Python.
On the MeVisLab side:
On the Debugger side:
Now you are done and can set breakpoints in any MeVisLab module that uses Python. You can also call "Attach Python Remote Debugger" on another module in MeVisLab, which will open that file in the already connected debugger.
PyDev is an open source Python development enviroment for Eclipse (http://pydev.org/index.html), and it not only features a Python remote debugger but it also enables code completion, customizable syntax highlighting, inline code analysis and some refactoring features. Eclipse on the other hand is an open source IDE for which there exist a lot of plugins, e.g. other programming languages or SDKs, version control, modeling, databases etc.
There are two possible ways to add other libraries for code completion / inline syntax check:
On the Debugger side:
On the MeVisLab side:
Now you are done and can set breakpoints in any MeVisLab module that uses Python. You can also call "Attach Python Remote Debugger" on another module in MeVisLab, which will open that file in the already connected debugger. The debugger remains attached to the modules until MeVisLab is closed (so you do not need to restart the debugger after you recreated your module, for example).