Scripting

Example 2.5: Interactions via Python scripting

Example 2.5: Module Interactions Using Python Scripting

Introduction

This chapter will give you an overview over Python scripting in MeVisLab. Here, no introduction into Python will be given. However, basic knowledge in Python is helpful. Instead, we will show how to integrate and use Python in the MeVisLab SDK.

In fact, nearly everything in MeVisLab can be done via Python scripting: You can add modules to your network, or remove modules, you can dynamically establish and remove connections and so on. But, much more important: You can access module inputs and outputs, as well as module fields to process their parameters and data. You can equip user interfaces and panel with custom functionalities. Python can be used to implement module interactions. When you open a panel or you press a button in a panel, the executed actions are implemented via Python scripting.

Example 2.5.1: The module RunPythonScript

Example 2.5.1: The module RunPythonScript

Introduction

The module RunPythonScript allows to execute Python scripts from within a MeVisLab network. You can draw parameter connection from modules to RunPythonScript and back, to process parameter fields using Python scripting.

Steps to do

Develop your network

In this example, we like to dynamically change the color of a cube in an Open Inventor scene. For that, add and connect the following modules as shown.

Example 2.5.2: Module interactions via Python scripting

Example 2.5.2: Module interactions via Python scripting

Introduction

In this example, you will learn how to add Python scripting to your User Interface. The network used in Chapter V will be used for creating the macro module.

Steps to do

Creating the macro module

First, we condense the example network into a macro module and then we create a panel for that module. To create a macro module use the Project Wizard, which you find under [ File → Run Project Wizard ]. Select Macro module and press Run.

Example 3: Creating a simple application

Example 3: Creating a simple application

Introduction

In the previous examples, you already learned how to create macro modules, user interfaces and how to interact with your UI via Python scripting.

In this example, you will learn how to create a simple Prototype application in MeVisLab including a User Interface with 2D and 3D viewer. You will learn how to implement field listeners and react on events.

Steps to do

Create your network

Start with an empty network and add the Module ImageLoad to your workspace. Then add a View2D and View3D to your workspace and connect the modules as seen below.