Overview

Aqtra Platform provides the ability to use Python for multiple purposes as a convenient widely known scripting/programming language.

Python scripts supported by Aqtra Platform need to use version 3.0 of Python as described here: https://docs.python.org/3/. The full developer’s guide can be found at Python Developer’s Guide.

The version of Python that Aqtra Platform uses is Iron Python which provides an interface to C# code. It provides two important libraries that need to be imported at the start of a script — clr and system. These libraries provide access to the Aqtra Platform entities that can be queried and controlled from inside the script.

Ways to use Python scripts in Aqtra Platform

There are two main methods of using Python with Aqtra Platform:

  1. As part of Component Script which is a part of any Component. It allows controlling application forms designed and executed using Aqtra Platform, as well as providing custom subscripts that can be run as a reaction to some event, such as a customer pressing a button.
  2. As part of Dataflow with the help of the Execute Script step. This step allows to designate scripts for Python actions such additional data conversion, establishing Dataflow model variables, and other actions.

Using Python as part of Component Script

Component Script is part of any component and is accessible via the Component Script button in the main component configuration window (starting from 0.6.х, earlier it was accessible via Settings > Component Script).

Component Script consists of two parts: the main part that is executed every time when a component page is rendered and Python functions (in the following format: def function name function body ; ) that can be called in different cases described below.

Python functions can be called from Component Script in the following cases:

  1. Functions can be called directly by user action, such as by pressing a button, if the Action parameter of the button is Execute Script. If you select this Action you need to enter the name and parameters of the call (if any) of your script in the fields provided by Aqtra Studio
  2. Functions can be called by one of the UI controls from the active window of the user interface if triggered by an event (Events) that supports this control. In detail, the events supported by the UI controls are described in the sections devoted to the description of the existing UI controls. An example of a supported control is, for instance, On focus change - when the focus moves to or from this UI control, - or On value change - when a control field value changes (this, for example, can be used to validate changes)
    1. To track field value changes you need to define the function in the component script and then pass on to a UI control element, such as text field and so on, then pass on to the "Events" section and enter the name of your script to the "On value change" field.
    2. Note, that this function will be called only if the field value changes and the control element focus moves from this element of the user interface.
  3. Functions can be called based by subscribing to the changes via the context.DataModel.Model.Subscribe() method - see below for the detailed description
    1. The simplest way to do this is to define a catch-all changes function (e.g. def check_all_changes()) in your Component Script, and then subscribe to it.
    2. The simplest way to do this is to define a catch-all changes function (e.g. def check_all_changes()) in your Component Script, and then subscribe to it.

Using Python to access Aqtra Platform components

To access Aqtra Platform components, first IronPython crl libraries need to be imported as shown below italic, and links to the Aqtra Platform libraries need to be added. Here's an example below.

*#Add IronPython library that imports system CRL (.NET) names into Python

import clr
clr.AddReference("Liminuza.Platform.Shared")*

After the import described above you can access Aqtra Platform components and functions from within a Python script using the "context" system variable.

Using context.Model & context.DataModel