DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
cider
widgets
popups
edit_cell_screen.py
Go to the documentation of this file.
1
from
os
import
environ
2
3
from
textual.screen
import
ModalScreen
4
from
textual.app
import
ComposeResult
5
from
textual.widgets
import
Input, Label
6
from
textual.containers
import
Container
7
8
from
typing
import
Protocol
9
10
from
daqconf.cider.widgets.configuration_controller
import
ConfigurationController
11
12
class
TableCellEvent
(Protocol):
13
row_key: object
14
15
16
class
EditCellScreen
(ModalScreen):
17
css_file_path = f
"{environ.get('DAQCONF_SHARE')}/config/textual_dbe/textual_css"
18
19
CSS_PATH = f
"{css_file_path}/edit_cell_layout.tcss"
20
21
def
__init__
(
22
self, event: TableCellEvent, name: str |
None
=
None
, id: str |
None
=
None
, classes: str |
None
=
None
) ->
None
:
23
super().
__init__
(name=name, id=id, classes=classes)
24
"""Screen which pops up when a cell is clicked in the ConfigTable
25
"""
26
27
# Need to get the main screen configuration
28
main_screen = self.app.get_screen(
"main"
)
29
self.
_data_table
= main_screen.query_one(
"DataTable"
)
30
self.
_config_table
= main_screen.query_one(
"ConfigTable"
)
31
# self._config_table = main_screen.query_one("ConfigTable")
32
33
# Get necessary info from table
34
self.
_row_key
= event.row_key
35
self.
_current_row
= self.
_data_table
.get_row(event.row_key)
36
self.
_controller
= main_screen.query_one(ConfigurationController)
37
38
def
compose
(self) -> ComposeResult:
39
with
Container(id=
"edit_cell"
):
40
yield
Label(f
"Enter new value for {self._current_row[0]}"
)
41
yield
Input()
42
43
def
on_mount
(self) -> None:
44
"""Finds the cell that was clicked and populates the input field
45
"""
46
cell_input = self.query_one(Input)
47
# Harcoded...
48
cell_input.value = str(self.
_current_row
[1])
49
cell_input.focus()
50
51
def
on_input_submitted
(self, event: Input.Submitted) ->
None
:
52
"""Applies update to the configuration object
53
54
Arguments:
55
event -- Information from table row
56
"""
57
attr_name = self.
_current_row
[0]
58
update_value = event.value
59
attr_type = self.
_current_row
[2]
60
is_multivalue = self.
_current_row
[3]
61
62
# Need to properly cast to list
63
if
is_multivalue:
64
update_value=self.
process_multivalue_input
(update_value, attr_type)
65
else
:
66
update_value = self.
cast_to_type_by_str
(update_value, attr_type)
67
68
self.
_controller
.update_configuration(attr_name, update_value)
69
self.
_config_table
.update_table(self.
_controller
.current_dal)
70
71
self.app.pop_screen()
72
73
74
@classmethod
75
def
cast_to_type_by_str
(cls, input_variable: str, data_type: str):
76
"""Attempt to enforce type-checking/convertion on input variable based on type-name in table. Will not work for non-built-in types
77
"""
78
try
:
79
return
getattr(__builtins__, data_type)(input_variable)
80
except
:
81
return
input_variable
82
83
@classmethod
84
def
process_multivalue_input
(cls, input_value: str, data_type: str):
85
"""Processing required to ensure multi-variate objects are correctly placed in the table
86
87
"""
88
# Strip brackets
89
input_value = input_value.replace(
"["
,
""
)
90
input_value = input_value.replace(
"]"
,
""
)
91
# Strip space
92
input_value = input_value.replace(
" "
,
""
)
93
input_value = [cls.
cast_to_type_by_str
(i, data_type)
for
i
in
input_value.split(
","
)]
94
95
return
input_value
edit_cell_screen.EditCellScreen
Definition
edit_cell_screen.py:16
edit_cell_screen.EditCellScreen.on_input_submitted
None on_input_submitted(self, Input.Submitted event)
Definition
edit_cell_screen.py:51
edit_cell_screen.EditCellScreen.process_multivalue_input
process_multivalue_input(cls, str input_value, str data_type)
Definition
edit_cell_screen.py:84
edit_cell_screen.EditCellScreen._row_key
_row_key
Definition
edit_cell_screen.py:34
edit_cell_screen.EditCellScreen._controller
_controller
Definition
edit_cell_screen.py:36
edit_cell_screen.EditCellScreen._current_row
_current_row
Definition
edit_cell_screen.py:35
edit_cell_screen.EditCellScreen.cast_to_type_by_str
cast_to_type_by_str(cls, str input_variable, str data_type)
Definition
edit_cell_screen.py:75
edit_cell_screen.EditCellScreen._config_table
_config_table
Definition
edit_cell_screen.py:30
edit_cell_screen.EditCellScreen.on_mount
None on_mount(self)
Definition
edit_cell_screen.py:43
edit_cell_screen.EditCellScreen.compose
ComposeResult compose(self)
Definition
edit_cell_screen.py:38
edit_cell_screen.EditCellScreen._data_table
_data_table
Definition
edit_cell_screen.py:29
edit_cell_screen.EditCellScreen.__init__
None __init__(self, TableCellEvent event, str|None name=None, str|None id=None, str|None classes=None)
Definition
edit_cell_screen.py:22
edit_cell_screen.TableCellEvent
Definition
edit_cell_screen.py:12
Generated on
for DUNE-DAQ by
1.17.0