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