DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
cider
widgets
selection_menu.py
Go to the documentation of this file.
1
from
typing
import
Any
2
import
numpy
as
np
3
4
from
textual.widgets
import
Static, Tree
5
from
textual.widgets.tree
import
TreeNode
6
from
daqconf.cider.widgets.configuration_controller
import
ConfigurationController
7
8
class
SelectionMenu
(Static):
9
'''
10
Basic selection menu, builds tree from selection objects
11
'''
12
_tree =
None
13
__node_states = {}
14
15
def
compose
(self):
16
self.
_build_tree
()
17
yield
self.
_tree
18
19
def
_build_tree
(self):
20
"""Iteratively builds tree via dictionary. This should be generated in SelectionInterface"""
21
22
# Grab current tree + config controller
23
if
self.
_tree
is
not
None
:
24
self.
_tree
.clear()
25
26
self.
_tree
= Tree(
"Configuration:"
)
27
main_screen = self.app.get_screen(
"main"
)
28
self.
_controller
= main_screen.query_one(
"ConfigurationController"
)
29
30
# Loop over interfaces + make sure they're up to date with config
31
for
key, interface
in
self.
_controller
.get_interface().items():
32
interface.recompose()
33
34
# Check if the current interface is in the controller
35
if
self.id
not
in
self.
_controller
.get_interface().keys():
36
raise
ValueError(f
"Cannot find {self._interface_label} in controller. \n \
37
available interfaces are {self._controller.get_interface()}"
)
38
39
# Grab root of tree
40
tree_root = self.
_tree
.root
41
tree_root.expand()
42
43
# Sort out the tree nodes to be alphabetical + loop overtop level noes
44
for
key, branch
in
sorted(self.
_controller
.get_interface()[self.id].relationships.items()):
45
tree_node = tree_root.add(f
"[green]{key}[/green]"
, expand=
False
)
46
if
self.
__node_states
.get(tree_node.id):
47
tree_node.expand()
48
49
self.
__build_tree_node
(tree_node, branch, is_disabled=
False
, disabled_elements=[])
50
51
52
def
__build_tree_node
(self, input_node: TreeNode, input_list: list, is_disabled: bool=
False
, disabled_elements: list=[]):
53
"""Recursively build tree nodes from a list of dictionaries"""
54
55
# Check if we need to remove the node since it's empty
56
if
len(input_list)==0:
57
input_node.remove()
58
59
# Loop over the input list
60
for
config_item
in
input_list:
61
# Check if it has sub-levels
62
if
isinstance(config_item, dict):
63
# Print the DAL name
64
config_key = list(config_item.keys())[0]
65
config_objects = list(config_item.values())[0]
66
67
# Need to be able to add categories so check if it's just a string
68
if
isinstance(config_key, str):
69
item_disabled = is_disabled
70
dal_str = config_key
71
stored_data=
None
#
72
73
else
:
74
if
config_key.className() ==
"Session"
:
75
disabled_elements = config_key.disabled
76
# Remove the Resource object since it just doubly defines disabled items
77
78
# Check if the item is disabled
79
item_disabled = self.
__check_item_disabled
(config_key, disabled_elements)
or
is_disabled
80
81
dal_str = self.
_controller
.generate_rich_string(config_key, item_disabled)
82
stored_data = config_key
83
84
# Bit confusing, set ensure we're not multiply defining things in the tree,
85
# for example disabled items in a session may also be defined elsewhere
86
tree_node = input_node.add(dal_str, data=stored_data)
87
if
self.
__node_states
.get(tree_node.id):
88
tree_node.expand()
89
90
self.
__build_tree_node
(tree_node, config_objects, item_disabled, disabled_elements)
91
92
else
:
93
# No sub-levels, just add the leaf
94
item_disabled = self.
__check_item_disabled
(config_item, disabled_elements)
or
is_disabled
95
input_node.add_leaf(self.
_controller
.generate_rich_string(config_item, item_disabled), data=config_item)
96
97
def
on_tree_node_selected
(self, event):
98
# Selector
99
controller:ConfigurationController = self.app.query_one(
"ConfigurationController"
)
100
101
if
event.node.data
is
not
None
:
102
controller.current_dal = event.node.data
103
104
self.
__node_states
[event.node.id] = event.node.is_expanded
105
106
def
__check_item_disabled
(self, item, disabled_elements):
107
"""Check if an item is disabled [currently unecessary extra method but may be useful in extended version]"""
108
return
item
in
disabled_elements
109
110
# Cache the tree state?
111
cider.widgets.selection_menu.SelectionMenu
Definition
selection_menu.py:8
cider.widgets.selection_menu.SelectionMenu.compose
compose(self)
Definition
selection_menu.py:15
cider.widgets.selection_menu.SelectionMenu.on_tree_node_selected
on_tree_node_selected(self, event)
Definition
selection_menu.py:97
cider.widgets.selection_menu.SelectionMenu.__node_states
dict __node_states
Definition
selection_menu.py:13
cider.widgets.selection_menu.SelectionMenu._build_tree
_build_tree(self)
Definition
selection_menu.py:19
cider.widgets.selection_menu.SelectionMenu._tree
_tree
Definition
selection_menu.py:12
cider.widgets.selection_menu.SelectionMenu.__check_item_disabled
__check_item_disabled(self, item, disabled_elements)
Definition
selection_menu.py:106
cider.widgets.selection_menu.SelectionMenu.__build_tree_node
__build_tree_node(self, TreeNode input_node, list input_list, bool is_disabled=False, list disabled_elements=[])
Definition
selection_menu.py:52
cider.widgets.selection_menu.SelectionMenu._controller
_controller
Definition
selection_menu.py:28
Generated on
for DUNE-DAQ by
1.17.0