Untitled
unknown
plain_text
a year ago
5.8 kB
14
Indexable
height=40,
fg_color="transparent",
hover_color=border_color,
command=self.close_screen
)
self.back_button.pack(side='left', padx=20)
# Title
self.title = ctk.CTkLabel(
self.header,
text=f"Connect to {self.network.ssid}",
font=("Dongle", 24, "bold"),
text_color=text_color
)
self.title.pack(side='left', padx=20)
# Main container
self.main_container = ctk.CTkFrame(self, fg_color=bg_color)
self.main_container.pack(fill='both', expand=True, padx=20, pady=20)
# Password entry
self.password_frame = ctk.CTkFrame(self.main_container, fg_color="transparent")
self.password_frame.pack(fill='x', pady=(0, 20))
self.password_entry = ctk.CTkEntry(
self.password_frame,
width=300,
height=40,
placeholder_text="Enter password",
show="•",
font=("Dongle", 16),
fg_color=border_color,
text_color=text_color
)
self.password_entry.pack(side='left', padx=(0, 10))
# Toggle password visibility button
try:
icon_suffix = "-w" if dark_mode else "-b"
eye_image = ctk.CTkImage(
light_image=Image.open(f"icons/eye{icon_suffix}.png"),
dark_image=Image.open(f"icons/eye{icon_suffix}.png"),
size=(20, 20)
)
self.toggle_password_button = ctk.CTkButton(
self.password_frame,
image=eye_image,
text="",
width=40,
height=40,
fg_color=border_color,
hover_color='#3a3a3c' if dark_mode else '#d1d1d6',
command=self.toggle_password_visibility
)
except Exception:
self.toggle_password_button = ctk.CTkButton(
self.password_frame,
text="👁",
width=40,
height=40,
fg_color=border_color,
hover_color='#3a3a3c' if dark_mode else '#d1d1d6',
command=self.toggle_password_visibility
)
self.toggle_password_button.pack(side='left', padx=5)
# Clear password button
try:
icon_suffix = "-w" if dark_mode else "-b"
clear_image = ctk.CTkImage(
light_image=Image.open(f"icons/x{icon_suffix}.png"),
dark_image=Image.open(f"icons/x{icon_suffix}.png"),
size=(20, 20)
)
self.clear_button = ctk.CTkButton(
self.password_frame,
image=clear_image,
text="",
width=40,
height=40,
fg_color=border_color,
hover_color='#3a3a3c' if dark_mode else '#d1d1d6',
command=self.clear_password
)
except Exception:
self.clear_button = ctk.CTkButton(
self.password_frame,
text="✕",
width=40,
height=40,
fg_color=border_color,
hover_color='#3a3a3c' if dark_mode else '#d1d1d6',
command=self.clear_password
)
self.clear_button.pack(side='left', padx=5)
# Connect button
self.connect_button = ctk.CTkButton(
self.main_container,
text="Connect",
width=200,
height=40,
font=("Dongle", 16),
fg_color="#34c759",
hover_color="#248a3d",
command=self.handle_password_submit
)
self.connect_button.pack(pady=(0, 20))
# Touch keyboard
self.keyboard = TouchKeyboard(self.main_container, self.password_entry, dark_mode)
self.keyboard.pack(fill='x', pady=(20, 0))
# Password visibility state
self.password_visible = False
def toggle_password_visibility(self):
self.password_visible = not self.password_visible
self.password_entry.configure(show="" if self.password_visible else "•")
def clear_password(self):
self.password_entry.delete(0, 'end')
def handle_password_submit(self):
password = self.password_entry.get()
if password:
self.connect_button.configure(state="disabled", text="Connecting...")
def connect():
success = WiFiNetwork.connect(self.network.ssid, password)
self.parent.after(0, lambda: self.handle_connection_result(success))
threading.Thread(target=connect).start()
def handle_connection_result(self, success: bool):
if success:
self.refresh_callback()
self.close_screen()
else:
self.connect_button.configure(
state="normal",
text="Connect",
fg_color="#ff3b30",
hover_color="#ff453a"
)
self.password_entry.configure(fg_color="#ff3b30")
self.parent.after(2000, lambda: self.reset_error_state())
def reset_error_state(self):
border_color = '#2c2c2e' if self.dark_mode else '#e5e5e7'
self.connect_button.configure(
fg_color="#34c759",
hover_color="#248a3d"
)
self.password_entry.configure(fg_color=border_color)
def close_screen(self):
self.destroy()Editor is loading...
Leave a Comment