59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
"""Rendering for the compact official-realm status strip."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Iterable
|
|
|
|
from ...depot import DepotStartOption
|
|
from ...server_status import RealmServerStatus
|
|
from ..viewmodels.health import server_status_presentation
|
|
|
|
|
|
def render_server_status(
|
|
container: Any,
|
|
*,
|
|
ttk: Any,
|
|
statuses: tuple[RealmServerStatus, ...] | None,
|
|
start_options: Iterable[DepotStartOption],
|
|
placeholder: str,
|
|
show_debug_details: bool,
|
|
) -> None:
|
|
"""Replace the status strip contents from one immutable state snapshot."""
|
|
|
|
for child in container.winfo_children():
|
|
child.destroy()
|
|
if statuses is None:
|
|
ttk.Label(
|
|
container,
|
|
text=placeholder,
|
|
style="ServerUnknown.TLabel",
|
|
).pack(side="left", anchor="w")
|
|
return
|
|
statuses_by_name = {item.name.casefold(): item for item in statuses}
|
|
visible = [
|
|
statuses_by_name[option.name.casefold()]
|
|
for option in start_options
|
|
if option.name.casefold() in statuses_by_name
|
|
]
|
|
if not visible:
|
|
ttk.Label(
|
|
container,
|
|
text="Official status is unavailable for this realm.",
|
|
style="ServerUnknown.TLabel",
|
|
).pack(side="left", anchor="w")
|
|
return
|
|
for index, server in enumerate(visible):
|
|
presentation = server_status_presentation(
|
|
server,
|
|
show_debug_details=show_debug_details,
|
|
)
|
|
ttk.Label(
|
|
container,
|
|
text=presentation.text,
|
|
style=presentation.style,
|
|
).pack(
|
|
side="left",
|
|
anchor="w",
|
|
padx=(0 if index == 0 else 6, 0),
|
|
)
|