From 7042d5344ff93352441c5cebe35422462dc36883 Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Sat, 20 Jan 2024 19:50:55 +0100 Subject: [PATCH] Switch to notify-py due to issues with Windows --- owocr/run.py | 22 +++++++++++++--------- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/owocr/run.py b/owocr/run.py index 0cb3e80..eb3ee10 100644 --- a/owocr/run.py +++ b/owocr/run.py @@ -17,7 +17,7 @@ from PIL import Image from PIL import UnidentifiedImageError from loguru import logger from pynput import keyboard -from desktop_notifier import DesktopNotifier +from notifypy import Notify import inspect from owocr import * @@ -78,14 +78,18 @@ def are_images_identical(img1, img2): return (img1.shape == img2.shape) and (img1 == img2).all() -def process_and_write_results(engine_instance, engine_color, img_or_path, write_to, notifier): +def process_and_write_results(engine_instance, engine_color, img_or_path, write_to, notifications): t0 = time.time() text = engine_instance(img_or_path) t1 = time.time() logger.opt(ansi=True).info(f"Text recognized in {t1 - t0:0.03f}s using <{engine_color}>{engine_instance.readable_name}: {text}") - if notifier != None: - notifier.send_sync(title="owocr", message=text, timeout=5) + if notifications == True: + notification = Notify() + notification.application_name = 'owocr' + notification.title = 'Text recognized:' + notification.message = text + notification.send(block=False) if write_to == 'websocket': websocket_server_thread.send_text(text) @@ -185,7 +189,7 @@ def run(read_from='clipboard', engine_color = 'cyan' delay_secs = 0.5 websocket_port = 7331 - notifier = None + notifications = False config_file = os.path.join(os.path.expanduser('~'),'.config','owocr_config.ini') config = configparser.ConfigParser() @@ -220,7 +224,7 @@ def run(read_from='clipboard', try: if config['general']['notifications'].strip().lower() == 'true': - notifier = DesktopNotifier() + notifications = True except KeyError: pass @@ -347,7 +351,7 @@ def run(read_from='clipboard', else: if not paused and not tmp_paused: img = Image.open(io.BytesIO(item)) - process_and_write_results(engine_instances[engine_index], engine_color, img, write_to, notifier) + process_and_write_results(engine_instances[engine_index], engine_color, img, write_to, notifications) elif read_from == 'clipboard': if not paused and not tmp_paused: if mac_clipboard_polling: @@ -373,7 +377,7 @@ def run(read_from='clipboard', logger.warning('Error while reading from clipboard ({})'.format(error)) else: if not just_unpaused and (ignore_flag or pyperclip.paste() != '*ocr_ignore*') and isinstance(img, Image.Image) and not are_images_identical(img, old_img): - process_and_write_results(engine_instances[engine_index], engine_color, img, write_to, notifier) + process_and_write_results(engine_instances[engine_index], engine_color, img, write_to, notifications) if just_unpaused: just_unpaused = False @@ -393,7 +397,7 @@ def run(read_from='clipboard', except (UnidentifiedImageError, OSError) as e: logger.warning(f'Error while reading file {path}: {e}') else: - process_and_write_results(engine_instances[engine_index], engine_color, img, write_to, notifier) + process_and_write_results(engine_instances[engine_index], engine_color, img, write_to, notifications) img.close() if delete_images: Path.unlink(path) diff --git a/requirements.txt b/requirements.txt index c049f41..e59350b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,4 @@ pyperclip unidic_lite pynput websockets -desktop-notifier \ No newline at end of file +notify-py \ No newline at end of file diff --git a/setup.py b/setup.py index 39e140d..96ff6c4 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setup( "unidic_lite", "pynput", "websockets", - "desktop-notifier" + "notify-py" ], entry_points={ "console_scripts": [