DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
cider
widgets
modify_config_relations.py
Go to the documentation of this file.
1
"""
2
NOT COMPLETE!
3
"""
4
5
from
textual
import
on
6
from
textual.widgets
import
Select, Button, Static, Label
7
from
textual.widgets
import
Button
8
from
textual.containers
import
VerticalScroll
9
from
rich.console
import
RichCast, ConsoleRenderable
10
11
from
typing
import
Protocol
12
13
from
daqconf.cider.widgets.configuration_controller
import
ConfigurationController
14
from
daqconf.cider.widgets.custom_rich_log
import
RichLogWError
15
16
17
18
class
RelatedDal
(Protocol):
19
def
__repr__
(self) -> str: ...
20
21
22
class
SingleRelationshipModifier
(Static):
23
def
__init__
(self, relationship_type: str, current_related_dal: RelatedDal | object, relationship_name: str,
24
renderable: ConsoleRenderable | RichCast | str =
""
, *, expand: bool =
False
,
25
shrink: bool =
False
, markup: bool =
True
, name: str |
None
=
None
, id: str |
None
=
None
,
26
classes: str |
None
=
None
, disabled: bool =
False
) ->
None
:
27
28
super().
__init__
(renderable, expand=expand, shrink=shrink, markup=markup,
29
name=name, id=id, classes=classes, disabled=disabled)
30
31
self.
_relationship_type
= relationship_type
32
self.
_current_related_dal
= current_related_dal
33
self.
_relationship_name
= relationship_name
34
35
@property
36
def
current_dal
(self):
37
return
self.
_current_related_dal
38
39
def
compose
(self):
40
# Need to get the main screen etc.
41
main_screen = self.app.get_screen(
"main"
)
42
self.
_config_controller
: ConfigurationController = main_screen.query_one(ConfigurationController)
43
self.
_logger
: RichLogWError = main_screen.query_one(
"#main_log"
)
44
45
# yield Grid(
46
# Actual dropdown menu
47
yield
Select([(repr(rel), rel)
for
48
rel
in
self.
_config_controller
.get_dals_of_class(self.
_relationship_type
)],
49
value=self.
_current_related_dal
, id=
"select_obj"
)
50
# Need a delete button
51
yield
Button(
"Delete"
, id=
"delete_rel"
, variant=
"error"
)
52
53
54
@on(Select.Changed)
55
def
select_changed
(self, event: Select.Changed)->
None
:
56
# Want to update the DAL
57
# HACK I really hate this, currently select can't deal with complex types
58
# Rather than change the low down stuff we convert to dal here
59
self.
_current_related_dal
= event.value
60
try
:
61
self.
_config_controller
.modify_current_dal_relationship(self.
_relationship_name
, self.
_current_related_dal
)
62
except
Exception
as
e:
63
self.
_logger
.write_error(e)
64
65
66
@on(Button.Pressed)
67
def
button_pressed
(self, event: Button.Pressed)->
None
:
68
if
event.button.id==
"delete_rel"
:
69
# Pop dal [if it's empty will just delete]
70
try
:
71
self.
_config_controller
.pop_dal_relationship(self.
_relationship_name
, self.
_current_related_dal
)
72
except
:
73
self.
_logger
.write(
"[bold blue]Info:[/bold blue] [blue]Removing duplicate"
)
74
self.remove()
75
76
77
class
RelationshipTypeGroup
(Static):
78
def
__init__
(self, relationship_name: str, renderable: ConsoleRenderable | RichCast | str =
""
, *, expand: bool =
False
, shrink: bool =
False
, markup: bool =
True
, name: str |
None
=
None
, id: str |
None
=
None
, classes: str |
None
=
None
, disabled: bool =
False
) ->
None
:
79
super().
__init__
(renderable, expand=expand, shrink=shrink, markup=markup, name=name, id=id, classes=classes, disabled=disabled)
80
81
self.
_relationship_name
= relationship_name
82
83
def
compose
(self):
84
main_screen = self.app.get_screen(
"main"
)
85
self.
_config_controller
: ConfigurationController = main_screen.query_one(ConfigurationController)
86
self.
_logger
: RichLogWError = main_screen.query_one(
"#main_log"
)
87
88
# Grab relations
89
relationship_dict = self.
_config_controller
.get_relation_category_in_current_dal(self.
_relationship_name
)
90
91
self.
_rinfo
= relationship_dict[
'rel_info'
]
92
rel_list = relationship_dict[self.
_relationship_name
]
93
94
# Want to be able to grab these
95
# self._dropdown_list = [SingleRelationshipModifier(self._rinfo["type"], r, self._relationship_name) ]
96
97
self.
_dropdown_list
= [
SingleRelationshipModifier
(self.
_rinfo
[
"type"
], r, self.
_relationship_name
)
for
r
in
rel_list]
98
99
yield
Label(self.
_relationship_name
)
100
for
s
in
self.
_dropdown_list
:
101
yield
s
102
103
# logic for button being disabled
104
add_deactivated = (
not
self.
_rinfo
[
'multivalue'
] \
105
and
len(self.
_dropdown_list
)>1 \
106
or
len(self.
_dropdown_list
)==len(self.
_config_controller
.get_dals_of_class(self.
_rinfo
[
'type'
])))
107
108
109
yield
Button(
"Add Relation"
,
"success"
, id=
"add_dal"
, disabled=add_deactivated)
110
111
def
verify_unique_dals
(self):
112
# Dumb hack, since dals occasionally have hache issues, replaces with string representation
113
selected_dals = [repr(s.current_dal)
for
s
in
self.
_dropdown_list
]
114
115
# Which lets us convert the entire thing to a set
116
if
len(selected_dals)!=len(set(selected_dals)):
117
raise
Exception(f
"Error DAL list contains non-unique entry for {self._relationship_name}"
)
118
119
# If this is meant to be implemented, has it been?
120
if
len(selected_dals)==0
and
self.
_rinfo
[
'not-null'
]:
121
raise
Exception(f
"Error {self._relationship_name} is required but has no DALs..."
)
122
123
def
_add_new_selection_box
(self):
124
if
not
len(self.
_config_controller
.get_dals_of_class(self.
_rinfo
[
"type"
])):
125
raise
Exception(f
"Error cannot find any objects of type {self._rinfo['type']}"
)
126
127
s =
SingleRelationshipModifier
(self.
_rinfo
[
"type"
],
128
self.
_config_controller
.get_dals_of_class(self.
_rinfo
[
"type"
])[0]
129
, self.
_relationship_name
)
130
self.
_dropdown_list
.append(s)
131
self.mount(s)
132
133
@on(Button.Pressed)
134
def
button_pressed
(self, event: Button.Pressed):
135
if
event.button.id !=
"add_dal"
:
136
return
137
138
self.
_add_new_selection_box
()
139
140
class
RelationshipSelectPanel
(Static):
141
def
compose
(self):
142
main_screen = self.app.get_screen(
"main"
)
143
self.
_config_controller
: ConfigurationController = main_screen.query_one(ConfigurationController)
144
self.
_logger
: RichLogWError = main_screen.query_one(
"#main_log"
)
145
146
relation_names = [list(r.keys())[0]
for
r
in
self.
_config_controller
.get_relations_to_current_dal()]
147
148
self.
_relation_groups
= [
RelationshipTypeGroup
(r)
for
r
in
relation_names]
149
150
yield
VerticalScroll(
151
*self.
_relation_groups
,
152
id=
"rel_groups_vert"
153
)
154
155
def
verify_relations
(self):
156
for
r
in
self.
_relation_groups
:
157
try
:
158
r.verify_unique_dals()
159
except
Exception
as
e:
160
self.
_logger
.write(e)
161
162
cider.widgets.modify_config_relations.RelatedDal
Definition
modify_config_relations.py:18
cider.widgets.modify_config_relations.RelatedDal.__repr__
str __repr__(self)
Definition
modify_config_relations.py:19
cider.widgets.modify_config_relations.RelationshipSelectPanel
Definition
modify_config_relations.py:140
cider.widgets.modify_config_relations.RelationshipSelectPanel.verify_relations
verify_relations(self)
Definition
modify_config_relations.py:155
cider.widgets.modify_config_relations.RelationshipSelectPanel._logger
RichLogWError _logger
Definition
modify_config_relations.py:144
cider.widgets.modify_config_relations.RelationshipSelectPanel._relation_groups
list _relation_groups
Definition
modify_config_relations.py:148
cider.widgets.modify_config_relations.RelationshipSelectPanel.compose
compose(self)
Definition
modify_config_relations.py:141
cider.widgets.modify_config_relations.RelationshipSelectPanel._config_controller
ConfigurationController _config_controller
Definition
modify_config_relations.py:143
cider.widgets.modify_config_relations.RelationshipTypeGroup
Definition
modify_config_relations.py:77
cider.widgets.modify_config_relations.RelationshipTypeGroup.verify_unique_dals
verify_unique_dals(self)
Definition
modify_config_relations.py:111
cider.widgets.modify_config_relations.RelationshipTypeGroup._relationship_name
_relationship_name
Definition
modify_config_relations.py:81
cider.widgets.modify_config_relations.RelationshipTypeGroup._config_controller
ConfigurationController _config_controller
Definition
modify_config_relations.py:85
cider.widgets.modify_config_relations.RelationshipTypeGroup._logger
RichLogWError _logger
Definition
modify_config_relations.py:86
cider.widgets.modify_config_relations.RelationshipTypeGroup._dropdown_list
list _dropdown_list
Definition
modify_config_relations.py:97
cider.widgets.modify_config_relations.RelationshipTypeGroup.button_pressed
button_pressed(self, Button.Pressed event)
Definition
modify_config_relations.py:134
cider.widgets.modify_config_relations.RelationshipTypeGroup._add_new_selection_box
_add_new_selection_box(self)
Definition
modify_config_relations.py:123
cider.widgets.modify_config_relations.RelationshipTypeGroup.compose
compose(self)
Definition
modify_config_relations.py:83
cider.widgets.modify_config_relations.RelationshipTypeGroup._rinfo
_rinfo
Definition
modify_config_relations.py:91
cider.widgets.modify_config_relations.RelationshipTypeGroup.__init__
None __init__(self, str relationship_name, ConsoleRenderable|RichCast|str renderable="", *, bool expand=False, bool shrink=False, bool markup=True, str|None name=None, str|None id=None, str|None classes=None, bool disabled=False)
Definition
modify_config_relations.py:78
cider.widgets.modify_config_relations.SingleRelationshipModifier
Definition
modify_config_relations.py:22
cider.widgets.modify_config_relations.SingleRelationshipModifier._relationship_name
_relationship_name
Definition
modify_config_relations.py:33
cider.widgets.modify_config_relations.SingleRelationshipModifier._relationship_type
_relationship_type
Definition
modify_config_relations.py:31
cider.widgets.modify_config_relations.SingleRelationshipModifier._current_related_dal
_current_related_dal
Definition
modify_config_relations.py:32
cider.widgets.modify_config_relations.SingleRelationshipModifier.current_dal
current_dal(self)
Definition
modify_config_relations.py:36
cider.widgets.modify_config_relations.SingleRelationshipModifier.select_changed
None select_changed(self, Select.Changed event)
Definition
modify_config_relations.py:55
cider.widgets.modify_config_relations.SingleRelationshipModifier._config_controller
ConfigurationController _config_controller
Definition
modify_config_relations.py:42
cider.widgets.modify_config_relations.SingleRelationshipModifier._logger
RichLogWError _logger
Definition
modify_config_relations.py:43
cider.widgets.modify_config_relations.SingleRelationshipModifier.__init__
None __init__(self, str relationship_type, RelatedDal|object current_related_dal, str relationship_name, ConsoleRenderable|RichCast|str renderable="", *, bool expand=False, bool shrink=False, bool markup=True, str|None name=None, str|None id=None, str|None classes=None, bool disabled=False)
Definition
modify_config_relations.py:26
cider.widgets.modify_config_relations.SingleRelationshipModifier.compose
compose(self)
Definition
modify_config_relations.py:39
cider.widgets.modify_config_relations.SingleRelationshipModifier.button_pressed
None button_pressed(self, Button.Pressed event)
Definition
modify_config_relations.py:67
Generated on
for DUNE-DAQ by
1.17.0