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 Any
12
13from daqconf.cider.widgets.configuration_controller import ConfigurationController
14from daqconf.cider.widgets.custom_rich_log import RichLogWError
15
16
17
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
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_dropdown_list = [SingleRelationshipModifier(self._rinfo["type"], r, self._relationship_name) for r in rel_list]
94
95 yield Label(self._relationship_name)
97 yield s
98
99 # logic for button being disabled
100 add_deactivated = (not self._rinfo['multivalue'] \
101 and len(self._dropdown_list_dropdown_list)>1 \
102 or len(self._dropdown_list_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
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_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
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_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
135
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
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
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, 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)