Skip to main content

Python-based Data Binding

The Python Connector Library is a simple library written in python and c++ that provides functionality to start and load scene composer binary assets and interact with a predefined set of data binding items (Variant) through python scripting.

Python Connector Library Package

The main functionality of the library is contained in two files, CanderaAppConnector.py [1] and BindingSourceEnum.py [2]. These files contain three classes.

  • CanderaAppConnector: This is the main class to be used to play assets and interact with them using data binding
  • BindingSourceEnum: A python enum generated by the build pipeline that contains the enum keys to be used when setting and getting data binding items. The keys underlay the nomenclature "SOURCE<sourceIndex>ITEM<itemIndex>". Source - and item index start at one and go to ten, as we currently have ten predefined binding sources and ten items per source.
  • Logger: Logger class that my be used to generate logs with compliant format and logging levels

The sources and types listed above are contained in a file system python package that can be installed with pip.

pip install path/to/python/library/root/folder

Note: It is suggested to install the library to a virtual environment and not to the global python installation. For an exemplary usage refer to the Blood Pressure Sample documentation and source code.

[1]: cgi_studio_player/src/PlayerConnector/Python/CanderaAppConnector/CanderaAppConnector.py
[2]: cgi_studio_player/src/PlayerConnector/Python/Generated/BindingSourceEnum.py

Workflow

The general workflow using the python connector library package consists of:

  1. Constructing the library with the connector library binary contained in the delivered package (PlayerConnectorLibrary)
  2. Initializing the library with the asset binary
  3. Optionally register data binding callbacks
  4. Continuously calling step to invoke the render loop and internal message delivery
  5. Interact with data bindings. Note that internally, changes to the data bindings are reflected on the view when step is called
  6. Shutdown library and gracefully exit program

Documentation

Constructor

Creates and instance of this class. Expects and absolute or relative path to the player connector binary as parameter.

Parameters
  1. BinaryLibraryPath: Absolute or relative path to the player connector binary

Init

Initializes the player with the provided asset path. Expects an absolute or relative path to the asset binary as parameter. Must be called before every other method. Returns a bool if the operation was successful.

Parameters
  1. AssetPath: Absolute or relative path to the asset binary
Returns Boolean if operation was successful

Step

Invokes the internal message processing and render loop execution. Needs to be called continuously. Databinding updates are reflected internally during the invocation of this method. Returns a bool if the operation was successful.

Parameters None
Returns Boolean if operation was successful

SetIntValue

Sets an integer value to a predefined databinding source item. 

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
  2. Value: The integer value
Returns Boolean if operation was successful

SetBoolValue

Sets a bool value to a predefined databinding source item. 

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
  2. Value: The bool value
Returns Boolean if operation was successful

SetStringValue

Sets a string to a predefined databinding source item. 

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
  2. Value: The string
Returns Boolean if operation was successful

SetFloatValue

Sets a float value to a predefined databinding source item. 

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
  2. Value: The float value
Returns Boolean if operation was successful

GetIntValue

Gets an int value from a predefined databinding source item.

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
Returns The integer value

GetBoolValue

Gets a bool value from a predefined databinding source item.

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
Returns The bool value

GetStringValue

Gets a string from a predefined databinding source item.

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
Returns The string

GetFloatValue

Gets a float value from a predefined databinding source item.

Parameters
  1. BindingSourceItem: Enum that specifies the binding source item. Enum is defined in Generated/BindingSourceEnum.py
Returns The float value

RegisterCallback

Registers a callback method. Multiple methods can be registered. Passed method must have two parameters. First param is  BindingSourceItem and second parameter is value.

Parameters
  1. CallbackFn: Callable type with two parameters
Returns Boolean if operation was successful

ShutDown

Shuts down the asset player and frees up allocated resources.

Parameters None
Returns Boolean if operation was successful