Allow adding headings to the system list that are just strings

This commit is contained in:
ChaoticByte 2025-02-23 16:55:59 +01:00
parent a235041277
commit 49cfb6fe57
No known key found for this signature in database
2 changed files with 28 additions and 22 deletions

View file

@ -17,34 +17,38 @@ def init_ui(
def systems_list(): def systems_list():
with ui.column(align_items="center").style("width: 40vw; max-width: 40rem; min-width: 25rem;"): with ui.column(align_items="center").style("width: 40vw; max-width: 40rem; min-width: 25rem;"):
for t in systems: for t in systems:
card = ui.card().classes("w-full") if isinstance(t, System):
if t.state == SystemState.OK: card = ui.card().classes("w-full")
card = card.style("border-left: 4px solid limegreen") if t.state == SystemState.OK:
elif t.state == SystemState.FAILED: card = card.style("border-left: 4px solid limegreen")
card = card.style("border-left: 4px solid red") elif t.state == SystemState.FAILED:
else: card = card.style("border-left: 4px solid red")
card = card.style("border-left: 4px solid dodgerblue") else:
card = card.style("border-left: 4px solid dodgerblue")
with card:
ui.label(t.name).classes("text-xl font-medium") with card:
if t.description != "": ui.label(t.name).classes("text-xl font-medium")
ui.label(t.description).classes("opacity-75") if t.description != "":
if t.state_verbose != "": ui.label(t.description).classes("opacity-75")
ui.label(t.state_verbose).classes("opacity-50") if t.state_verbose != "":
actions = t.get_actions() ui.label(t.state_verbose).classes("opacity-50")
if len(actions) > 0: actions = t.get_actions()
if t.description != "" or t.state_verbose != "": if len(actions) > 0:
ui.separator() if t.description != "" or t.state_verbose != "":
with ui.card_actions(): ui.separator()
for n, c in actions.items(): with ui.card_actions():
ui.button(text=n, on_click=c) for n, c in actions.items():
ui.button(text=n, on_click=c)
elif isinstance(t, str):
ui.label(t).classes("text-2xl textmedium")
with ui.column(align_items="center").classes("w-full"): with ui.column(align_items="center").classes("w-full"):
systems_list() systems_list()
def update_states(): def update_states():
for t in systems: for t in systems:
t.update_state() if isinstance(t, System):
t.update_state()
ui.timer(system_state_update_interval, callback=update_states) ui.timer(system_state_update_interval, callback=update_states)
ui.timer(ui_refresh_interval, systems_list.refresh) ui.timer(ui_refresh_interval, systems_list.refresh)

View file

@ -47,7 +47,9 @@ class ExampleSystem(System):
# #
systems = [ systems = [
"Example Heading 1",
ExampleSystem("Example System 1", "Description text ..."), ExampleSystem("Example System 1", "Description text ..."),
"Example Heading 2",
ExampleSystem("Example System 2", "Another description text ...") ExampleSystem("Example System 2", "Another description text ...")
] ]