DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
main_screen.py
Go to the documentation of this file.
1from textual.screen import Screen
2from textual.widgets import Footer
3from textual.binding import Binding
4
5# Textual OKS imports
6from daqconf.cider.widgets.custom_rich_log import RichLogWError
7from daqconf.cider.widgets.config_table import ConfigTable
8from daqconf.cider.widgets.configuration_controller import ConfigurationController
9from daqconf.cider.widgets.popups.file_io import SaveWithMessageScreen, OpenFileScreen
10from daqconf.cider.widgets.popups.dropdown_selector import SelectSessionScreen
11from daqconf.cider.app_structures.selection_panel import SelectionPanel
12from daqconf.cider.widgets.popups.quit_screen import QuitScreen
13from daqconf.cider.widgets.popups.config_object_modifier_screen import ConfigObjectModifierScreen
14from daqconf.cider.widgets.popups.add_objects import AddNewObjectScreen
15from daqconf.cider.widgets.popups.delete_object_screen import DeleteConfigObjectScreen
16from daqconf.cider.widgets.popups.file_io import RenameConfigObjectScreen
17
18from os import path
19
20
21class MainScreen(Screen):
22 """Main screen for navigating python DBE
23 """
24
25 # Key binds
26 BINDINGS = [
27 # Binding("ctrl+s", "save_configuration", "Save Configuration"),
28 Binding("ctrl+s", "save_configuration_with_message", "Save Configuration"),
29 Binding("o", "open_configuration", "Open Configuration"),
30 Binding("ctrl+q", "request_quit", "Exit Cider"),
31 Binding("e", "modify_relations", "Modify Relation to Object"),
32 Binding("r", "rename_configuration", "Rename Conf Object"),
33 Binding("d", "toggle_disable", "Toggle Disable"),
34 Binding("a", "add_configuration", "Add Conf Object"),
35 Binding("ctrl+d", "destroy_configuration", "Delete Conf Object"),
36 ]
37
38 _config_controller = None
39 _init_input = None
40
41 def __make_logger(self, splash: bool=False):
42 self.logger = RichLogWError(id="main_log", highlight=True, markup=True)
43
44 # Splash screen
45 if splash:
46 self.logger.write("[red]========================================================================")
47 self.logger.write(" [bold yellow]Welcome to CIDER![/bold yellow]")
48 self.logger.write(" [green]This is a work in progress, please use with[/green] [bold red]caution![/bold red]")
49 self.logger.write("[red]========================================================================\n\n")
50
51 async def on_mount(self):
52 """Mount widgets with the logger appearing first"""
53 self.__make_logger(splash=True)
54 await self.mount(self.logger) # Mount the logger first
55
56 # Mount other widgets
57 if self._config_controller is None:
58 self._config_controller = ConfigurationController()
59 await self.mount(self._config_controller)
60 await self.mount(Footer())
61
62 if self._init_input is not None:
64
65 def set_initial_input_file(self, input_file: str):
66 self._init_input = input_file
67
68 def update_with_new_input(self, input_file_name: str):
69 '''
70 Update main screen to have a new input file.
71 '''
72 self._init_input = input_file_name
73
74 try:
75 self._config_controller.new_handler_from_str(input_file_name)
76 except Exception as e:
77 self.logger.write_error(e)
78 return
79
80 # Add interfaces
81 self._config_controller.add_interface("class-selection")
82 self._config_controller.add_interface("relation-selection")
83
84 # Mount the selection panel
85 try:
86 self.mount(SelectionPanel())
87 except Exception as e:
88 raise e
89
90 # Mount config table
91 try:
92 config_table = self.query_one(ConfigTable)
93 config_table.update_table(self._config_controller.current_dal)
94 except:
95 config_table = ConfigTable(id="main_table")
96 self.mount(config_table)
97
98 # Refresh the screen for safety
99 self.refresh()
100
101 # Get logger (defined at the start)
102
103 # Get the current database name
104 current_database_path = self._config_controller.configuration.databases[0]
105 data_base_name = path.basename(current_database_path)
106
107 # Print everything!
108 self.logger.write(f"[bold green]Opened new configuration file: [/bold green][bold red]{data_base_name}[/bold red][bold green].\nConnected databases are:[/bold green]\n" \
109 + "".join([f" - [red]{db}[/red] \n" for db in self._config_controller.configuration.get_includes()]))
110
112 """Updates table based on global state of the configuration controller
113 """
114 config_table = self.query_one(ConfigTable)
115 if config_table is not None:
116 config_table.update_table(event.dal)
117
119 """Save current configuration
120 """
121 config = self.query_one(ConfigurationController)
122 config.commit_configuration("Update configuration")
123
125 """Save current configuration with an update message
126 """
127 self.app.push_screen(SaveWithMessageScreen())
128
129 async def action_open_configuration(self) -> None:
130 """Activate open file splash screen
131 """
132 # Push the OpenFileScreen and wait for it to be closed
133 await self.app.push_screen(OpenFileScreen())
134
135 async def action_toggle_disable(self)->None:
136 """Toggle disable on the selected configuration object
137 """
138 if self._config_controller.can_be_disabled():
139 await self.app.push_screen(SelectSessionScreen())
140
141 else:
142 # except:
143 self.query_one(RichLogWError).write_error("Could not toggle disable configuration object")
144
145
147 """Call the quit handler just like action_request_quit."""
148 self.app.push_screen(QuitScreen()) # Show the quit confirmation screen
149
150 async def action_request_quit(self)->None:
151 """Quit TDBE
152 """
153 self.call_quit_handler()
154
155 def handle_sigint(self, signum, frame):
156 # In the event quit is done with ctrl+c
157 self.call_quit_handler()
158
159 async def action_modify_relations(self)->None:
160 self.app.push_screen(ConfigObjectModifierScreen())
161
162 async def action_add_configuration(self)->None:
163 try:
164 self.app.push_screen(AddNewObjectScreen())
165 except Exception as e:
166 self.query_one(RichLogWError).write_error(e)
167
168 async def action_destroy_configuration(self)->None:
169 try:
170 self.app.push_screen(DeleteConfigObjectScreen())
171 except Exception as e:
172 self.query_one(RichLogWError).write_error(e)
173
174 async def action_rename_configuration(self)->None:
175 self.app.push_screen(RenameConfigObjectScreen())
176
None action_save_configuration_with_message(self)
on_configuration_controller_changed(self, event)
None action_save_configuration(self)
None action_request_quit(self)
None action_modify_relations(self)
None action_rename_configuration(self)
__make_logger(self, bool splash=False)
None action_destroy_configuration(self)
None action_open_configuration(self)
update_with_new_input(self, str input_file_name)
None action_add_configuration(self)
None action_toggle_disable(self)
handle_sigint(self, signum, frame)
set_initial_input_file(self, str input_file)