visiannot.configuration.Configuration

Summary

Module defining class Configuration and function check_configuration()

Classes

visiannot.configuration.Configuration.Configuration(…)

Class defining a configuration and its widget

Functions

visiannot.configuration.Configuration.check_configuration(…)

Checks if a configuration list has the right number of elements

API

Class Configuration

class visiannot.configuration.Configuration.Configuration(lay_parent, position, config_type, nb_level, elt_list, default_config_list, help_text='', config_base_name='config_', pos_dir=None, flag_dir_identical=False, flag_key=False, parent_config=None, children_config_name_list=[])[source]

Bases: object

Class defining a configuration and its widget

The widget is contained in Configuration.lay and group_box. The group box is added to the input window stored in the attribute lay_parent.

The configuration dictionary is stored in the attribute dict.

There are 3 callback methods for user interaction:

We can add a new configuration to the widget thanks to the push button “Add” (contained in button_group_add). This will add an instance of QtWidgets.QGridLayout to Configuration.lay, that we call a configuration grid. This configuration grid is contained in an instance of QtWidgets.QGroupBox. The configuration grids are stored in the list config_grid_list and the configuration group boxes are stored in the list config_group_box_list.

On the one hand, for a given configuration grid, we can have a single configuration list to set, in this case nb_level is set to 1. For example, this is the case for video configuration: for a given camera ID, there is only 1 video file to display.

On the other hand, for a given configuration grid, we can have a list of configuration lists to set, in this case nb_level is set to 2. For example, this the case for signal configuration: for a given signal type, there can be several data to plot on the same widget.

The number of sub-configurations in each configuration grid is stored in the list nb_sub_list.

Parameters
  • lay_parent (QtWidgets.QGridLayout) – parent layout where the configuration group box is added

  • position (tuple of integers) – position of the configuration widget in the layout of the input window, length 2 (row, col) or 4 (row, col, rowspan, colspan)

  • config_type (str) – configuration type, see ConfigurationWindow.config_type_list

  • nb_level (int) – number of nesting levels for a configuration list, typically 1 (video) or 2 (signal)

  • elt_list (list) –

    list of the elements defining a configuration list in the group box, the length is equal to the length of a configuration list, each element is a tuple of length 3:

    • (str) Type of widget for the element, might be one of the following:

      • "edit" (QLineEdit, the value is a string),

      • "edit_freq" (QLineEdit, the value is converted to a float if necessary, otherwise stick to a string), "edit_float" (QLineEdit, the value is converted to a float or an exception is raised if conversion failed),

      • "edit_literal" (QLineEdit, ast.literal_eval is applied on the value, so that None or dictionary are retrieved),

      • "spin" (QSpinBox, the value is an integer),

    • (int) Number of widgets for the element (for example, RGB color might be defined as 3 spin boxes, then the value is a tuple of 3 elements),

    • (dict) Keyword parameters to pass to the element widget constructor (for example, for "spin", {"minimum": 0, "maximum": 255})

  • default_config_list (list) – default configuration list to display when adding a (sub-)configuration, make sure to give a nested list if nb_level equals 2

  • help_text (str) – text to display in the help window, describing the different elements of a configuration list

  • config_base_name (str) – base name of the configuration keys in dict, the index of the configuration (in order of creation) is appended to config_base_name

  • pos_dir (int) – index of the widget element in elt_list which is a directory, it is then linked to a push button that opens a dialog window for selecting a directory

  • flag_dir_identical (bool) – in case pos_dir is not None, specify if the directories of the different configurations must be the same, implying that when the directory of one configuration is modified, the directory of the other configurations is also modifed (currently only working when modifying directory with push button)

  • flag_key (bool) – specify if the configuration key can be modified thanks to a line edit (puts a QLineEdit widget element on the left side of each configuration)

  • parent_config (Configuration) – parent configuration, if a parent configuration is specified, then the configuration keys of dict are forced to be the same as in the configuration parent dictionary

  • children_config_name_list (list) – list of strings with the name of children configurations

Methods:

add_child_configuration(config_child)

Adds a child configuration to children_configuration_list

add_config_callback(button_id)

Callback method for adding a (sub-)configuration

add_configuration(config_dict)

Adds one or several configurations

add_configuration_simple(config_list[, …])

Adds a single (sub-)configuration list to a configuration grid

config_key_changed(text)

Callback method for updating configuration key, as well as those of the children configurations, when it is edited in the QLineEdit

create_configuration_group_box(position, …)

Creates group box and adds it to lay_parent

create_help_window(help_text)

Creates help window without showing it

create_widgets_in_config_grid(config_grid, …)

Creates widgets elements for a new configuration list in a configuration grid

delete_configuration(button_id)

Callback method for deleting a (sub-)configuration

get_configuration_simple(config_grid, row_ind)

Reads the values filled in a single row of a configuration grid in order to get the corresponding configuration list

reset_display()

Deletes the configuration grids in config_grid_list) and replaces them with ConfigurationWindow.dict

set_dictionary()

Sets the attribute dict with the current values filled in the configuration grids (config_grid_list)

set_directory(button_id)

Callback method for directory selection

Attributes:

lay_parent

(QtWidgets.QGridLayout) See first positional argument of Configuration constructor

type

(str) See third positional argument of Configuration constructor

nb_level

(int) Nesting level of configuration list, either 1 or 2

elt_list

(list) See fifth positional argument of Configuration constructor

default_config_list

(int) See sixth positional argument of Configuration constructor

flag_dir_identical

(int) See keyword argument flag_dir_identical of Configuration constructor

flag_key

(int) See keyword argument flag_key of Configuration constructor

pos_dir

(int) See keyword argument pos_dir of Configuration constructor

pos_dir_grid

(int) Index of the widget element in the configuration grid which is a directory, it is then linked to a push button that opens a dialog window for selecting a directory

config_base_name

(int) See keyword argument config_base_name of Configuration constructor

parent_config

(Configuration) See keyword argument parent_config of Configuration

children_configuration_list

(list) Instances of Configuration containing the children configurations

dict

(dict) Configuration dictionary, each item corresponds to one configuration grid of config_grid_list, key is the configuration identifier (generated with config_base_name), value is the configuration list (nested list in case of nb_level equal to 2)

config_grid_list

(list) Instances of QtWidgets.QGridLayout containing the configuration grids (same order as config_group_box_list), each grid corresponds to one key of dict

config_group_box_list

(list) Instances of QtWidgets.QGroupBox containing the configuration grids (same order as config_grid_list), each group box corresponds to one key of dict

nb_sub_list

(list) Integers with the number of sub-configurations for each configuration grid (same order as config_grid_list)

btn_id_to_config_id

(list) Each element is a list with the configuration grid index and the sub-configuration index corresponding to the push buttons “Change directory”/”Delete”

nb_rows_header

(int) Number of rows in the group box header

config_grid_span

(int) Number of columns spanned by the configuration grids in the layout of group_box, equivalent to the number of widgets in the group box header minus 1

lay

(QtWidgets.QGridLayout) Layout filling the group box group_box

group_box

(QtWidgets.QGroupBox) Group box where configuration grids are created

check_box

(QtWidgets.QCheckBox) Check box to specify if all directories are identical (when using the push button for changing directory), may be None

button_group_children

(QtWidgets.QButtonGroup) Group of buttons for displaying children configuration windows

button_group_dir

(QtWidgets.QButtonGroup) Group of buttons for changing directory

button_group_add

(QtWidgets.QButtonGroup) Group of buttons for adding (sub-)configurations

button_group_del

(QtWidgets.QButtonGroup) Group of buttons for deleting (sub-)configurations

button_help_show

(QtWidgets.QPushButton) Push button for displaying help window

win_help

(QtWidgets.QWidget) Container of help window

button_help_hide

(QtWidgets.QPushButton) Push button for hding help window

add_child_configuration(config_child)[source]

Adds a child configuration to children_configuration_list

Parameters

config_child (Configuration) – child configuration

add_config_callback(button_id)[source]

Callback method for adding a (sub-)configuration

Connected to the signal buttonClicked[int] of button_group_add.

There are two kinds of buttons:

  • button_id == 0: add a configuration

  • button_id >= 1: add a sub-configuration (in case of nb_level equal to 2)

Parameters

button_id (int) – index of the button that has been pushed

add_configuration(config_dict)[source]

Adds one or several configurations

This method updates the following attributes:

Parameters

config_dict (dict) – dictionary of the configurations to add, see dict

Each item of config_dict corresponds to one configuration, implying one created configuration grid. Value is a configuration list, which is nested if nb_level is equal to 2, see dict.

add_configuration_simple(config_list, config_id=None)[source]

Adds a single (sub-)configuration list to a configuration grid

This method updates the following attributes:

Parameters
  • config_list (list) – configuration list with the values to fill in

  • config_id (int) – index of the configuration grid where to add the (sub-)configuration, by default the last configuration grid of config_grid_list is chosen

config_key_changed(text)[source]

Callback method for updating configuration key, as well as those of the children configurations, when it is edited in the QLineEdit

Connected to the signal textChanged of the instances of QtWidgets.QLineEdit created in add_configuration().

It sets the attribute dict and the configuration dictionary of the children configurations.

Parameters

text (str) – updated configuration key

create_configuration_group_box(position, children_config_name_list)[source]

Creates group box and adds it to lay_parent

At this point, the group box contains only the header and one or several push buttons to add configurations.

NB: make sure that type is in ConfigurationWindow.config_type_list.

It sets the following attributes:

Parameters
  • position (tuple) – position of the configuration group box in lay_parent, length 2 (row, col) or 4 (row, col, rowspan, colspan)

  • children_config_name_list (list) – names of the children configurations

create_help_window(help_text)[source]

Creates help window without showing it

It has two widgets: a QLabel with the text and a push button for closing the window.

Parameters

help_text (str) – text to be displayed

create_widgets_in_config_grid(config_grid, config_list, row_ind, start_col_ind)[source]

Creates widgets elements for a new configuration list in a configuration grid

Parameters
  • config_grid (QtWidgets.QGridLayout) – configuration grid where to add a configuration list

  • config_list (list) – configuration list with the values to fill in

  • row_ind (int) – index of the row in the configuration grid where to add the widgets elementst of the configuration list

  • start_col_ind (int) – index of the column in the configuration grid where to start to add widgets elements of the configuration list

delete_configuration(button_id)[source]

Callback method for deleting a (sub-)configuration

Connected to the signal buttonClicked[int] of button_group_del.

This method updates the following attributes:

Parameters

button_id (int) – index of the button that has been pushed

get_configuration_simple(config_grid, row_ind)[source]

Reads the values filled in a single row of a configuration grid in order to get the corresponding configuration list

In case of nb_level equal to 2, it does nor return a nested configuration list, but the sub-configuration list at index row_ind.

In case of nb_level equal to 2, set row_ind to 0.

Parameters
  • config_grid (QtWidgets.QGridLayout) – configuration grid

  • row_ind (int) – index of the row in the configuration grid from which to retrieve the (sub-)configuration list

reset_display()[source]

Deletes the configuration grids in config_grid_list) and replaces them with ConfigurationWindow.dict

This method updates the following attributes:

set_dictionary()[source]

Sets the attribute dict with the current values filled in the configuration grids (config_grid_list)

NB: make sure that type is in ConfigurationWindow.config_type_list.

set_directory(button_id)[source]

Callback method for directory selection

Connected to the signal buttonClicked[int] of button_group_dir.

Parameters

button_id (int) – index of the button that has been pushed

btn_id_to_config_id

(list) Each element is a list with the configuration grid index and the sub-configuration index corresponding to the push buttons “Change directory”/”Delete”

In case of nb_level equal to 2, the sub-configurations are not necessarily added in the order of display, so the push buttons “Change directory” / “Delete” are not necessarily added in the order of display. As a consequence, the button groups button_group_del and button_group_dir contain the push buttons in the order of addition, which is decorrelated to the the order of display.

When listening to the callbacks methods delete_configuration() and set_directory(), the input argument is the push button index in the button group. We cannot link it explicitely to the configuration grid position. So, when a push button is added to the button group, the new sub-configuration grid position is appended to the list btn_id_to_config_id.

The position is expressed as a list with 2 integers:

  • index of the configuration grid (index in the list config_grid_list)

  • index of the sub-configuration grid inside the configuration grid

An example of configuration with the zero-indexed order of addition (which gives the button index in the button group):

  • config_key_1

    • sub_config_11 => 0

    • sub_config_12 => 5

  • config_key_2

    • sub_config_21 => 1

  • config_key_3

    • sub_config_31 => 2

    • sub_config_32 => 3

    • sub_config_33 => 4

It will give btn_id_to_config_id == [[0, 0], [1, 0], [2, 0], [2, 1], [2, 2], [0, 1]].

button_group_add

(QtWidgets.QButtonGroup) Group of buttons for adding (sub-)configurations

button_group_children

(QtWidgets.QButtonGroup) Group of buttons for displaying children configuration windows

button_group_del

(QtWidgets.QButtonGroup) Group of buttons for deleting (sub-)configurations

button_group_dir

(QtWidgets.QButtonGroup) Group of buttons for changing directory

button_help_hide

(QtWidgets.QPushButton) Push button for hding help window

button_help_show

(QtWidgets.QPushButton) Push button for displaying help window

check_box

(QtWidgets.QCheckBox) Check box to specify if all directories are identical (when using the push button for changing directory), may be None

children_configuration_list

(list) Instances of Configuration containing the children configurations

When a configuration is deleted, the children configuration with the same key are deleted as well.

config_base_name

(int) See keyword argument config_base_name of Configuration constructor

config_grid_list

(list) Instances of QtWidgets.QGridLayout containing the configuration grids (same order as config_group_box_list), each grid corresponds to one key of dict

config_grid_span

(int) Number of columns spanned by the configuration grids in the layout of group_box, equivalent to the number of widgets in the group box header minus 1

Computed as 2 + len(children_config_name_list): in the group box header, there are two widgets (“Help” push button / check box for identical directories or empty QLabel) and as many push buttons as children configurations. The configuration grids must span all those widgets.

config_group_box_list

(list) Instances of QtWidgets.QGroupBox containing the configuration grids (same order as config_grid_list), each group box corresponds to one key of dict

default_config_list

(int) See sixth positional argument of Configuration constructor

dict

(dict) Configuration dictionary, each item corresponds to one configuration grid of config_grid_list, key is the configuration identifier (generated with config_base_name), value is the configuration list (nested list in case of nb_level equal to 2)

The content of a configuration list depends on elt_list, which specifies the type of its elements.

Currently, 7 instances of Configuration are created in ConfigurationWindow (see config_type_list for the corresponding configuration types). Here is the content of the configuration list according to the conifguration type:

  • "Video" (nb_level is 1)

    • (str) Directory where to find video files

    • (str) File pattern

    • (str) Delimiter for finding timestamp in file name

    • (str) Position of the timestamp in file name after splitting with delimiter

    • (str) Format of timestamp string in file name

  • "Signal" (nb_level is 2 => configuration list is nested, configuration key is the name of the signal widget in ViSiAnnoT)

    • (str) Directory where to find data files

    • (str) Key to access the data (in case of .h5 or .mat data files)

    • (int or str) Signal frequency, 0 if 2D data with timestamps, it might be a string with the path to the key containing the frequency in a .h5 or .mat file

    • (str) File pattern

    • (str) Delimiter for finding timestamp in file name

    • (str) Position of the timestamp in file name after splitting with delimiter

    • (str) Format of timestamp string in file name

    • (dict) Plot style (default is None)

  • "AnnotEvent" (nb_level is 1, configuration key is the label)

    • (tuple) RGB color

  • "AnnotImage" (nb_level is 1)

    • (str) Label

  • "Interval" (nb_level is 2 => configuration list is nested, child of Signal)

    • (str) Directory where to find data files

    • (str) Key to access the data (in case of .h5 or .mat data files)

    • (int or str) Signal frequency, 0 if 2D data with timestamps, it might be a string with the path to the key containing the frequency in a .h5 or .mat file

    • (str) File pattern

    • (str) Delimiter for finding timestamp in file name

    • (str) Position of the timestamp in file name after splitting with delimiter

    • (str) Format of timestamp string in file name

    • (tuple) RGB color

  • "Threshold" (nb_level is 1, child of Signal)

    • (str) Threshold value

    • (tuple) RGB color

  • "YRange" (nb_level is 1, child of Signal)

    • (float) Minimum value to display on Y axis in the corresponding signal widget

    • (float) Maximum value to display on Y axis in the corresponding signal widget

elt_list

(list) See fifth positional argument of Configuration constructor

flag_dir_identical

(int) See keyword argument flag_dir_identical of Configuration constructor

flag_key

(int) See keyword argument flag_key of Configuration constructor

group_box

(QtWidgets.QGroupBox) Group box where configuration grids are created

lay

(QtWidgets.QGridLayout) Layout filling the group box group_box

lay_parent

(QtWidgets.QGridLayout) See first positional argument of Configuration constructor

nb_level

(int) Nesting level of configuration list, either 1 or 2

  • 1: single list (single line in configuration grid)

  • 2: list of lists (ability to add sub-configuration in a configuration grid)

The value of this attribute depends on the value of type, as follows:

  • "Video": 1

  • "Signal": 2

  • "Interval": 2

  • "Threshold": 2

  • "YRange": 1

  • "AnnotEvent": 1

  • "AnnotImage": 1

nb_rows_header

(int) Number of rows in the group box header

In all cases it equals 1.

nb_sub_list

(list) Integers with the number of sub-configurations for each configuration grid (same order as config_grid_list)

If nb_level is equal to 1, then each element equals 1.

An example of configuration:

  • config_key_1

    • sub_config_11

    • sub_config_12

  • config_key_2

    • sub_config_21

  • config_key_3

    • sub_config_31

    • sub_config_32

    • sub_config_33

It will give self.nb_sub_list == [2, 1, 3].

parent_config

(Configuration) See keyword argument parent_config of Configuration

pos_dir

(int) See keyword argument pos_dir of Configuration constructor

pos_dir_grid

(int) Index of the widget element in the configuration grid which is a directory, it is then linked to a push button that opens a dialog window for selecting a directory

It is equal to pos_dir, unless flag_key is set to True, which implies that a QLineEdit is added at the beginning of the configuration grid, so the index is incremented by 1.

type

(str) See third positional argument of Configuration constructor

win_help

(QtWidgets.QWidget) Container of help window

Functions

visiannot.configuration.Configuration.check_configuration(config_id, config, config_type, flag_long_rec=True)[source]

Checks if a configuration list has the right number of elements

It raises an exception if it is not the case.

Parameters
  • config_id (str) – configuration key in the configuration dictionary

  • config (list) – configuration list

  • config_type (str) – used to set the right number of elements, one of the following: “Video”, “Signal”, “Interval”, “Threshold” or “YRange” (otherwise nothing happens)

  • flag_long_rec (bool) – specify if configuration in the context of ViSiAnnoTLongRec, otherwise ViSiAnnoT (it has an impact on “video”, “signal” and “interval”)