Untitled
unknown
plain_text
5 months ago
3.9 kB
4
Indexable
def check_wifi_connection(): """Check if WiFi is connected""" try: result = subprocess.run( ["nmcli", "-t", "-f", "ACTIVE,SSID", "dev", "wifi"], capture_output=True, text=True ) return any(line.startswith("yes:") for line in result.stdout.split("\n")) except Exception: return False def create_saying_label(parent, dark_mode): # Create a main container with some extra vertical space container = ctk.CTkFrame( parent, fg_color='transparent', height=120 ) 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) # Bottom decorative elements - same layout as top 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) # First check WiFi status before setting any text current_language = parent.winfo_toplevel().LANGUAGE if not check_wifi_connection(): saying_label.configure( text=TRANSLATIONS[current_language].get('wifi_disconnected', 'No WiFi Connection'), text_color='#ff3b30' ) else: sayings = load_sayings() saying_label.configure( text=random.choice(sayings[current_language]), text_color='white' if dark_mode else 'black' ) def update_status(): if container.winfo_exists(): current_language = parent.winfo_toplevel().LANGUAGE if not check_wifi_connection(): saying_label.configure( text=TRANSLATIONS[current_language].get('wifi_disconnected', 'No WiFi Connection'), text_color='#ff3b30' ) else: sayings = load_sayings() saying_label.configure( text=random.choice(sayings[current_language]), text_color='white' if dark_mode else 'black' ) container.after(5000, update_status) # Start periodic updates container.after(5000, update_status) return saying_label
Editor is loading...
Leave a Comment