Untitled

 avatar
unknown
plain_text
2 months ago
4.3 kB
3
Indexable
def main():
    ctk.deactivate_automatic_dpi_awareness()  # Prevent DPI scaling issues

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

    turntable = TurntableController()

    # Start calibration in separate thread
    def calibration_thread_func():
        turntable.calibrate()
        # Update any UI elements that should be enabled after calibration
        print("Turntable calibration complete")

    calibration_thread = threading.Thread(
        target=calibration_thread_func,
        daemon=True
    )
    calibration_thread.start()

    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)

    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)

    classification_prompt = ClassificationPrompt(
        main_frame,
        DARK_MODE,
        LANGUAGE,
        turntable=turntable  # Make sure this line is present
    )
    classification_prompt.place(relx=0.5, rely=0.8, anchor='center')

    try:
        root.mainloop()
    finally:
        observer.stop()
        observer.join()
        if 'classification_prompt' in locals():
            classification_prompt.cleanup()

if __name__ == "__main__":
    main()
Leave a Comment