Scripting is used to implement the dynamic functionality of module user interfaces and applications (which are defined as macro modules) in MeVisLab.
Scripting is done in the context of a module. Via the script context variable of the module (ctx), access is given to the module instance itself as well as to all members of the module like fields, input/outputs, and GUI controls. This way, getting/setting field values (module parameters), connecting/disconnecting fields, implementing dynamic user interfaces, and much more can be done dynamically .
In the context of an MLABMacroModule, access to the contexts of all modules contained in the modules macro network is available (recursive descend).
For scripting in MeVisLab, two script languages are supported:
Python: via binding with PythonQt, an inhouse-development by MeVis.
JavaScript: as QSA — Qt Script for Applications, an implementation of a subset of ECMAScript 4.0.
Both script languages have the same “view” on the MeVisLab API as both use the Qt Meta Object System to find out about the MLAB object features.
For the doxygen documentation of the scripting interface, see the MeVisLab Scripting Reference.
Tip | |
---|---|
It is possible (but not recommended) to include single line script statements in MDL script files. |
The Scripting View works like the Scripting console that can be opened via the menu bar, Scripting → Show Scripting Console.
Example listing in Python (the code has to be entered one line at a time, and without any indents):
# get module context module = ctx.module("LocalImage") # set/get module field value filename = module.field("trueName").value module.field("name").value = "$(DemoDataPath)/bone.tiff" # connect fields ctx.connectField("View2D.inImage","LocalImage.outImage") # open GUI window control window = ctx.module("View2D").createWindow("Viewer") window.setTitle("HelloWorld") ctx.module("View2D").showWindow("Viewer")
The context menu of the Scripting View contains the usual commands for text editing, see also Section 4.2, “Edit Menu”.
In addition, three options are available:
Show MeVisLab Scripting Help
Opens the Scripting Reference documentation (HTML) in the default web browser.
Scripting Language
Can be switched from the default (as defined in the Preferences) to the other script language.
Clear
Clears the scripting console.
© 2013 MeVis Medical Solutions AG