Untitled

 avatar
unknown
plain_text
5 months ago
8.4 kB
3
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 for password visibility toggle with dark/light mode variants
        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)
        )

        # Create main container without borders
        self.main_container = ctk.CTkFrame(self, fg_color=self.bg_color, border_width=0)
        self.main_container.pack(fill="both", expand=True)
        
        # Create close button with updated styling
        self.close_button = ctk.CTkButton(
            self,
            text="×",
            width=30,
            height=25,
            command=self.destroy,
            fg_color='#ff3b30',
            hover_color='#ff453a',
            text_color='white',
            font=("Arial", 24, "bold")
        )
        self.close_button.place(relx=0.98, rely=0.02, anchor="ne")
        self.close_button.lift()
        
        # 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):
        # Top section
        self.top_frame = ctk.CTkFrame(self.main_container, fg_color="transparent")
        self.top_frame.pack(fill="x", padx=20, pady=(40, 0))

        # Title and Status with updated styling
        title_label = ctk.CTkLabel(
            self.top_frame, 
            text=TRANSLATIONS[self.language]['wifi_diagnostics'],
            font=("Arial", 28, "bold"),
            text_color=self.text_color
        )
        title_label.pack(pady=(5, 0))

        self.status_label = ctk.CTkLabel(
            self.top_frame,
            textvariable=self.status_message,
            font=("Arial", 14),
            text_color=self.text_color
        )
        self.status_label.pack(pady=(0, 5))

        # Content section
        self.content_frame = ctk.CTkFrame(self.main_container, fg_color="transparent")
        self.content_frame.pack(fill="both", expand=True, padx=20, pady=(0, 0))

        # Network selection with updated styling
        network_label = ctk.CTkLabel(
            self.content_frame,
            text=TRANSLATIONS[self.language]['current_network'],
            font=("Arial", 14),
            text_color=self.text_color
        )
        network_label.pack(pady=(10, 0))

        self.network_dropdown = ctk.CTkOptionMenu(
            self.content_frame,
            variable=self.selected_network,
            values=self.networks,
            width=250,
            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
        )
        self.network_dropdown.pack(pady=(0, 5))

        # Password entry with updated styling
        password_label = ctk.CTkLabel(
            self.content_frame,
            text=TRANSLATIONS[self.language].get('password', 'Password'),  # Add translation
            font=("Arial", 14),
            text_color=self.text_color
        )
        password_label.pack(pady=(5, 0))

        password_container = ctk.CTkFrame(self.content_frame, fg_color="transparent")
        password_container.pack(pady=(0, 5))

        self.password_entry = ctk.CTkEntry(
            password_container,
            textvariable=self.password,
            show="*",
            width=250,
            height=35,
            fg_color=self.button_color,
            text_color=self.text_color,
            border_color=self.button_hover_color
        )
        self.password_entry.pack(side="left", padx=(0, 5))

        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")

        self.password_entry.bind("<Button-1>", self.show_keyboard)
        self.password_entry.bind("<FocusIn>", self.show_keyboard)

        # Action buttons with updated styling
        button_frame = ctk.CTkFrame(self.content_frame, fg_color="transparent")
        button_frame.pack(pady=(5, 10))

        ctk.CTkButton(
            button_frame,
            text=TRANSLATIONS[self.language]['reconnect'],
            command=self.start_connecting_to_wifi,
            width=100,
            height=35,
            fg_color=self.button_color,
            hover_color=self.button_hover_color,
            text_color=self.text_color
        ).grid(row=0, column=0, padx=5)

        ctk.CTkButton(
            button_frame,
            text=TRANSLATIONS[self.language].get('refresh', 'Refresh'),  # Add translation
            command=self.scan_wifi_networks,
            width=100,
            height=35,
            fg_color=self.button_color,
            hover_color=self.button_hover_color,
            text_color=self.text_color
        ).grid(row=0, column=1, padx=5)

        # Connection info frame with updated styling
        self.connection_frame = ctk.CTkFrame(
            self.content_frame,
            fg_color=self.button_color
        )
        self.connection_frame.pack(fill="x", pady=(0, 10))

        self.ssid_label = ctk.CTkLabel(
            self.connection_frame,
            text=f"SSID: {TRANSLATIONS[self.language]['wifi_disconnected']}",
            font=("Arial", 12),
            text_color=self.text_color
        )
        self.ssid_label.pack(pady=1)

        self.signal_label = ctk.CTkLabel(
            self.connection_frame,
            text="Signal Strength: N/A",
            font=("Arial", 12),
            text_color=self.text_color
        )
        self.signal_label.pack(pady=1)

        self.ip_label = ctk.CTkLabel(
            self.connection_frame,
            text="IP Address: N/A",
            font=("Arial", 12),
            text_color=self.text_color
        )
        self.ip_label.pack(pady=1)

        # Keyboard container
        self.keyboard_frame = ctk.CTkFrame(self.main_container, fg_color="transparent")
        self.keyboard = TouchKeyboard(
            self.keyboard_frame,
            self.password_entry,
            self.hide_keyboard,
            fg_color="transparent",
            dark_mode=self.dark_mode
        )
        self.keyboard.pack(pady=(0, 10))
Editor is loading...
Leave a Comment