From d693e7563aaa8dc7f3044007ac45980a4e825340 Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Sun, 11 Feb 2024 19:47:06 -0500 Subject: [PATCH] Use CF methods for now --- owocr/ocr.py | 7 ++++--- owocr/run.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/owocr/ocr.py b/owocr/ocr.py index 5db54b5..99c9f7b 100644 --- a/owocr/ocr.py +++ b/owocr/ocr.py @@ -23,7 +23,7 @@ try: import Vision import objc from AppKit import NSData, NSImage, NSBundle - from PyObjCTools.AppHelper import runConsoleEventLoop, stopEventLoop + from CoreFoundation import CFRunLoopRun, CFRunLoopStop, CFRunLoopGetCurrent except ImportError: pass @@ -349,7 +349,8 @@ class AppleLiveText: req.setLocales_(['ja','en']) self.result = None self.analyzer.processRequest_progressHandler_completionHandler_(req, lambda progress: None, self._process) - runConsoleEventLoop() + + CFRunLoopRun() if not self.result: return (False, 'Unknown error!') @@ -362,7 +363,7 @@ class AppleLiveText: for line in lines: res += line.string() + '\n' self.result = res - stopEventLoop() + CFRunLoopStop(CFRunLoopGetCurrent()) def _preprocess(self, img): image_bytes = pil_image_to_bytes(img, 'tiff') diff --git a/owocr/run.py b/owocr/run.py index e8d896a..9827d5b 100644 --- a/owocr/run.py +++ b/owocr/run.py @@ -404,7 +404,7 @@ def run(read_from=None, for config_engine in config.get_general('engines').split(','): config_engines.append(config_engine.strip().lower()) - for _,engine_class in sorted(inspect.getmembers(sys.modules[__name__], lambda x: hasattr(x, '__module__') and __package__ + '.ocr' in x.__module__ and inspect.isclass(x))): + for _,engine_class in sorted(inspect.getmembers(sys.modules[__name__], lambda x: hasattr(x, '__module__') and x.__module__ and __package__ + '.ocr' in x.__module__ and inspect.isclass(x))): if len(config_engines) == 0 or engine_class.name in config_engines: if config.get_engine(engine_class.name) == None: engine_instance = engine_class()