- 56 PNG icons (28 unique × 2 color variants) from Material Design Icons (round style, 96×96px) - core/icons.py: ctk_icon(), make_icon_button(), reconfigure_icon_button() with CTkImage cache - Updated 15 GUI files: app.py, sidebar.py, server_dialog.py, all tabs - build.py: auto-include assets/icons/ in PyInstaller bundle, patch rollover at 99→minor+1 - tools/download_icons.py: icon download script - Automatic dark↔light theme switching via CTkImage dual-image support Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
119 lines
4.3 KiB
Python
119 lines
4.3 KiB
Python
"""
|
|
Info tab — display server details, edit button.
|
|
"""
|
|
|
|
import customtkinter as ctk
|
|
from core.i18n import t
|
|
from core.icons import icon_text, make_icon_button
|
|
|
|
|
|
class InfoTab(ctk.CTkFrame):
|
|
# Map field keys to i18n keys
|
|
_FIELD_KEYS = ["alias", "ip", "port", "user", "type", "database", "db_index", "ssl", "notes", "status"]
|
|
_FIELD_I18N = {
|
|
"alias": "info_alias",
|
|
"ip": "info_ip",
|
|
"port": "info_port",
|
|
"user": "info_user",
|
|
"type": "info_type",
|
|
"database": "info_database",
|
|
"db_index": "info_db_index",
|
|
"ssl": "info_ssl",
|
|
"notes": "info_notes",
|
|
"status": "info_status",
|
|
}
|
|
|
|
# Which fields are relevant per server type
|
|
_SQL_TYPES = {"mariadb", "mssql", "postgresql"}
|
|
_SSL_TYPES = {"grafana", "prometheus", "winrm"}
|
|
_NO_USER_TYPES = {"redis", "grafana", "prometheus"}
|
|
|
|
def __init__(self, master, store, edit_callback=None):
|
|
super().__init__(master, fg_color="transparent")
|
|
self.store = store
|
|
self.edit_callback = edit_callback
|
|
self._current_alias: str | None = None
|
|
|
|
# Header
|
|
self.header = ctk.CTkLabel(self, text=t("no_server_selected_info"), font=ctk.CTkFont(size=20, weight="bold"))
|
|
self.header.pack(padx=20, pady=(20, 10))
|
|
|
|
# Info card
|
|
self.card = ctk.CTkFrame(self)
|
|
self.card.pack(fill="x", padx=20, pady=10)
|
|
|
|
self._fields: dict[str, ctk.CTkLabel] = {}
|
|
self._field_labels: dict[str, ctk.CTkLabel] = {}
|
|
for key in self._FIELD_KEYS:
|
|
row = ctk.CTkFrame(self.card, fg_color="transparent")
|
|
row.pack(fill="x", padx=15, pady=4)
|
|
label = ctk.CTkLabel(row, text=t(self._FIELD_I18N[key]), width=80, anchor="w",
|
|
font=ctk.CTkFont(size=12), text_color="#9ca3af")
|
|
label.pack(side="left")
|
|
val = ctk.CTkLabel(row, text="-", anchor="w", font=ctk.CTkFont(size=13))
|
|
val.pack(side="left", fill="x", expand=True)
|
|
self._field_labels[key] = label
|
|
self._fields[key] = val
|
|
|
|
# Edit button
|
|
self.edit_btn = make_icon_button(self, "edit", t("edit_server_btn"), command=self._on_edit)
|
|
self.edit_btn.pack(pady=15)
|
|
|
|
def set_server(self, alias: str | None):
|
|
self._current_alias = alias
|
|
self.refresh()
|
|
|
|
def refresh(self):
|
|
if not self._current_alias:
|
|
self.header.configure(text=t("no_server_selected_info"))
|
|
for v in self._fields.values():
|
|
v.configure(text="-")
|
|
return
|
|
|
|
server = self.store.get_server(self._current_alias)
|
|
if not server:
|
|
return
|
|
|
|
stype = server.get("type", "ssh").lower()
|
|
|
|
self.header.configure(text=server["alias"])
|
|
self._fields["alias"].configure(text=server.get("alias", "-"))
|
|
self._fields["ip"].configure(text=server.get("ip", "-"))
|
|
self._fields["port"].configure(text=str(server.get("port", 22)))
|
|
|
|
# Hide user for types that don't use it
|
|
if stype in self._NO_USER_TYPES:
|
|
self._fields["user"].configure(text="-")
|
|
else:
|
|
self._fields["user"].configure(text=server.get("user", "root"))
|
|
|
|
self._fields["type"].configure(text=stype.upper())
|
|
|
|
# Database field — relevant for SQL types
|
|
if stype in self._SQL_TYPES:
|
|
self._fields["database"].configure(text=server.get("database", "-"))
|
|
else:
|
|
self._fields["database"].configure(text="-")
|
|
|
|
# DB index — relevant for redis
|
|
if stype == "redis":
|
|
self._fields["db_index"].configure(text=str(server.get("db_index", 0)))
|
|
else:
|
|
self._fields["db_index"].configure(text="-")
|
|
|
|
# SSL — relevant for grafana, prometheus, winrm
|
|
if stype in self._SSL_TYPES:
|
|
self._fields["ssl"].configure(text="Yes" if server.get("use_ssl") else "No")
|
|
else:
|
|
self._fields["ssl"].configure(text="-")
|
|
|
|
self._fields["notes"].configure(text=server.get("notes", "-") or "-")
|
|
|
|
status = self.store.get_status(self._current_alias)
|
|
color = {"online": "#22c55e", "offline": "#ef4444"}.get(status, "#9ca3af")
|
|
self._fields["status"].configure(text=status.upper(), text_color=color)
|
|
|
|
def _on_edit(self):
|
|
if self.edit_callback and self._current_alias:
|
|
self.edit_callback(self._current_alias)
|