Switch back to desktop-notifier

This commit is contained in:
AuroraWright
2024-02-12 22:54:31 +01:00
parent eec4484217
commit 10d7f69f78
3 changed files with 18 additions and 15 deletions

View File

@@ -18,7 +18,7 @@ from PIL import Image
from PIL import UnidentifiedImageError from PIL import UnidentifiedImageError
from loguru import logger from loguru import logger
from pynput import keyboard from pynput import keyboard
from notifypy import Notify from desktop_notifier import DesktopNotifier
import inspect import inspect
from owocr.ocr import * from owocr.ocr import *
@@ -168,9 +168,7 @@ def pause_handler(is_combo=True):
message = 'Paused!' message = 'Paused!'
if is_combo: if is_combo:
notification.title = message notifier.send_sync(title='owocr', message=message)
notification.message = ''
notification.send(block=False)
logger.info(message) logger.info(message)
paused = not paused paused = not paused
@@ -190,9 +188,7 @@ def engine_change_handler(user_input='s', is_combo=True):
if engine_index != old_engine_index: if engine_index != old_engine_index:
new_engine_name = engine_instances[engine_index].readable_name new_engine_name = engine_instances[engine_index].readable_name
if is_combo: if is_combo:
notification.title = f'Switched to {new_engine_name}' notifier.send_sync(title='owocr', message=f'Switched to {new_engine_name}')
notification.message = ''
notification.send(block=False)
engine_color = config.get_general('engine_color') engine_color = config.get_general('engine_color')
logger.opt(ansi=True).info(f'Switched to <{engine_color}>{new_engine_name}</{engine_color}>!') logger.opt(ansi=True).info(f'Switched to <{engine_color}>{new_engine_name}</{engine_color}>!')
@@ -289,6 +285,13 @@ def on_window_moved(pos):
sct_params['top'] = pos[1] sct_params['top'] = pos[1]
async def fix_windows_notifications():
try:
await notifier.request_authorisation()
except OSError:
pass
def are_images_identical(img1, img2): def are_images_identical(img1, img2):
if None in (img1, img2): if None in (img1, img2):
return img1 == img2 return img1 == img2
@@ -313,9 +316,7 @@ def process_and_write_results(img_or_path, write_to, notifications, enable_filte
text = post_process(text) text = post_process(text)
logger.opt(ansi=True).info(f'Text recognized in {t1 - t0:0.03f}s using <{engine_color}>{engine_instance.readable_name}</{engine_color}>: {text}') logger.opt(ansi=True).info(f'Text recognized in {t1 - t0:0.03f}s using <{engine_color}>{engine_instance.readable_name}</{engine_color}>: {text}')
if notifications: if notifications:
notification.title = 'Text recognized:' notifier.send_sync(title='owocr', message='Text recognized: ' + text)
notification.message = text
notification.send(block=False)
if write_to == 'websocket': if write_to == 'websocket':
websocket_server_thread.send_text(text) websocket_server_thread.send_text(text)
@@ -426,7 +427,7 @@ def run(read_from=None,
global paused global paused
global just_unpaused global just_unpaused
global first_pressed global first_pressed
global notification global notifier
terminated = False terminated = False
paused = pause_at_startup paused = pause_at_startup
just_unpaused = True just_unpaused = True
@@ -435,8 +436,7 @@ def run(read_from=None,
engine_color = config.get_general('engine_color') engine_color = config.get_general('engine_color')
delay_secs = config.get_general('delay_secs') delay_secs = config.get_general('delay_secs')
screen_capture_on_combo = False screen_capture_on_combo = False
notification = Notify() notifier = DesktopNotifier()
notification.application_name = 'owocr'
key_combos = {} key_combos = {}
if combo_pause != '': if combo_pause != '':
@@ -450,6 +450,9 @@ def run(read_from=None,
user_input_thread = threading.Thread(target=user_input_thread_run, daemon=True) user_input_thread = threading.Thread(target=user_input_thread_run, daemon=True)
user_input_thread.start() user_input_thread.start()
if sys.platform == 'win32':
asyncio.run(fix_windows_notifications())
if read_from == 'websocket' or write_to == 'websocket': if read_from == 'websocket' or write_to == 'websocket':
global websocket_server_thread global websocket_server_thread
websocket_server_thread = WebsocketServerThread(read_from == 'websocket') websocket_server_thread = WebsocketServerThread(read_from == 'websocket')

View File

@@ -6,7 +6,7 @@ Pillow>=10.0.0
pyperclipfix pyperclipfix
pynput pynput
websockets websockets
notify-py desktop-notifier,
mss mss
pywinctl pywinctl
pysbd pysbd

View File

@@ -27,7 +27,7 @@ setup(
"pyperclipfix", "pyperclipfix",
"pynput", "pynput",
"websockets", "websockets",
"notify-py", "desktop-notifier",
"mss", "mss",
"pywinctl", "pywinctl",
"pysbd", "pysbd",