Support new desktop-notifier
This commit is contained in:
20
owocr/run.py
20
owocr/run.py
@@ -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 desktop_notifier import DesktopNotifier
|
from desktop_notifier import DesktopNotifierSync
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
@@ -296,7 +296,7 @@ def pause_handler(is_combo=True):
|
|||||||
message = 'Paused!'
|
message = 'Paused!'
|
||||||
|
|
||||||
if is_combo:
|
if is_combo:
|
||||||
notifier.send_sync(title='owocr', message=message)
|
notifier.send(title='owocr', message=message)
|
||||||
logger.info(message)
|
logger.info(message)
|
||||||
paused = not paused
|
paused = not paused
|
||||||
|
|
||||||
@@ -316,7 +316,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:
|
||||||
notifier.send_sync(title='owocr', message=f'Switched to {new_engine_name}')
|
notifier.send(title='owocr', message=f'Switched to {new_engine_name}')
|
||||||
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}>!')
|
||||||
|
|
||||||
@@ -413,13 +413,6 @@ 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 normalize_macos_clipboard(img):
|
def normalize_macos_clipboard(img):
|
||||||
ns_data = NSData.dataWithBytes_length_(img, len(img))
|
ns_data = NSData.dataWithBytes_length_(img, len(img))
|
||||||
ns_image = NSImage.alloc().initWithData_(ns_data)
|
ns_image = NSImage.alloc().initWithData_(ns_data)
|
||||||
@@ -474,7 +467,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:
|
||||||
notifier.send_sync(title='owocr', message='Text recognized: ' + text)
|
notifier.send(title='owocr', message='Text recognized: ' + text)
|
||||||
|
|
||||||
if write_to == 'websocket':
|
if write_to == 'websocket':
|
||||||
websocket_server_thread.send_text(text)
|
websocket_server_thread.send_text(text)
|
||||||
@@ -591,7 +584,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
|
||||||
notifier = DesktopNotifier()
|
notifier = DesktopNotifierSync()
|
||||||
key_combos = {}
|
key_combos = {}
|
||||||
|
|
||||||
if combo_pause != '':
|
if combo_pause != '':
|
||||||
@@ -605,9 +598,6 @@ 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')
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -5,7 +5,7 @@ long_description = (Path(__file__).parent / "README.md").read_text('utf-8')
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="owocr",
|
name="owocr",
|
||||||
version='1.7.4',
|
version='1.7.5',
|
||||||
description="Japanese OCR",
|
description="Japanese OCR",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
@@ -27,7 +27,7 @@ setup(
|
|||||||
"pyperclipfix",
|
"pyperclipfix",
|
||||||
"pynput",
|
"pynput",
|
||||||
"websockets",
|
"websockets",
|
||||||
"desktop-notifier",
|
"desktop-notifier>=5.0.0",
|
||||||
"mss",
|
"mss",
|
||||||
"pysbd",
|
"pysbd",
|
||||||
"langid",
|
"langid",
|
||||||
|
|||||||
Reference in New Issue
Block a user