Untitled

 avatar
unknown
plain_text
5 months ago
8.9 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 initialization remains the same...
        [previous variable initialization code remains unchanged]

        # Create main container with reduced top padding
        self.main_container = ctk.CTkFrame(self, fg_color=self.bg_color, corner_radius=0)
        self.main_container.pack(fill="both", expand=True, padx=40, pady=(20, 40))
        
        # Create close button
        self.close_button = ctk.CTkButton(
            self,
            text="×",
            width=40,
            height=40,
            command=self.destroy,
            fg_color='#ff3b30',
            hover_color='#ff453a',
            text_color='white',
            font=("Dongle", 24, "bold"),
            corner_radius=20
        )
        self.close_button.place(relx=0.97, rely=0.02, anchor="ne")  # Moved slightly up
        
        # Create UI Elements
        self.create_widgets()
        self.scan_wifi_networks()
        self.update_current_connection()
        self.bind('<Button-1>', self.check_hide_keyboard)

    def create_widgets(self):
        # Title and Status with reduced padding
        title_label = ctk.CTkLabel(
            self.main_container, 
            text=TRANSLATIONS[self.language]['wifi_diagnostics'],
            font=("Dongle", 42, "bold"),
            text_color=self.text_color
        )
        title_label.pack(pady=(10, 0))  # Reduced top padding

        self.status_label = ctk.CTkLabel(
            self.main_container,
            textvariable=self.status_message,
            font=("Dongle", 24),
            text_color=self.text_color
        )
        self.status_label.pack(pady=(0, 15))  # Reduced bottom padding

        # Content container moved up
        content_container = ctk.CTkFrame(self.main_container, fg_color="transparent")
        content_container.pack(fill="x", padx=40, expand=False)  # Changed expand to False

        # Left side - Network selection and password
        left_frame = ctk.CTkFrame(content_container, fg_color="transparent")
        left_frame.pack(side="left", fill="both", expand=True, padx=(0, 20))

        # Network selection with reduced padding
        network_label = ctk.CTkLabel(
            left_frame,
            text=TRANSLATIONS[self.language]['current_network'],
            font=("Dongle", 24),
            text_color=self.text_color
        )
        network_label.pack(pady=(0, 5))

        self.network_dropdown = ctk.CTkOptionMenu(
            left_frame,
            variable=self.selected_network,
            values=self.networks,
            width=300,
            height=45,
            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))  # Reduced padding

        # Password entry with reduced padding
        password_label = ctk.CTkLabel(
            left_frame,
            text=TRANSLATIONS[self.language].get('password', 'Password'),
            font=("Dongle", 24),
            text_color=self.text_color
        )
        password_label.pack(pady=(0, 5))

        password_container = ctk.CTkFrame(left_frame, fg_color="transparent")
        password_container.pack(pady=(0, 15))  # Reduced padding

        self.password_entry = ctk.CTkEntry(
            password_container,
            textvariable=self.password,
            show="*",
            width=300,
            height=45,
            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=45,
            height=45,
            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 with reduced padding
        button_container = ctk.CTkFrame(left_frame, fg_color="transparent")
        button_container.pack(pady=(0, 15))  # Reduced padding

        ctk.CTkButton(
            button_container,
            text=TRANSLATIONS[self.language]['reconnect'],
            command=self.start_connecting_to_wifi,
            width=145,
            height=45,
            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=45,
            fg_color=self.button_color,
            hover_color=self.button_hover_color,
            text_color=self.text_color,
            font=("Dongle", 20)
        ).pack(side="left")

        # Right side - Connection info with reduced height
        right_frame = ctk.CTkFrame(content_container, fg_color="transparent")
        right_frame.pack(side="left", fill="both", expand=True, padx=(20, 0))

        # Connection info frame with reduced padding
        self.connection_frame = ctk.CTkFrame(
            right_frame,
            fg_color=self.button_color,
            corner_radius=15
        )
        self.connection_frame.pack(fill="x")

        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))  # Reduced padding

        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)  # Reduced padding

        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)  # Reduced padding

        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))  # Reduced padding

        # 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,
            dark_mode=self.dark_mode,
            fg_color="transparent"
        )
        self.keyboard.pack()

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

    def show_keyboard(self, event=None):
        if not self.keyboard_visible:
            # Position the keyboard at the bottom of the screen
            self.keyboard_frame.pack(side="bottom", fill="x", pady=(0, 10))
            self.keyboard_visible = True
        self.password_entry.focus_set()

    def hide_keyboard(self):
        if self.keyboard_visible:
            self.keyboard_frame.pack_forget()
            self.keyboard_visible = False
Editor is loading...
Leave a Comment