Untitled

 avatar
unknown
plain_text
5 months ago
3.6 kB
4
Indexable
def create_saying_label(parent, dark_mode):
    # Create a main container with some extra vertical space
    container = ctk.CTkFrame(
        parent,
        fg_color='transparent',
        height=160  # Increased height to accommodate both labels
    )
    container.place(relx=0.5, rely=0.15, anchor='center')
    
    # Create decorative elements container for top elements
    top_decorative = ctk.CTkFrame(
        container,
        fg_color='transparent'
    )
    top_decorative.pack(pady=(0, 10))
    
    line_color = '#2c2c2e' if dark_mode else '#e5e5e7'
    
    # Top decorative elements
    left_line = ctk.CTkFrame(
        top_decorative,
        width=40,
        height=2,
        fg_color=line_color
    )
    left_line.pack(side='left', padx=10)
    
    dot = ctk.CTkFrame(
        top_decorative,
        width=4,
        height=4,
        corner_radius=2,
        fg_color=line_color
    )
    dot.pack(side='left')
    
    right_line = ctk.CTkFrame(
        top_decorative,
        width=40,
        height=2,
        fg_color=line_color
    )
    right_line.pack(side='left', padx=10)
    
    # Create the main saying label
    saying_label = ctk.CTkLabel(
        container,
        text="",
        font=("Dongle", 42, "bold"),
        text_color='white' if dark_mode else 'black',
        pady=15
    )
    saying_label.pack(expand=True)
    
    # Create the WiFi status label
    wifi_label = ctk.CTkLabel(
        container,
        text="",
        font=("Dongle", 24, "bold"),
        text_color='#ff3b30',  # Always red for warning
        pady=5
    )
    wifi_label.pack(expand=True)
    
    # Bottom decorative elements
    bottom_decorative = ctk.CTkFrame(
        container,
        fg_color='transparent'
    )
    bottom_decorative.pack(pady=(5, 0))
    
    # Bottom elements with same dimensions as top
    left_line = ctk.CTkFrame(
        bottom_decorative,
        width=120,
        height=2,
        fg_color=line_color
    )
    left_line.pack(side='left', padx=10)
    
    dot = ctk.CTkFrame(
        bottom_decorative,
        width=4,
        height=4,
        corner_radius=2,
        fg_color=line_color
    )
    dot.pack(side='left')
    
    right_line = ctk.CTkFrame(
        bottom_decorative,
        width=120,
        height=2,
        fg_color=line_color
    )
    right_line.pack(side='left', padx=10)

    def check_wifi_status():
        try:
            result = subprocess.run(
                ["nmcli", "-t", "-f", "ACTIVE,SSID", "dev", "wifi"],
                capture_output=True, text=True
            )
            is_connected = any(line.startswith("yes:") for line in result.stdout.split("\n"))
            
            if container.winfo_exists():
                if not is_connected:
                    wifi_label.configure(
                        text=TRANSLATIONS[parent.winfo_toplevel().LANGUAGE].get('wifi_disconnected', 'No WiFi Connection')
                    )
                else:
                    wifi_label.configure(text="")
                
                container.after(5000, check_wifi_status)
        except Exception:
            if container.winfo_exists():
                wifi_label.configure(
                    text=TRANSLATIONS[parent.winfo_toplevel().LANGUAGE].get('wifi_disconnected', 'No WiFi Connection')
                )
                container.after(5000, check_wifi_status)

    # Start checking WiFi status
    check_wifi_status()
    
    return saying_label
Editor is loading...
Leave a Comment