-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual_status.py
More file actions
88 lines (69 loc) · 2.23 KB
/
Copy pathvisual_status.py
File metadata and controls
88 lines (69 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import annotations
from typing import Any, Iterable, Optional
def safe_len(value: Optional[Iterable[Any]]) -> int:
if value is None:
return 0
try:
return len(value)
except Exception:
count = 0
for _ in value:
count += 1
return count
def normalize_mode_name(mode: Optional[str]) -> str:
if not mode:
return "Unknown"
mode = str(mode).strip().lower()
mapping = {
"sandbox": "Sandbox",
"controlled": "Controlled Path",
"control": "Controlled Path",
"kontrollu": "Controlled Path",
"kontrollü": "Controlled Path",
}
return mapping.get(mode, mode.title())
def build_status_text(
mode: str = "sandbox",
*,
selected: Any = "-",
path: Optional[Iterable[Any]] = None,
state: str = "Ready",
extra: Optional[str] = None,
) -> str:
mode_name = normalize_mode_name(mode)
path_length = safe_len(path)
text = f"Mode: {mode_name} | Selected: {selected} | Path Length: {path_length} | State: {state}"
if extra:
text += f" | {extra}"
return text
def build_result_status(mode: str, result: Any) -> str:
path = getattr(result, "path", None)
state = getattr(result, "state", "Ready")
selected = getattr(result, "selected", "-")
extra = getattr(result, "extra", None)
return build_status_text(
mode=mode,
selected=selected,
path=path,
state=state,
extra=extra,
)
def update_status_label(label, text: str) -> None:
try:
label.configure(text=text)
except Exception:
label.config(text=text)
def set_ready(label, mode: str = "sandbox") -> None:
update_status_label(label, build_status_text(mode=mode, state="Ready"))
def set_running(label, mode: str = "sandbox", selected: Any = "-") -> None:
update_status_label(label, build_status_text(mode=mode, selected=selected, state="Running"))
def set_finished(label, mode: str = "sandbox", selected: Any = "-", path: Optional[Iterable[Any]] = None) -> None:
update_status_label(
label,
build_status_text(
mode=mode,
selected=selected,
path=path,
state="Finished",
),
)