Files
pristontale-eu-linux/ptlinux/ui/components/progress_panel.py
2026-09-03 19:07:09 +02:00

164 lines
4.6 KiB
Python

"""Operation progress, realm choice, and server-summary controls."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
@dataclass(frozen=True)
class ProgressPanel:
container: Any
realm_value: Any
realm_selector: Any
play_button: Any
status: Any
progress_text: Any
speed_text: Any
client_activity_text: Any
download_context_text: Any
activity_meta_text: Any
progress_bar: Any
server_status_content: Any
server_status_debug_text: Any
log_toggle: Any
def refresh_activity_metadata(self) -> None:
self.activity_meta_text.set(
self.download_context_text.get() or self.client_activity_text.get()
)
def set_download_context(self, value: str) -> None:
self.download_context_text.set(value)
self.refresh_activity_metadata()
def build_progress_panel(
parent: Any,
*,
widgets: Any,
tk_module: Any,
default_realm: str,
) -> ProgressPanel:
activity_panel = widgets.Frame(parent, style="Surface.TFrame", padding=(10, 7))
activity_panel.pack(fill="x", pady=(0, 8))
realm_value = tk_module.StringVar(value=default_realm)
activity_action = widgets.Frame(activity_panel, style="Surface.TFrame")
activity_action.pack(side="right", fill="y", padx=(12, 0))
play_button = widgets.Button(
activity_action,
text="PLAY",
style="Play.TButton",
underline=0,
)
play_button.pack(fill="both", expand=True)
realm_selector = widgets.Combobox(
activity_action,
name="realm_selector",
textvariable=realm_value,
values=(default_realm,),
state="readonly",
style="Realm.TCombobox",
font=("Sans", 9, "bold"),
justify="center",
width=20,
)
realm_selector.pack(fill="x", pady=(6, 5))
activity_copy = widgets.Frame(activity_panel, style="Surface.TFrame")
activity_copy.pack(side="left", fill="both", expand=True)
status = tk_module.StringVar(value="Ready")
progress_text = tk_module.StringVar(value="Click Play to start your journey")
speed_text = tk_module.StringVar(value="")
client_activity_text = tk_module.StringVar(value="")
download_context_text = tk_module.StringVar(value="")
activity_meta_text = tk_module.StringVar(value="")
activity_heading = widgets.Frame(activity_copy, style="Surface.TFrame")
activity_heading.pack(fill="x")
widgets.Label(
activity_heading,
textvariable=status,
style="Status.TLabel",
).pack(side="left", anchor="w")
widgets.Label(
activity_heading,
textvariable=activity_meta_text,
style="Muted.TLabel",
).pack(side="right", anchor="e")
progress_bar = widgets.Progressbar(
activity_copy,
style="Depot.Horizontal.TProgressbar",
mode="determinate",
maximum=1,
value=0,
)
progress_bar.pack(fill="x", pady=(5, 2))
progress_details = widgets.Frame(activity_copy, style="Surface.TFrame")
progress_details.pack(fill="x")
widgets.Label(
progress_details,
textvariable=speed_text,
style="Speed.TLabel",
width=28,
anchor="e",
).pack(side="right")
widgets.Label(
progress_details,
textvariable=progress_text,
style="Muted.TLabel",
anchor="w",
).pack(side="left", fill="x", expand=True)
server_status_row = widgets.Frame(activity_copy, style="Surface.TFrame")
server_status_row.pack(fill="x", pady=(5, 1))
widgets.Label(
server_status_row,
text="SERVERS",
style="ServerHeading.TLabel",
).pack(side="left", fill="y", padx=(0, 8))
server_status_content = widgets.Frame(server_status_row, style="Surface.TFrame")
server_status_content.pack(side="left", fill="y", anchor="w")
log_toggle = tk_module.Button(
server_status_row,
text=">_",
background="#191311",
foreground="#f8fafc",
activebackground="#24170f",
activeforeground="#ffffff",
font=("Monospace", 8, "bold"),
padx=3,
pady=1,
borderwidth=0,
highlightthickness=1,
highlightbackground="#191311",
highlightcolor="#f4bd61",
relief="flat",
takefocus=True,
)
log_toggle.pack(side="right", anchor="e", padx=(8, 0))
server_status_debug_text = tk_module.StringVar(value="")
widgets.Label(
server_status_row,
textvariable=server_status_debug_text,
style="Muted.TLabel",
).pack(side="right", anchor="e", padx=(8, 0))
widgets.Label(
server_status_content,
text="Checking official server status…",
style="ServerUnknown.TLabel",
).pack(side="left", anchor="w")
return ProgressPanel(
container=activity_panel,
realm_value=realm_value,
realm_selector=realm_selector,
play_button=play_button,
status=status,
progress_text=progress_text,
speed_text=speed_text,
client_activity_text=client_activity_text,
download_context_text=download_context_text,
activity_meta_text=activity_meta_text,
progress_bar=progress_bar,
server_status_content=server_status_content,
server_status_debug_text=server_status_debug_text,
log_toggle=log_toggle,
)