DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
modify_config_relations.py
Go to the documentation of this file.
1"""
2NOT COMPLETE!
3"""
4
5from textual import on
6from textual.widgets import Select, Button, Static, Label
7from textual.widgets import Button
8from textual.containers import VerticalScroll
9from rich.console import RichCast, ConsoleRenderable
10
11from typing import Protocol
12
13from daqconf.cider.widgets.configuration_controller import ConfigurationController
14from daqconf.cider.widgets.custom_rich_log import RichLogWError
15
16
17
18class RelatedDal(Protocol):
19 def __repr__(self) -> str: ...
20
21
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
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
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
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
139
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
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
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)
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)