You are a Python programmer tasked with refactoring code. You are proficient in…
- User
SYSTEM: You are a Python programmer tasked with refactoring code. You are proficient in Python 3.12 and use modern features where appropriate. Your code is clear, easy to read, and free of unnecessary verbosity. For documentation, you use single-line docstrings and occasional comments. Often code you get is only part of a larger program. USER: The default folders are important for a button in the gui. Code: # --- Configuration ---
@dataclass class SharedState: processed_files_lock: threading.Lock = field(default_factory=threading.Lock) processed_files_count: int = 0 total_files_count: int = 0 log_message_queue: Queue = field(default_factory=Queue) tab_messages: Dict[str, List[str]] = field(default_factory=lambda: { "Log": [], "Black": [], "White": [], "Color": [] }) stop_event: threading.Event = field(default_factory=threading.Event)
class Config: """Configuration class for the image processing application.""" SCRIPT_DIR = Path(file).parent.resolve() INPUT_FOLDER = Path(os.getenv('INPUT_FOLDER', SCRIPT_DIR / '1. Input')) OUTPUT_FOLDER = Path(os.getenv('OUTPUT_FOLDER', SCRIPT_DIR / '2. Output')) DEFAULT_INPUT_FOLDER = INPUT_FOLDER DEFAULT_OUTPUT_FOLDER = OUTPUT_FOLDER
code# Executables IMAGEMAGICK: Path = Path(os.getenv('IMAGEMAGICK', 'D:/Bilder/Python/0. Code/Requirements/ImageMagick.exe')) FFMPEG: Path = Path(os.getenv('FFMPEG', 'D:/Bilder/Python/0. Code/Requirements/ffmpeg.exe')) # File Extensions AUDIO_EXTENSIONS: Set[str] = {'.mka', '.mpga', '.mp3', '.aac', '.flac', '.opus'} IMAGE_EXTENSIONS: Set[str] = {'.png', '.jpg', '.jpeg', '.webp'} VIDEO_EXTENSIONS: Set[str] = {'.mkv', '.mp4'} # Formatting and Display Constants SEPARATOR_LENGTH: int = 310 PADDING_LENGTH: int = 82 PROGRESS_BAR_LENGTH: int = 100 # Resize Options Defaults DEFAULT_RESIZE_MODE: str = "Shortest Side" DEFAULT_RESIZE_WIDTH: int = 0 DEFAULT_RESIZE_HEIGHT: int = 0 DEFAULT_RESIZE_SIDE: int = 1600 DEFAULT_RESIZE_FORMAT: str = "png" # Color Detection Thresholds COLORDIFF_THRESHOLD: int = 5 FRACTION_COLORED_PIXELS_THRESHOLD: float = 0.03 @classmethod def setup(cls) -> None: """Set up the output folder and configure logging.""" cls.OUTPUT_FOLDER.mkdir(parents=True, exist_ok=True) logging.getLogger("PIL").setLevel(logging.WARNING) @classmethod def initialize(cls) -> SharedState: """Initialize configuration and return shared application state.""" cls.setup() return SharedState() - Assistant