4.7. Scripting Menu

Offers features for script editing and for running user scripts.

For details on user scripts, see Section 4.8, “User Scripts”

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 one can use the Python language, via an object-binding with PythonQt, an inhouse-development by MeVis.

This object-binding uses 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]Tip

It is possible (but not recommended) to include single line script statements in MDL script files.

Figure 4.22. Scripting Menu

Scripting Menu

4.7.1. Show Scripting Console

Opens a command line console to type in Python code. Useful for debugging when programming user interfaces dynamically. The console is opened in the context of the current network. Access is possible to

  • the contexts of all modules contained in the current network

  • (for macro modules) to all objects of included modules in a recursive descend

[Note]Note

If the current network is a macro network, the script console is opened in the context of the macro module. The same context is reached when opening the script console via the macro module's context menu, DebuggingShow Script Console.

Figure 4.23. Scripting Editor

Scripting Editor

Example listing in Python. The code has to be entered one line at a time, and without any indents. Make sure that the modules LocalImage and View2D exist in the current network, and that the modules have those specific instance names:

# 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")

Figure 4.24. Scripting Example

Scripting Example

4.7.2. Scripting Context Menu

The context menu of the Scripting View contains the usual commands for text editing, see also Section 4.2, “Edit Menu”.

Figure 4.25. Scripting Context Menu

Scripting Context 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. We recommend to stay with Python (see note above).

Clear

Clears the scripting console.

4.7.3. Edit Network Script

(Macro modules only) Opens the interface definition file (.script or .def) in the default text editor.

4.7.4. Start Network Script

(Macro modules only) Parses the interface definition file (.script or .def). Has the same effect as adding the macro module to a network and opening the module panel.