From 37bdfaf9952ed6cb9f1b50625577b954853a6941 Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Sun, 6 Jul 2025 04:27:57 +0200 Subject: [PATCH] Make screen capture combo ignore paused status, make screen capture in general not affect the autopause timer --- README.md | 2 +- owocr/config.py | 2 +- owocr/run.py | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 784d9be..91f0caf 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Additionally: - You can switch between OCR providers pressing their corresponding keyboard key inside the terminal window (refer to the list of keys in the providers list below) - You can start the script paused with the `-p` option or with a specific provider with the `-e` option (refer to `owocr -h` for the list) - You can specify keyboard combos in the config file to pause/unpause and switch the OCR provider from anywhere (refer to the config file or `owocr -h`) -- You can auto pause the script after a successful text recognition with the `-a=seconds` option if you're not using screen capture with automatic screenshots. 0 (the default) disables it. +- You can auto pause the script after a successful text recognition with the `-a=seconds` option if you're not using screen capture. 0 (the default) disables it. - You can enable notifications in the config file or with `-n` to show the text with a native OS notification if you're not using screen capture with automatic screenshots. **Important for macOS users:** if you use Python from brew, you need to enter this command in your terminal before the first notification: `codesign -f -s - $(brew --cellar python)/3.*/Frameworks/Python.framework` (works on Ventura/Sonoma). Older macOS versions might require Python to be installed from the [official website](https://www.python.org/downloads/). Nothing can be done about this unfortunately. - Optionally, you can speed up the online providers by installing fpng-py: `pip install owocr[faster-png]` (requires setting up a developer environment on most operating systems/Python versions) - Optionally, you can improve filtering of non-Japanese text for screen capture by installing transformers and sentencepiece: `pip install owocr[accurate-filtering]` diff --git a/owocr/config.py b/owocr/config.py index 34145b7..018e05f 100644 --- a/owocr/config.py +++ b/owocr/config.py @@ -35,7 +35,7 @@ parser.add_argument('-d', '--delete_images', action='store_true', default=argpar parser.add_argument('-n', '--notifications', action='store_true', default=argparse.SUPPRESS, help='Show an operating system notification with the detected text. Will be ignored when reading with screen capture, unless screen_capture_combo is set.') parser.add_argument('-a', '--auto_pause', type=float, default=argparse.SUPPRESS, - help='Automatically pause the program after the specified amount of seconds since the last successful text recognition. Will be ignored when reading with screen capture, unless screen_capture_combo is set. 0 to disable.') + help='Automatically pause the program after the specified amount of seconds since the last successful text recognition. Will be ignored when reading with screen capture. 0 to disable.') parser.add_argument('-cp', '--combo_pause', type=str, default=argparse.SUPPRESS, help='Combo to wait on for pausing the program. As an example: "++p". The list of keys can be found here: https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Key') parser.add_argument('-cs', '--combo_engine_switch', type=str, default=argparse.SUPPRESS, diff --git a/owocr/run.py b/owocr/run.py index b92db0c..39f4dad 100644 --- a/owocr/run.py +++ b/owocr/run.py @@ -772,12 +772,11 @@ def on_window_closed(alive): def on_screenshot_combo(): - if not paused: - screenshot_event.set() + screenshot_event.set() def process_and_write_results(img_or_path, last_result, filtering, notify): - if auto_pause_handler: + if auto_pause_handler and not filtering: auto_pause_handler.stop() engine_instance = engine_instances[engine_index] @@ -804,7 +803,7 @@ def process_and_write_results(img_or_path, last_result, filtering, notify): with Path(write_to).open('a', encoding='utf-8') as f: f.write(text + '\n') - if auto_pause_handler and not paused: + if auto_pause_handler and not paused and not filtering: auto_pause_handler.start() else: logger.opt(ansi=True).info(f'<{engine_color}>{engine_instance.readable_name} reported an error after {end_time - start_time:0.03f}s: {text}')