added automatic minsize of UI to prevent hidden Elements at startup
This commit is contained in:
40
src/gui.py
40
src/gui.py
@@ -55,7 +55,6 @@ class DHCPApp(tk.Frame):
|
||||
def __init__(self, master: tk.Tk) -> None:
|
||||
super().__init__(master)
|
||||
master.title("Simple DHCP Server (Lab)")
|
||||
master.minsize(700, 500)
|
||||
self.pack(fill="both", expand=True, padx=12, pady=12)
|
||||
|
||||
# Single server instance
|
||||
@@ -104,20 +103,20 @@ class DHCPApp(tk.Frame):
|
||||
self.btn_rescan.pack(side="left", padx=(8, 0))
|
||||
|
||||
# --- Clients & Logs Paned Layout ---
|
||||
paned = ttk.Panedwindow(self, orient="horizontal")
|
||||
paned.pack(fill="both", expand=True)
|
||||
self.paned = ttk.Panedwindow(self, orient="horizontal")
|
||||
self.paned.pack(fill="both", expand=True)
|
||||
|
||||
# Clients list
|
||||
left = ttk.Labelframe(paned, text="Aktive Clients / Leases")
|
||||
left = ttk.Labelframe(self.paned, text="Aktive Clients / Leases")
|
||||
self.clients = tk.Listbox(left, height=12)
|
||||
self.clients.pack(fill="both", expand=True, padx=6, pady=6)
|
||||
paned.add(left, weight=1)
|
||||
self.paned.add(left, weight=1)
|
||||
|
||||
# Logs
|
||||
right = ttk.Labelframe(paned, text="Log")
|
||||
right = ttk.Labelframe(self.paned, text="Log")
|
||||
self.log = tk.Text(right, height=12, state="disabled")
|
||||
self.log.pack(fill="both", expand=True, padx=6, pady=6)
|
||||
paned.add(right, weight=2)
|
||||
self.paned.add(right, weight=2)
|
||||
|
||||
# --- Status bar ---
|
||||
self.status_var = tk.StringVar(value="Bereit.")
|
||||
@@ -125,6 +124,9 @@ class DHCPApp(tk.Frame):
|
||||
status.pack(fill="x", side="bottom")
|
||||
|
||||
self._refresh_interface_list(initial=True)
|
||||
self._apply_min_sizes()
|
||||
self.paned.bind("<Configure>", lambda _e: self._enforce_pane_sizes())
|
||||
self.after_idle(self._enforce_pane_sizes)
|
||||
|
||||
# periodic refresh
|
||||
self.after(400, self._refresh)
|
||||
@@ -192,6 +194,30 @@ class DHCPApp(tk.Frame):
|
||||
if not initial:
|
||||
self.status_var.set("Keine Netzwerk-Interfaces gefunden.")
|
||||
|
||||
def _apply_min_sizes(self) -> None:
|
||||
# Ensure window cannot shrink below a comfortable layout
|
||||
self.update_idletasks()
|
||||
min_w = max(self.winfo_reqwidth() + 16, 720)
|
||||
min_h = max(self.winfo_reqheight() + 16, 540)
|
||||
self.master.minsize(min_w, min_h)
|
||||
|
||||
def _enforce_pane_sizes(self) -> None:
|
||||
# prevent panes from collapsing too far
|
||||
try:
|
||||
if not self.paned or not self.paned.panes():
|
||||
return
|
||||
total = self.paned.winfo_width()
|
||||
left_min, right_min = 240, 360
|
||||
if total <= left_min + right_min:
|
||||
return
|
||||
pos = self.paned.sashpos(0)
|
||||
if pos < left_min:
|
||||
self.paned.sashpos(0, left_min)
|
||||
elif pos > total - right_min:
|
||||
self.paned.sashpos(0, total - right_min)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def rescan_interfaces(self) -> None:
|
||||
if self.server and self.server.is_running():
|
||||
messagebox.showinfo("Server läuft", "Stoppe den Server, bevor du Interfaces neu scannst.")
|
||||
|
||||
Reference in New Issue
Block a user