From 39ae86a00541edd9516a8d732043ee999f9a64fd Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Sat, 18 Oct 2025 10:20:38 +0200 Subject: [PATCH] New version --- owocr/config.py | 2 +- owocr/run.py | 38 +++++++++++++++++++++----------------- owocr_config.ini | 2 +- pyproject.toml | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/owocr/config.py b/owocr/config.py index 35c876c..97342b5 100644 --- a/owocr/config.py +++ b/owocr/config.py @@ -102,7 +102,7 @@ class Config: 'furigana_filter': True, 'screen_capture_combo': '', 'coordinate_selector_combo': '', - 'screen_capture_old_macos_api': False, + 'screen_capture_old_macos_api': True, 'language': 'ja', 'output_format': 'text', 'verbosity': -2, diff --git a/owocr/run.py b/owocr/run.py index ecc4d4c..55e9848 100644 --- a/owocr/run.py +++ b/owocr/run.py @@ -1000,12 +1000,15 @@ class ScreenshotThread(threading.Thread): return with objc.autorelease_pool(): - width = CGImageGetWidth(image) - height = CGImageGetHeight(image) - raw_data = CGDataProviderCopyData(CGImageGetDataProvider(image)) - bpr = CGImageGetBytesPerRow(image) - img = Image.frombuffer('RGBA', (width, height), bytes(raw_data), 'raw', 'BGRA', bpr, 1) - self.screencapturekit_queue.put(img) + try: + width = CGImageGetWidth(image) + height = CGImageGetHeight(image) + raw_data = CGDataProviderCopyData(CGImageGetDataProvider(image)) + bpr = CGImageGetBytesPerRow(image) + img = Image.frombuffer('RGBA', (width, height), bytes(raw_data), 'raw', 'BGRA', bpr, 1) + self.screencapturekit_queue.put(img) + except: + self.screencapturekit_queue.put(None) window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionIncludingWindow, window_id) if not window_list or len(window_list) == 0: @@ -1092,12 +1095,15 @@ class ScreenshotThread(threading.Thread): if sys.platform == 'darwin': with objc.autorelease_pool(): if self.old_macos_screenshot_api: - cg_image = CGWindowListCreateImageFromArray(CGRectNull, [self.window_id], kCGWindowImageBoundsIgnoreFraming | kCGWindowImageNominalResolution) - width = CGImageGetWidth(cg_image) - height = CGImageGetHeight(cg_image) - raw_data = CGDataProviderCopyData(CGImageGetDataProvider(cg_image)) - bpr = CGImageGetBytesPerRow(cg_image) - img = Image.frombuffer('RGBA', (width, height), bytes(raw_data), 'raw', 'BGRA', bpr, 1) + try: + cg_image = CGWindowListCreateImageFromArray(CGRectNull, [self.window_id], kCGWindowImageBoundsIgnoreFraming | kCGWindowImageNominalResolution) + width = CGImageGetWidth(cg_image) + height = CGImageGetHeight(cg_image) + raw_data = CGDataProviderCopyData(CGImageGetDataProvider(cg_image)) + bpr = CGImageGetBytesPerRow(cg_image) + img = Image.frombuffer('RGBA', (width, height), bytes(raw_data), 'raw', 'BGRA', bpr, 1) + except: + img = None else: img = self.capture_macos_window_screenshot(self.window_id) if not img: @@ -1241,6 +1247,8 @@ class ScreenshotThread(threading.Thread): self.write_result(img, is_combo) if img == False: + logger.info('The window was closed or an error occurred.') + terminate_handler() break if self.screencapture_mode == 2: @@ -1795,11 +1803,7 @@ def run(): skip_waiting = True pass - if img == False: - logger.info('The window was closed or an error occurred, terminated!') - terminated.set() - break - elif img: + if img: output_result(img, filter_text, auto_pause, notify) if isinstance(img, Path) and delete_images: Path.unlink(img) diff --git a/owocr_config.ini b/owocr_config.ini index 54ce33e..cd77583 100644 --- a/owocr_config.ini +++ b/owocr_config.ini @@ -103,7 +103,7 @@ ;https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Key ;coordinate_selector_combo = -;screen_capture_old_macos_api = False +;screen_capture_old_macos_api = True ;Two letter language code for filtering screencapture OCR results. Ex. "ja" ;for Japanese, "zh" for Chinese, "ko" for Korean, "ar" for Arabic, "ru" for diff --git a/pyproject.toml b/pyproject.toml index 1a339cd..ac1f8f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "owocr" -version = "1.18.1" +version = "1.18.2" description = "Japanese OCR" readme = "README.md" requires-python = ">=3.11"