visiannot.configuration.Configuration¶
Summary¶
Module defining class Configuration and function
check_configuration()
Classes¶
Class defining a configuration and its widget |
Functions¶
|
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:
objectClass defining a configuration and its widget
The widget is contained in
Configuration.layandgroup_box. The group box is added to the input window stored in the attributelay_parent.The configuration dictionary is stored in the attribute
dict.There are 3 callback methods for user interaction:
add_config_callback()=> adding a (sub-)configurationdelete_configuration()=> deleting a (sub-)configurationset_directory()=> setting the directory where to find data (if necessary)
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 toConfiguration.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 listconfig_grid_listand the configuration group boxes are stored in the listconfig_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_levelis 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_levelis 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_listnb_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_evalis applied on the value, so thatNoneor 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_levelequals 2help_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 toconfig_base_namepos_dir (int) – index of the widget element in
elt_listwhich is a directory, it is then linked to a push button that opens a dialog window for selecting a directoryflag_dir_identical (bool) – in case
pos_diris notNone, 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 ofdictare forced to be the same as in the configuration parent dictionarychildren_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_listadd_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_parentcreate_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
Deletes the configuration grids in
config_grid_list) and replaces them withConfigurationWindow.dictSets the attribute
dictwith the current values filled in the configuration grids (config_grid_list)set_directory(button_id)Callback method for directory selection
Attributes:
(QtWidgets.QGridLayout) See first positional argument of
Configurationconstructor(str) See third positional argument of
Configurationconstructor(int) Nesting level of configuration list, either
1or2(list) See fifth positional argument of
Configurationconstructor(int) See sixth positional argument of
Configurationconstructor(int) See keyword argument
flag_dir_identicalofConfigurationconstructor(int) See keyword argument
flag_keyofConfigurationconstructor(int) See keyword argument
pos_dirofConfigurationconstructor(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
(int) See keyword argument
config_base_nameofConfigurationconstructor(
Configuration) See keyword argumentparent_configofConfiguration(list) Instances of
Configurationcontaining the children configurations(dict) Configuration dictionary, each item corresponds to one configuration grid of
config_grid_list, key is the configuration identifier (generated withconfig_base_name), value is the configuration list (nested list in case ofnb_levelequal to2)(list) Instances of QtWidgets.QGridLayout containing the configuration grids (same order as
config_group_box_list), each grid corresponds to one key ofdict(list) Instances of QtWidgets.QGroupBox containing the configuration grids (same order as
config_grid_list), each group box corresponds to one key ofdict(list) Integers with the number of sub-configurations for each configuration grid (same order as
config_grid_list)(list) Each element is a list with the configuration grid index and the sub-configuration index corresponding to the push buttons “Change directory”/”Delete”
(int) Number of rows in the group box header
(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(QtWidgets.QGridLayout) Layout filling the group box
group_box(QtWidgets.QGroupBox) Group box where configuration grids are created
(QtWidgets.QCheckBox) Check box to specify if all directories are identical (when using the push button for changing directory), may be
None(QtWidgets.QButtonGroup) Group of buttons for displaying children configuration windows
(QtWidgets.QButtonGroup) Group of buttons for changing directory
(QtWidgets.QButtonGroup) Group of buttons for adding (sub-)configurations
(QtWidgets.QButtonGroup) Group of buttons for deleting (sub-)configurations
(QtWidgets.QPushButton) Push button for displaying help window
(QtWidgets.QWidget) Container of help window
(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 configurationbutton_id >= 1: add a sub-configuration (in case ofnb_levelequal 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:
button_group_dirwith the created push buttons for directory selection (if any)button_group_delwith the created push button for deleting
- Parameters
config_dict (dict) – dictionary of the configurations to add, see
dict
Each item of
config_dictcorresponds to one configuration, implying one created configuration grid. Value is a configuration list, which is nested ifnb_levelis equal to2, seedict.
-
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:
button_group_dirwith the created push buttons for directory selection (if any)button_group_delwith the created push button for deleting
- 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_listis 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
textChangedof the instances of QtWidgets.QLineEdit created inadd_configuration().It sets the attribute
dictand 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_parentAt this point, the group box contains only the header and one or several push buttons to add configurations.
NB: make sure that
typeis inConfigurationWindow.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_levelequal to2, it does nor return a nested configuration list, but the sub-configuration list at indexrow_ind.In case of
nb_levelequal to2, setrow_indto0.- 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 withConfigurationWindow.dictThis method updates the following attributes:
-
set_dictionary()[source]¶ Sets the attribute
dictwith the current values filled in the configuration grids (config_grid_list)NB: make sure that
typeis inConfigurationWindow.config_type_list.
-
set_directory(button_id)[source]¶ Callback method for directory selection
Connected to the signal
buttonClicked[int]ofbutton_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_levelequal 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 groupsbutton_group_delandbutton_group_dircontain 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()andset_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 listbtn_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]].
(QtWidgets.QButtonGroup) Group of buttons for adding (sub-)configurations
(QtWidgets.QButtonGroup) Group of buttons for displaying children configuration windows
(QtWidgets.QButtonGroup) Group of buttons for deleting (sub-)configurations
(QtWidgets.QButtonGroup) Group of buttons for changing directory
(QtWidgets.QPushButton) Push button for hding help window
(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
Configurationcontaining the children configurationsWhen a configuration is deleted, the children configuration with the same key are deleted as well.
-
config_base_name¶ (int) See keyword argument
config_base_nameofConfigurationconstructor
-
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 ofdict
-
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 1Computed 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 ofdict
-
default_config_list¶ (int) See sixth positional argument of
Configurationconstructor
-
dict¶ (dict) Configuration dictionary, each item corresponds to one configuration grid of
config_grid_list, key is the configuration identifier (generated withconfig_base_name), value is the configuration list (nested list in case ofnb_levelequal to2)The content of a configuration list depends on
elt_list, which specifies the type of its elements.Currently, 7 instances of
Configurationare created inConfigurationWindow(seeconfig_type_listfor the corresponding configuration types). Here is the content of the configuration list according to the conifguration type:"Video"(nb_levelis1)(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_levelis2=> configuration list is nested, configuration key is the name of the signal widget inViSiAnnoT)(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,
0if 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_levelis1, configuration key is the label)(tuple) RGB color
"AnnotImage"(nb_levelis1)(str) Label
"Interval"(nb_levelis2=> configuration list is nested, child ofSignal)(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,
0if 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_levelis1, child ofSignal)(str) Threshold value
(tuple) RGB color
"YRange"(nb_levelis1, child ofSignal)(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
Configurationconstructor
-
flag_dir_identical¶ (int) See keyword argument
flag_dir_identicalofConfigurationconstructor
-
flag_key¶ (int) See keyword argument
flag_keyofConfigurationconstructor
-
group_box¶ (QtWidgets.QGroupBox) Group box where configuration grids are created
-
lay_parent¶ (QtWidgets.QGridLayout) See first positional argument of
Configurationconstructor
-
nb_level¶ (int) Nesting level of configuration list, either
1or21: 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_levelis 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 argumentparent_configofConfiguration
-
pos_dir¶ (int) See keyword argument
pos_dirofConfigurationconstructor
-
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, unlessflag_keyis set toTrue, 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
Configurationconstructor
-
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, otherwiseViSiAnnoT(it has an impact on “video”, “signal” and “interval”)