Untitled
unknown
plain_text
a year ago
10 kB
4
Indexable
class WifiConfigurationScreen(ctk.CTkToplevel):
def __init__(self, parent, dark_mode: bool, language='EN'):
super().__init__(parent)
self._is_destroyed = False
self.bind("<Destroy>", self._on_destroy)
# Make it fullscreen and disable all close operations
self.overrideredirect(True)
self.geometry(f"{self.winfo_screenwidth()}x{self.winfo_screenheight()}+0+0")
self.protocol("WM_DELETE_WINDOW", lambda: None)
self.attributes('-topmost', True)
# Set colors based on dark mode
self.dark_mode = dark_mode
self.bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
self.text_color = 'white' if dark_mode else 'black'
self.button_color = '#2c2c2e' if dark_mode else '#e5e5e7'
self.button_hover_color = '#3a3a3c' if dark_mode else '#d1d1d6'
self.configure(fg_color=self.bg_color)
# Variables
self.networks = []
self.selected_network = StringVar()
self.password = StringVar()
self.show_password = ctk.BooleanVar(value=False)
self.keyboard_visible = False
self.current_connection = {
"SSID": TRANSLATIONS[language]['wifi_disconnected'],
"Signal Strength": "N/A",
"IP Address": "N/A"
}
self.status_message = StringVar(value=TRANSLATIONS[language]['diagnostic_running'])
self.language = language
# Load icons (same as before)
self.load_icons()
# Create main layout container with three rows
self.main_container = ctk.CTkFrame(self, fg_color=self.bg_color, corner_radius=0)
self.main_container.pack(fill="both", expand=True)
# Top section (20% height)
self.top_section = ctk.CTkFrame(self.main_container, fg_color=self.bg_color)
self.top_section.pack(fill="x", pady=(20, 10), padx=40)
# Middle section (60% height)
self.middle_section = ctk.CTkFrame(self.main_container, fg_color=self.bg_color)
self.middle_section.pack(fill="both", expand=True, pady=10, padx=40)
# Bottom section (20% height)
self.bottom_section = ctk.CTkFrame(self.main_container, fg_color=self.bg_color)
self.bottom_section.pack(fill="x", pady=(10, 20), padx=40)
# Create close button
self.close_button = ctk.CTkButton(
self,
text="×",
width=35,
height=20,
command=self.destroy,
fg_color='#ff3b30',
hover_color='#ff453a',
text_color='white',
font=("Dongle", 24, "bold"),
)
self.close_button.place(relx=0.995, rely=0.01, anchor="ne")
# Create UI Elements
self.create_widgets()
self.scan_wifi_networks()
self.update_current_connection()
# Bind click outside password entry to hide keyboard
self.bind('<Button-1>', self.check_hide_keyboard)
def create_widgets(self):
# Title and Status in top section
title_label = ctk.CTkLabel(
self.top_section,
text=TRANSLATIONS[self.language]['wifi_diagnostics'],
font=("Dongle", 42, "bold"),
text_color=self.text_color
)
title_label.pack(pady=(0, 5))
self.status_label = ctk.CTkLabel(
self.top_section,
textvariable=self.status_message,
font=("Dongle", 24),
text_color=self.text_color
)
self.status_label.pack(pady=(0, 5))
# Create two columns in middle section
left_column = ctk.CTkFrame(self.middle_section, fg_color="transparent")
left_column.pack(side="left", fill="both", expand=True, padx=(0, 10))
right_column = ctk.CTkFrame(self.middle_section, fg_color="transparent")
right_column.pack(side="left", fill="both", expand=True, padx=(10, 0))
# Network selection
network_label = ctk.CTkLabel(
left_column,
text=TRANSLATIONS[self.language]['current_network'],
font=("Dongle", 25),
text_color=self.text_color
)
network_label.pack(pady=(0, 5))
self.network_dropdown = ctk.CTkOptionMenu(
left_column,
variable=self.selected_network,
values=self.networks,
width=300,
height=35,
fg_color=self.button_color,
button_color=self.button_hover_color,
button_hover_color=self.button_hover_color,
text_color=self.text_color,
font=("Dongle", 20)
)
self.network_dropdown.pack(pady=(0, 15))
# Password entry
password_label = ctk.CTkLabel(
left_column,
text=TRANSLATIONS[self.language].get('password', 'Password'),
font=("Dongle", 25),
text_color=self.text_color
)
password_label.pack(pady=(0, 5))
password_container = ctk.CTkFrame(left_column, fg_color="transparent")
password_container.pack(pady=(0, 15))
self.password_entry = ctk.CTkEntry(
password_container,
textvariable=self.password,
show="*",
width=300,
height=35,
fg_color=self.button_color,
text_color=self.text_color,
border_color=self.button_hover_color,
font=("Dongle", 20)
)
self.password_entry.pack(side="left", padx=(0, 10))
self.toggle_password_btn = ctk.CTkButton(
password_container,
text="",
image=self.show_icon,
width=35,
height=35,
fg_color=self.button_color,
hover_color=self.button_hover_color,
command=self.toggle_password_visibility
)
self.toggle_password_btn.pack(side="left")
# Action buttons
button_container = ctk.CTkFrame(left_column, fg_color="transparent")
button_container.pack(pady=(0, 15))
ctk.CTkButton(
button_container,
text=TRANSLATIONS[self.language]['reconnect'],
command=self.start_connecting_to_wifi,
width=145,
height=35,
fg_color=self.button_color,
hover_color=self.button_hover_color,
text_color=self.text_color,
font=("Dongle", 20)
).pack(side="left", padx=(0, 10))
ctk.CTkButton(
button_container,
text=TRANSLATIONS[self.language].get('refresh', 'Refresh'),
command=self.scan_wifi_networks,
width=145,
height=35,
fg_color=self.button_color,
hover_color=self.button_hover_color,
text_color=self.text_color,
font=("Dongle", 20)
).pack(side="left")
# Connection info in right column
self.connection_frame = ctk.CTkFrame(
right_column,
fg_color=self.button_color,
corner_radius=15
)
self.connection_frame.pack(fill="x", pady=(0, 15))
connection_title = ctk.CTkLabel(
self.connection_frame,
text=TRANSLATIONS[self.language].get('connection_details', 'Connection Details'),
font=("Dongle", 28, "bold"),
text_color=self.text_color
)
connection_title.pack(pady=(10, 5))
self.ssid_label = ctk.CTkLabel(
self.connection_frame,
text=f"SSID: {TRANSLATIONS[self.language]['wifi_disconnected']}",
font=("Dongle", 24),
text_color=self.text_color
)
self.ssid_label.pack(pady=2)
self.signal_label = ctk.CTkLabel(
self.connection_frame,
text="",
image=self.signal_icons['signal-zero'],
font=("Dongle", 24),
text_color=self.text_color
)
self.signal_label.pack(pady=2)
self.ip_label = ctk.CTkLabel(
self.connection_frame,
text="IP Address: N/A",
font=("Dongle", 24),
text_color=self.text_color
)
self.ip_label.pack(pady=(2, 10))
# Keyboard in bottom section
self.keyboard_frame = ctk.CTkFrame(self.bottom_section, fg_color="transparent")
self.keyboard = TouchKeyboard(
self.keyboard_frame,
self.password_entry,
self.hide_keyboard,
dark_mode=self.dark_mode,
fg_color="transparent"
)
self.keyboard.pack(fill="both", expand=True)
self.password_entry.bind("<Button-1>", self.show_keyboard)
self.password_entry.bind("<FocusIn>", self.show_keyboard)
def load_icons(self):
# Load all signal icons
suffix = "-w" if self.dark_mode else "-b"
self.signal_icons = {}
for strength in ['zero', 'low', 'medium', 'high']:
try:
self.signal_icons[f'signal-{strength}'] = ctk.CTkImage(
light_image=Image.open(f"icons/signal-{strength}-b.png"),
dark_image=Image.open(f"icons/signal-{strength}-w.png"),
size=(20, 20)
)
except Exception as e:
print(f"Error loading signal-{strength} icon: {e}")
# Load other icons
self.show_icon = ctk.CTkImage(
light_image=Image.open("icons/eye-b.png"),
dark_image=Image.open("icons/eye-w.png"),
size=(20, 20)
)
self.hide_icon = ctk.CTkImage(
light_image=Image.open("icons/eye-off-b.png"),
dark_image=Image.open("icons/eye-off-w.png"),
size=(20, 20)
)Editor is loading...
Leave a Comment