Wydaj wersję 0.0.1

This commit is contained in:
Wojtek
2026-10-14 11:33:01 +02:00
parent 6ffbce804e
commit d9f0a69eae
2 changed files with 50 additions and 6 deletions
+2
View File
@@ -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:
+43 -1
View File
@@ -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("<<TreeviewSelect>>", 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,17 +90,51 @@ 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
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:
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():