From 668bbb8ea68ed6edffa3299c9b09d7c52d27ca53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:53:33 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/myutils/ocrutil.py | 2 +- LunaTranslator/LunaTranslator/textsource/ocrtext.py | 11 +++-------- .../LunaTranslator/textsource/textsourcebase.py | 1 + 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/LunaTranslator/LunaTranslator/myutils/ocrutil.py b/LunaTranslator/LunaTranslator/myutils/ocrutil.py index 775f134b..488e1098 100644 --- a/LunaTranslator/LunaTranslator/myutils/ocrutil.py +++ b/LunaTranslator/LunaTranslator/myutils/ocrutil.py @@ -87,7 +87,7 @@ _initlock = threading.Lock() def ocr_end(): - global _ocrengine, _nowuseocr + global _ocrengine, _nowuseocr, _nowuseocrx with _initlock: _nowuseocr = None _nowuseocrx = None diff --git a/LunaTranslator/LunaTranslator/textsource/ocrtext.py b/LunaTranslator/LunaTranslator/textsource/ocrtext.py index 0ba4efaa..f03e516e 100644 --- a/LunaTranslator/LunaTranslator/textsource/ocrtext.py +++ b/LunaTranslator/LunaTranslator/textsource/ocrtext.py @@ -1,11 +1,10 @@ -import time, os +import time, os, threading from myutils.config import globalconfig import winsharedutils, windows from gui.rangeselect import rangeadjust -from myutils.ocrutil import imageCut, ocr_run, ocr_end, ocr_init +from myutils.ocrutil import imageCut, ocr_run, ocr_init import time, gobject from qtsymbols import * -from traceback import print_exc from collections import Counter from textsource.textsourcebase import basetext @@ -36,10 +35,7 @@ def compareImage(img1: QImage, img2): class ocrtext(basetext): def __init__(self): - try: - ocr_init() - except: - print_exc() + threading.Thread(target=ocr_init).start() self.screen = QApplication.primaryScreen() self.savelastimg = [] self.savelastrecimg = [] @@ -205,4 +201,3 @@ class ocrtext(basetext): globalconfig["ocrregions"] = [_.getrect() for _ in self.range_ui] [_.closesignal.emit() for _ in self.range_ui] super().end() - ocr_end() diff --git a/LunaTranslator/LunaTranslator/textsource/textsourcebase.py b/LunaTranslator/LunaTranslator/textsource/textsourcebase.py index 183ae690..31055061 100644 --- a/LunaTranslator/LunaTranslator/textsource/textsourcebase.py +++ b/LunaTranslator/LunaTranslator/textsource/textsourcebase.py @@ -137,6 +137,7 @@ class basetext: return None def end(self): + self.hwnd = None self.ending = True ##################