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