Table Of Contents

Adding Event Scripts to Widgets

Last Modified: November 20, 2020

Add a Python script to a widget in a dashboard to register and respond to events you specify.

  1. In Dashboards, open the dashboard you want to add a Python script to.
  2. Click »Edit.
  3. Add a widget to the panel.
  4. In the configuration pane, under Scripts, click + to add an event script to the widget. The Script window opens.
  5. Select the type of event.
    Type of Event Description
    Binding updated Executes when the values for the widget's binding updates.
    Loaded Registers when the widget loads.
    State changed Registers when the widget transitions from one state to another state.
    Timer Executes the script at the time interval you specify.
    User input Executes when a user provides new values

    Only output widgets have the option to create a script for the user input event.

  6. Enter a unique name for the main function, or the entry point that the script calls when the event executes.

    If you do not name the main function, Dashboards automatically wraps the script in an anonymous Python function and nests all of the functions inside of it.

  7. In the Script window, enter def and press Ctrl+Space to autogenerate the function definition and return statement.
  8. Add your Python code. You can call two Python functions from a script to access the dashboard widgets. Refer to the following table to learn more about the Python functions.
    Name of Function Description Function
    Get Widget Properties Returns the value of the requested widget property in the configuration pane.
    get_widget_prop(widget_name, property_name)
    Set Widget Properties Writes the value of the requested widget property.
    set_widget_prop(widget_name, property_name, value)
  9. When you finish adding your Python code, click OK. Dashboards lists the script in the configuration pane.
  10. Click Save and Play to view your dashboard.
  11. To make changes to the event script, double-click the event script in the configuration pane.

    You cannot change a script's event type. To do so, you must delete the existing event script and add it to a new event.

After you add an event script to a widget, add a virtual tag script to your dashboard to enable communication between your event script and widget.

Recently Viewed Topics