Python Dialogs

Defining Dialogs in Python scripts

Product line

Standard

|

Expert

Operating mode

CLOUD ABO

|

ON-PREMISES

Modules

Services & CRM

Budget & Phases

Purchases

Resource Planning

Business Intelligence

Created: 16.11.2016
Machine translated
Updated: 11.07.2019 | Return value of the buttons described in more detail.

As of version 6.1 there is a dialog function, with which dialogs can be defined in Python scripts and shown by the script. The dialog call is made via the API function

vtcapp.showcustomdialog(dialog definition, initial values)

Dialog Definition

To create the dialog, there is an element called Dialog with the following properties:

Title Sets the title of the dialog
Width

Sets the width of the dialog. For example, the dialog in the example below has set Width=”500”.

The height of the dialog is determined by the quantity of controls placed on it.

InitialFocus

Here you can specify where the focus is when the dialog is opened. The options are First, Last and None. If nothing is set, First applies.

Buttons

Buttons can be placed on the dialog to which dialog commands can be linked.

The dialog offers the following commands:

  • CloseCommand: Close dialog with own button.
  • OkCommand: Close dialog with the result 'Ok’.
  • CancelCommand: Close dialog with the result 'Cancel’.

OkCommand and CancelCommand are usually placed in the Dialog.Buttons. CloseCommand can be used to close the dialog with its own button. The dialog result is 'Ok’ and in the Values Dictionary the corresponding button has the value 'True’.

Controls

As with customizing, the required controls are placed on the dialog. Basically, the same controls can be used as in UI Customizing. Each control for which values are to be set or queried needs a unique name within the dialog.

For controls that have more than one property, secondary properties are separated by the period, e.g. ListBox.Items, SelectionBox.Items.

The following remarks apply:

  • The AdditionalFieldComboBox cannot be used in this context.
  • The custom dialogs do not allow binding to business objects, e.g. event scripts.
  • Configurations of controls via OCL, such as <ProjectComboBox Name=”Projekt” Label=”Projekt” ListExpression=”Projekt.allinstances->select(aktiv)” />, are possible. The OCL is always global, because there is no context.

Initial Values

The initial values of the feature are passed as an argument and the result values are returned as a result. Both the initial values and the return values are passed as a Python dictionary. The keys in the dictionary correspond to the control names, e.g.

initValues = {}
initValues["AuswahlBox.Items"] = ("Option 1", "Option 2", "Option 3")
initValues["Value1"] = "Default 1"

Assign a default value

A default value can also be assigned (e.g. if the form is not completely filled in and you have to call it again with already entered data), e.g.

initValues["Projekt.SelectedValue"] = Projekt.eval("boldid")

SelectedValue is a property of the UI control used.

Example

This dialog call looks like this in Python:

# Python Script für Custom Dialog
dlgDefinition="""
<Dialog Title="Test Dialog" Width="500">
    <TextBlock Text="Bitte geben Sie folgende Werte ein:" Appearance="Info"/>
    <Group Label="Auswahl" ShowLabel="True">
        <ListBox Name="AuswahlBox" Lines="6"/>
    </Group>
    <ProjectComboBox Name="Projekt" Label="Projekt"/>
    <TextBox Name="Value1" Label="Wert 1"/>
    <CheckBox Name="Check1" Label="Option 1"/>
    <Group Appearance="NoSpacing" FlexWidth="0" Width="300" HorizontalAlignment="Left">
        <Button Name="Option21" FlexWidth="0" Width="100" Text="Option21" Command="{Binding CloseCommand}" />
        <Button Name="Option22" FlexWidth="0" Width="100" Text="Option22" Command="{Binding CloseCommand}" />
        <Button Name="Option23" FlexWidth="0" Width="100" Text="Option23" Command="{Binding CloseCommand}" />
    </Group>
    <Dialog.Buttons>
        <Button Text="OK" IsAccept="True" Command="{Binding OkCommand}" />
        <Button Text="Cancel" IsCancel="True" Command="{Binding CancelCommand}" />
    </Dialog.Buttons>
</Dialog>
"""
initValues = {}
initValues["AuswahlBox.Items"] = ("Option 1", "Option 2", "Option 3")
initValues["Value1"] = "Default 1"
ok, values = vtcapp.showcustomdialog(dlgDefinition, initValues)
if ok:
    vtcapp.msgbox('Dialog OK, Werte: %s' % values)

Return Value

The showcustomdialog feature returns a tuple of Return-Value and Values-Dictionary. Return-Value is true for OK and false for Cancel. For each control with a name, there is an entry (name/value) in the Values-Dictionary. The controls return the following values:

  • Input control: input value
  • ListBox: Index of the selected entry
  • DataGrid: Index of the selected entry
  • Button: 'True’, if this button has triggered the CloseCommand, otherwise 'False’ (see buttons in the dialog definition)

Certain input controls (e.g. ComboBox, ReferenceBox, etc.) do not provide the object, but its internal ID.

Example

Example of a return value from the example above:

The reading of the individual values from the Values Dictionary takes place as follows, e.g.:

ProjektID = values["Projekt"]