smartinspectpython.siconfiguration

Module: siconfiguration.py

Revision History

Date Version Description
2023/05/30 3.0.0.0 Initial Version.

@export
class SIConfiguration:

Responsible for handling the SmartInspect configuration and loading it from a file.

This class is responsible for loading and reading values from a SmartInspect configuration file. For more information, please refer to the SmartInspect.LoadConfiguration method.

Threadsafety:

This class is not guaranteed to be thread-safe.

SIConfiguration()

Initializes a new instance of the class.

Count: int

Returns the number of key/value pairs of this SmartInspect configuration.

def Contains(self, key: str) -> bool:

Tests if the configuration contains a value for a given key.

Arguments:
  • key (str): The key to test for.
Returns:

True if a value exists for the given key; otherwise, false.

def Clear(self) -> None:

Removes all key/value pairs of the configuration.

def LoadFromFile(self, fileName: str) -> None:

Loads the configuration from a file.

Arguments:
  • fileName (str): The name of the file to load the configuration from.
Raises:
  • IOException: An I/O error occurred while trying to load the configuration or if the specified file does not exist.
  • SIArgumentNullException: The fileName argument is null.

This method loads key/value pairs separated with a '=' character from a file. Empty, unrecognized lines or lines beginning with a ';' character are ignored.

def Parse(self, pair: str) -> None:

Parses a line read from a configuration file, adding the found key and value to the configuration variables table.

Arguments:
  • pair (str): String that contains a KEY=VALUE pair.
def ReadBoolean(self, key: str, defaultValue: bool) -> bool:

Returns a boolean value of an element for a given key.

Arguments:
  • key (str): The key whose value to return.
  • defaultValue (bool): The value to return if the given key is unknown.
Returns:

Either the value converted to a bool for the given key if an element with the given key exists or defaultValue otherwise.

Raises:
  • SIArgumentNullException: The key argument is null.

This method returns a bool value of true if the found value of the given key matches either "true", "1" or "yes" and false otherwise. If the supplied key is unknown, the defaultValue argument is returned.

def ReadColor( self, key: str, defaultValue: smartinspectpython.sicolor.SIColor) -> smartinspectpython.sicolor.SIColor:

Returns a color value of an element for a given key.

Arguments:
  • key (str): The key whose value to return.
  • defaultValue (SIColor): The value to return if the given key is unknown or if the found value has an invalid format.
Returns:

Either the value converted to a SIColor value for the given key if an element with the given key exists and the found value has a valid format or defaultValue otherwise.

Raises:
  • SIArgumentNullException: The key argument is null.

The element value must be specified as hexadecimal string. To indicate that the element value represents a hexadecimal string, the element value must begin with "0x", "&H" or "$". A '0' nibble is appended if the hexadecimal string has an odd length.

The hexadecimal value must represent a three or four byte integer value. The hexadecimal value is handled as follows.

Bytes Format
3 RRGGBB
4 AARRGGBB
Other Ignored

A stands for the alpha channel and R, G and B represent the red, green and blue channels, respectively. If the value is not given as hexadecimal value with a length of 6 or 8 characters excluding the hexadecimal prefix identifier or if the value does not have a valid hexadecimal format, this method returns defaultValue.

def ReadInteger(self, key: str, defaultValue: bool) -> bool:

Returns a integer value of an element for a given key.

Arguments:
  • key (str): The key whose value to return.
  • defaultValue (bool): The value to return if the given key is unknown.
Returns:

Either the value converted to an int for the given key if an element with the given key exists and the found value is a valid int or defaultValue otherwise.

Raises:
  • SIArgumentNullException: The key argument is null.

This method returns the defaultValue argument if either the supplied key is unknown or the found value is not a valid int. Only non-negative int values are recognized as valid.

def ReadKey(self, index: int) -> str:

Returns a key of this SmartInspect configuration for a given index.

Arguments:
  • index (int): The index in this SmartInspect configuration.
Returns:

A key of this SmartInspect configuration for the given index.

Raises:
  • SIArgumentOutOfRangeException: The index argument is not a valid index of this SmartInspect configuration.

To find out the total number of key/value pairs in this SmartInspect configuration, use Count. To get the value for a given key, use ReadString.

def ReadLevel( self, key: str, defaultValue: smartinspectpython.silevel.SILevel) -> smartinspectpython.silevel.SILevel:

Returns a SILevel value of an element for a given key.

Arguments:
  • key (str): The key whose value to return.
  • defaultValue (SILevel): The value to return if the given key is unknown.
Returns:

Either the value converted to the corresponding SILevel value for the given key if an element with the given key exists and the found value is a valid SILevel value or defaultValue otherwise.

Raises:
  • SIArgumentNullException: The key argument is null.

This method returns the defaultValue argument if either the supplied key is unknown or the found value is not a valid SILevel value. Please see the SILevel enum for more information on the available values.

def ReadString(self, key: str, defaultValue: str) -> str:

Returns a string value of an element for a given key.

Arguments:
  • key (str): The key whose value to return.
  • defaultValue (str): The value to return if the given key is unknown.
Returns:

Either the value for a given key if an element with the given key exists or defaultValue otherwise.

Raises:
  • SIArgumentNullException: The key argument is null.