From d9f0a69eae4da77e2cee5f31c7fe2ac9648948f9 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Wed, 14 Oct 2026 11:33:01 +0200 Subject: [PATCH] =?UTF-8?q?Wydaj=20wersj=C4=99=200.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ app.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8efa64c..c842cee 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Prosty monitor dostępności hostów przez HTTP albo ICMP. Wymaga Python 3.10+ i nie korzysta z dodatkowych pakietów. +Wersja: `0.0.1` + ## Aplikacja graficzna Uruchom: diff --git a/app.py b/app.py index 00fa2bf..24fd358 100644 --- a/app.py +++ b/app.py @@ -16,6 +16,7 @@ from tkinter import messagebox, ttk from host_checker import CheckResult, check +__version__ = "0.0.1" CONFIG_FILE = Path(__file__).with_name("hosts.json") @@ -28,7 +29,7 @@ class Host: class HostMonitorApp(tk.Tk): def __init__(self) -> None: super().__init__() - self.title("Monitor dostępności hostów") + self.title(f"Monitor dostępności hostów v{__version__}") self.geometry("1120x620") self.minsize(850, 450) self.hosts: list[Host] = [] @@ -37,6 +38,7 @@ class HostMonitorApp(tk.Tk): self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=10) self.running = False self.after_id: str | None = None + self.selected_target: str | None = None self.worker_lock = threading.Lock() self._build_ui() self._load_config() @@ -80,6 +82,7 @@ class HostMonitorApp(tk.Tk): self.table.configure(yscrollcommand=scrollbar.set) self.table.pack(side="left", fill="both", expand=True) scrollbar.pack(side="right", fill="y") + self.table.bind("<>", self._select_host) self.table.tag_configure("up", foreground="#16803c") self.table.tag_configure("down", foreground="#b42318") self.table.tag_configure("unknown", foreground="#666666") @@ -87,18 +90,52 @@ class HostMonitorApp(tk.Tk): self.status_var = tk.StringVar(value="Gotowy. Dodaj hosty i uruchom monitoring.") ttk.Label(self, textvariable=self.status_var, relief="sunken", anchor="w", padding=5).pack(fill="x", side="bottom") + def _select_host(self, _event: tk.Event[tk.Misc] | None = None) -> None: + selected = self.table.selection() + if len(selected) != 1: + self.selected_target = None + return + target = selected[0] + host = next((item for item in self.hosts if item.target == target), None) + if host is None: + self.selected_target = None + return + self.selected_target = target + self.target_var.set(host.target) + self.method_var.set(host.method) + def _add_host(self) -> None: target = self.target_var.get().strip() method = self.method_var.get() if not target: messagebox.showwarning("Brak hosta", "Wpisz adres hosta lub URL.") return - existing = next((host for host in self.hosts if host.target == target), None) - if existing: - existing.method = method + + selected_host = next((host for host in self.hosts if host.target == self.selected_target), None) + duplicate = next((host for host in self.hosts if host.target == target and host is not selected_host), None) + if duplicate: + messagebox.showwarning("Host już istnieje", "Host o tym adresie jest już na liście.") + return + + was_update = selected_host is not None + if selected_host: + old_target = selected_host.target + selected_host.target = target + selected_host.method = method + if old_target != target: + if old_target in self.stats: + self.stats[target] = self.stats.pop(old_target) + self.selected_target = target else: - self.hosts.append(Host(target, method)) - self.target_var.set("") + existing = next((host for host in self.hosts if host.target == target), None) + if existing: + existing.method = method + self.selected_target = target + else: + self.hosts.append(Host(target, method)) + self.selected_target = target + if not was_update: + self.target_var.set("") self._refresh_table() self._save_config(silent=True) @@ -109,6 +146,8 @@ class HostMonitorApp(tk.Tk): self.hosts = [host for host in self.hosts if host.target not in selected] for target in selected: self.stats.pop(target, None) + if self.selected_target in selected: + self.selected_target = None self._refresh_table() self._save_config(silent=True) @@ -195,6 +234,9 @@ class HostMonitorApp(tk.Tk): self.table.item(host.target, values=values, tags=(tag,)) else: self.table.insert("", "end", iid=host.target, values=values, tags=(tag,)) + if self.selected_target in current: + self.table.selection_set(self.selected_target) + self.table.focus(self.selected_target) def _load_config(self) -> None: if CONFIG_FILE.exists():