DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
cider
app_structures
main_screen.py
Go to the documentation of this file.
1
from
textual.screen
import
Screen
2
from
textual.widgets
import
Footer
3
from
textual.binding
import
Binding
4
5
# Textual OKS imports
6
from
daqconf.cider.widgets.custom_rich_log
import
RichLogWError
7
from
daqconf.cider.widgets.config_table
import
ConfigTable
8
from
daqconf.cider.widgets.configuration_controller
import
ConfigurationController
9
from
daqconf.cider.widgets.popups.file_io
import
SaveWithMessageScreen, OpenFileScreen
10
from
daqconf.cider.widgets.popups.dropdown_selector
import
SelectSessionScreen
11
from
daqconf.cider.app_structures.selection_panel
import
SelectionPanel
12
from
daqconf.cider.widgets.popups.quit_screen
import
QuitScreen
13
from
daqconf.cider.widgets.popups.config_object_modifier_screen
import
ConfigObjectModifierScreen
14
from
daqconf.cider.widgets.popups.add_objects
import
AddNewObjectScreen
15
from
daqconf.cider.widgets.popups.delete_object_screen
import
DeleteConfigObjectScreen
16
from
daqconf.cider.widgets.popups.file_io
import
RenameConfigObjectScreen
17
18
from
os
import
path
19
20
21
class
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
:
63
self.
update_with_new_input
(self.
_init_input
)
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
111
def
on_configuration_controller_changed
(self, event):
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
118
def
action_save_configuration
(self)->None:
119
"""Save current configuration
120
"""
121
config = self.query_one(ConfigurationController)
122
config.commit_configuration(
"Update configuration"
)
123
124
def
action_save_configuration_with_message
(self)->None:
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
146
def
call_quit_handler
(self):
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
main_screen.MainScreen
Definition
main_screen.py:21
main_screen.MainScreen.action_save_configuration_with_message
None action_save_configuration_with_message(self)
Definition
main_screen.py:124
main_screen.MainScreen._config_controller
_config_controller
Definition
main_screen.py:38
main_screen.MainScreen.on_configuration_controller_changed
on_configuration_controller_changed(self, event)
Definition
main_screen.py:111
main_screen.MainScreen.action_save_configuration
None action_save_configuration(self)
Definition
main_screen.py:118
main_screen.MainScreen.action_request_quit
None action_request_quit(self)
Definition
main_screen.py:150
main_screen.MainScreen.action_modify_relations
None action_modify_relations(self)
Definition
main_screen.py:159
main_screen.MainScreen.action_rename_configuration
None action_rename_configuration(self)
Definition
main_screen.py:174
main_screen.MainScreen.__make_logger
__make_logger(self, bool splash=False)
Definition
main_screen.py:41
main_screen.MainScreen.logger
logger
Definition
main_screen.py:42
main_screen.MainScreen._init_input
_init_input
Definition
main_screen.py:39
main_screen.MainScreen.on_mount
on_mount(self)
Definition
main_screen.py:51
main_screen.MainScreen.action_destroy_configuration
None action_destroy_configuration(self)
Definition
main_screen.py:168
main_screen.MainScreen.action_open_configuration
None action_open_configuration(self)
Definition
main_screen.py:129
main_screen.MainScreen.update_with_new_input
update_with_new_input(self, str input_file_name)
Definition
main_screen.py:68
main_screen.MainScreen.action_add_configuration
None action_add_configuration(self)
Definition
main_screen.py:162
main_screen.MainScreen.call_quit_handler
call_quit_handler(self)
Definition
main_screen.py:146
main_screen.MainScreen.action_toggle_disable
None action_toggle_disable(self)
Definition
main_screen.py:135
main_screen.MainScreen.handle_sigint
handle_sigint(self, signum, frame)
Definition
main_screen.py:155
main_screen.MainScreen.set_initial_input_file
set_initial_input_file(self, str input_file)
Definition
main_screen.py:65
Generated on
for DUNE-DAQ by
1.17.0