diff --git a/modules/ui.py b/modules/ui.py index 3a1d56b..0fc8a0f 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -7,6 +7,7 @@ from cv2_enumerate_cameras import enumerate_cameras # Add this import from PIL import Image, ImageOps import time import json + import modules.globals import modules.metadata from modules.face_analyser import ( @@ -25,11 +26,6 @@ from modules.utilities import ( resolve_relative_path, has_image_extension, ) -from modules.video_capture import VideoCapturer -import platform - -if platform.system() == "Windows": - from pygrabber.dshow_graph import FilterGraph ROOT = None POPUP = None @@ -100,7 +96,7 @@ def save_switch_states(): "fp_ui": modules.globals.fp_ui, "show_fps": modules.globals.show_fps, "mouth_mask": modules.globals.mouth_mask, - "show_mouth_mask_box": modules.globals.show_mouth_mask_box, + "show_mouth_mask_box": modules.globals.show_mouth_mask_box } with open("switch_states.json", "w") as f: json.dump(switch_states, f) @@ -122,9 +118,7 @@ def load_switch_states(): modules.globals.fp_ui = switch_states.get("fp_ui", {"face_enhancer": False}) modules.globals.show_fps = switch_states.get("show_fps", False) modules.globals.mouth_mask = switch_states.get("mouth_mask", False) - modules.globals.show_mouth_mask_box = switch_states.get( - "show_mouth_mask_box", False - ) + modules.globals.show_mouth_mask_box = switch_states.get("show_mouth_mask_box", False) except FileNotFoundError: # If the file doesn't exist, use default values pass @@ -321,22 +315,18 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C camera_label.place(relx=0.1, rely=0.86, relwidth=0.2, relheight=0.05) available_cameras = get_available_cameras() - camera_indices, camera_names = available_cameras - - if not camera_names or camera_names[0] == "No cameras found": - camera_variable = ctk.StringVar(value="No cameras found") - camera_optionmenu = ctk.CTkOptionMenu( - root, - variable=camera_variable, - values=["No cameras found"], - state="disabled", + # Convert camera indices to strings for CTkOptionMenu + available_camera_indices, available_camera_strings = available_cameras + camera_variable = ctk.StringVar( + value=( + available_camera_strings[0] + if available_camera_strings + else "No cameras found" ) - else: - camera_variable = ctk.StringVar(value=camera_names[0]) - camera_optionmenu = ctk.CTkOptionMenu( - root, variable=camera_variable, values=camera_names - ) - + ) + camera_optionmenu = ctk.CTkOptionMenu( + root, variable=camera_variable, values=available_camera_strings + ) camera_optionmenu.place(relx=0.35, rely=0.86, relwidth=0.25, relheight=0.05) live_button = ctk.CTkButton( @@ -345,16 +335,9 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C cursor="hand2", command=lambda: webcam_preview( root, - ( - camera_indices[camera_names.index(camera_variable.get())] - if camera_names and camera_names[0] != "No cameras found" - else None - ), - ), - state=( - "normal" - if camera_names and camera_names[0] != "No cameras found" - else "disabled" + available_camera_indices[ + available_camera_strings.index(camera_variable.get()) + ], ), ) live_button.place(relx=0.65, rely=0.86, relwidth=0.2, relheight=0.05) @@ -371,7 +354,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C text_color=ctk.ThemeManager.theme.get("URL").get("text_color") ) donate_label.bind( - "