Untitled
unknown
plain_text
a year ago
8.2 kB
6
Indexable
class WiFiDiagnosticsScreen(ctk.CTkFrame):
def __init__(self, parent, dark_mode: bool, language: str):
super().__init__(parent)
self.diagnostics = WiFiDiagnostics()
self.dark_mode = dark_mode
self.language = language
self.parent = parent
self.place(x=0, y=0, relwidth=1, relheight=1)
# Background color setup
bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
accent_color = '#2c2c2e' if dark_mode else '#e5e5e7'
text_color = 'white' if dark_mode else 'black'
self.configure(fg_color=bg_color)
# Header with title and close button
header = ctk.CTkFrame(self, fg_color=bg_color, height=50)
header.pack(fill='x', padx=20, pady=(20,10))
title = ctk.CTkLabel(
header,
text=TRANSLATIONS[language]['wifi_diagnostics'],
font=("Dongle", 24, "bold"),
text_color=text_color
)
title.pack(side='left')
close_btn = ctk.CTkButton(
header,
text="×",
width=40,
height=40,
font=("Dongle", 20),
fg_color=accent_color,
hover_color='#3a3a3c' if dark_mode else '#d1d1d6',
command=self.close_diagnostics
)
close_btn.pack(side='right')
# Main content container
content = ctk.CTkFrame(self, fg_color=bg_color)
content.pack(fill='both', expand=True, padx=20, pady=10)
# Left status panel
self.status_panel = ctk.CTkFrame(
content,
fg_color=accent_color,
corner_radius=10,
width=300
)
self.status_panel.pack(side='left', fill='y', padx=(0,10))
# Status panel content
status_title = ctk.CTkLabel(
self.status_panel,
text="WLAN",
font=("Dongle", 20, "bold"),
text_color=text_color
)
status_title.pack(pady=(20,10), padx=20, anchor='w')
# Current network
current_network_label = ctk.CTkLabel(
self.status_panel,
text=TRANSLATIONS[language]['current_network'],
font=("Dongle", 16),
text_color=text_color
)
current_network_label.pack(pady=(10,5), padx=20, anchor='w')
self.network_label = ctk.CTkLabel(
self.status_panel,
text="-",
font=("Dongle", 16, "bold"),
text_color=text_color
)
self.network_label.pack(pady=(0,10), padx=20, anchor='w')
# Status
status_label = ctk.CTkLabel(
self.status_panel,
text="Status",
font=("Dongle", 16),
text_color=text_color
)
status_label.pack(pady=(10,5), padx=20, anchor='w')
self.status_value = ctk.CTkLabel(
self.status_panel,
text=TRANSLATIONS[language]['wifi_disconnected'],
font=("Dongle", 16, "bold"),
text_color='#ff453a'
)
self.status_value.pack(pady=(0,10), padx=20, anchor='w')
# IP Address
ip_label = ctk.CTkLabel(
self.status_panel,
text="IP",
font=("Dongle", 16),
text_color=text_color
)
ip_label.pack(pady=(10,5), padx=20, anchor='w')
self.ip_value = ctk.CTkLabel(
self.status_panel,
text="-",
font=("Dongle", 16, "bold"),
text_color=text_color
)
self.ip_value.pack(pady=(0,10), padx=20, anchor='w')
# Right network list panel
self.network_panel = ctk.CTkFrame(
content,
fg_color=accent_color,
corner_radius=10
)
self.network_panel.pack(side='left', fill='both', expand=True)
# Refresh button
refresh_btn = ctk.CTkButton(
self.network_panel,
text="↻",
width=40,
height=40,
font=("Dongle", 20),
fg_color=accent_color,
hover_color='#3a3a3c' if dark_mode else '#d1d1d6',
command=self.scan_networks
)
refresh_btn.pack(pady=10, padx=10, anchor='e')
# Network list
self.network_list = ctk.CTkScrollableFrame(
self.network_panel,
fg_color='transparent',
corner_radius=0
)
self.network_list.pack(fill='both', expand=True, padx=2, pady=2)
# Start monitoring and initial scan
self.diagnostics.start_monitoring(self.update_status)
self.after(100, self.scan_networks) # Delay initial scan slightly
# Schedule periodic rescans
self.rescan_networks()
def rescan_networks(self):
"""Periodically rescan for networks"""
self.scan_networks()
self.after(30000, self.rescan_networks) # Rescan every 30 seconds
def scan_networks(self):
# Clear existing network list
for widget in self.network_list.winfo_children():
widget.destroy()
scanning_label = ctk.CTkLabel(
self.network_list,
text="Scanning for networks...",
font=("Dongle", 16),
text_color='white' if self.dark_mode else 'black'
)
scanning_label.pack(pady=10)
def scan():
try:
networks = self.diagnostics.get_available_networks()
self.after(100, lambda: self._update_network_list(networks, scanning_label))
except Exception as e:
print(f"Scan error: {e}")
self.after(100, lambda: self._show_scan_error(scanning_label))
threading.Thread(target=scan, daemon=True).start()
def _update_network_list(self, networks, scanning_label):
try:
scanning_label.destroy()
except tk.TclError:
return # Widget already destroyed
if not networks:
no_networks_label = ctk.CTkLabel(
self.network_list,
text="No networks found",
font=("Dongle", 16),
text_color='white' if self.dark_mode else 'black'
)
no_networks_label.pack(pady=10)
return
current_network = self.diagnostics.get_current_network()
for network in networks:
try:
ssid = network['ssid']
if not ssid: # Skip empty SSIDs
continue
network_frame = ctk.CTkFrame(
self.network_list,
fg_color='transparent'
)
network_frame.pack(fill='x', pady=2, padx=5)
is_current = ssid == current_network
btn = ctk.CTkButton(
network_frame,
text=ssid,
font=("Dongle", 16),
height=40,
fg_color='#34c759' if is_current else '#3a3a3c' if self.dark_mode else '#d1d1d6',
hover_color='#32b357' if is_current else '#34c759',
text_color='white' if self.dark_mode else 'black',
command=lambda s=ssid: self.show_connection_screen(s)
)
btn.pack(fill='x')
except tk.TclError:
return # Screen was closed during update
def _show_scan_error(self, scanning_label):
try:
scanning_label.configure(text="Error scanning networks")
except tk.TclError:
pass # Widget already destroyedEditor is loading...
Leave a Comment