Untitled

 avatar
unknown
plain_text
2 months ago
4.6 kB
2
Indexable
def main():
    ctk.deactivate_automatic_dpi_awareness()

    settings = load_settings()
    DARK_MODE = settings.get('dark_mode', False)
    LANGUAGE = settings.get('language', 'DE')
    SHOW_WIFI_STATUS = settings.get('show_wifi_status', True)

    reboot_button = setup_reboot_button()
    bin_config = BinConfiguration()
    observer = setup_file_monitoring(CircularProgress.update_all_instances)

    ctk.set_appearance_mode("dark" if DARK_MODE else "light")
    ctk.set_default_color_theme("dark-blue")

    root = ctk.CTk()
    root.title("SortiMate")
    root.LANGUAGE = LANGUAGE
    root.DARK_MODE = DARK_MODE
    root.overrideredirect(True)
    root.geometry("1024x600+0+0")
    root.focus_set()

    bg_color = '#1c1c1e' if DARK_MODE else '#f5f5f7'
    main_frame = ctk.CTkFrame(root, fg_color=bg_color)
    main_frame.pack(fill='both', expand=True)

    # Show initial interface
    sayings = load_sayings()
    current_language_sayings = sayings[LANGUAGE]
    initial_saying = random.choice(current_language_sayings)
    
    saying_label = create_saying_label(
        main_frame, 
        DARK_MODE, 
        check_wifi=True,
        show_wifi_status=SHOW_WIFI_STATUS
    )
    saying_label.configure(text=initial_saying)

    settings_menu = SettingsMenu(main_frame, DARK_MODE, LANGUAGE)

    # Create reset button
    try:
        is_light_bg = not DARK_MODE
        icon_suffix = "-b" if is_light_bg else "-w"
        reset_icon = ctk.CTkImage(
            light_image=Image.open(f"icons/reset{icon_suffix}.png"),
            dark_image=Image.open(f"icons/reset{icon_suffix}.png"),
            size=(30, 30)
        )
        reset_button = ctk.CTkButton(
            main_frame,
            image=reset_icon,
            text="",
            width=30,
            height=30,
            fg_color="transparent",
            hover_color='#2c2c2e' if DARK_MODE else '#e5e5e7',
            command=lambda: ResetFillLevelsScreen(root, DARK_MODE, LANGUAGE)
        )
        reset_button.place(relx=0.03, rely=0.05, anchor='center')
    except Exception as e:
        print(f"Error loading reset icon: {e}")
        reset_button = ctk.CTkButton(
            main_frame,
            text="?",
            width=30,
            height=30,
            fg_color="transparent",
            hover_color='#2c2c2e' if DARK_MODE else '#e5e5e7',
            command=lambda: ResetFillLevelsScreen(root, DARK_MODE, LANGUAGE)
        )
        reset_button.place(relx=0.03, rely=0.05, anchor='center')

    close_button = CloseButton(main_frame, command=root.destroy)
    close_button.place(relx=0.05, rely=0.95, anchor='center')

    circles_frame = ctk.CTkFrame(main_frame, fg_color=bg_color)
    circles_frame.place(relx=0.5, rely=0.5, anchor='center')

    padding_frame = ctk.CTkFrame(circles_frame, fg_color=bg_color)
    padding_frame.pack(padx=50)

    # Create circles for each bin from configuration
    for bin_config_item in bin_config.bins:
        container = ctk.CTkFrame(padding_frame, fg_color=bg_color)
        container.pack(side='left', padx=15)

        progress = CircularProgress(
            container,
            bin_id=bin_config_item['id'],
            size=220
        )
        progress.pack()
        progress.set_dark_mode(root.DARK_MODE)

    # Show calibrating message
    calibrating_label = ctk.CTkLabel(
        main_frame,
        text=TRANSLATIONS[LANGUAGE]['calibrating'],
        font=("Dongle", 42, "bold"),
        text_color='white' if DARK_MODE else 'black'
    )
    calibrating_label.place(relx=0.5, rely=0.8, anchor='center')

    classification_prompt = None

    def init_turntable():
        nonlocal classification_prompt
        # Initialize turntable
        turntable = TurntableController()
        
        # Remove calibrating label
        calibrating_label.destroy()
        
        # Create classification prompt
        classification_prompt = ClassificationPrompt(
            main_frame,
            DARK_MODE,
            LANGUAGE,
            turntable=turntable
        )
        classification_prompt.place(relx=0.5, rely=0.8, anchor='center')

    # Start turntable initialization in a separate thread
    threading.Thread(target=init_turntable, daemon=True).start()

    try:
        root.mainloop()
    finally:
        observer.stop()
        observer.join()
        if classification_prompt is not None:
            classification_prompt.cleanup()

if __name__ == "__main__":
    main()
Editor is loading...
Leave a Comment