mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-01 10:04:12 +08:00
fix
This commit is contained in:
parent
90de8735ad
commit
252f1bec1b
@ -6,6 +6,7 @@ from gui.dynalang import LAction
|
|||||||
|
|
||||||
|
|
||||||
class rangeadjust(Mainw):
|
class rangeadjust(Mainw):
|
||||||
|
closesignal = pyqtSignal()
|
||||||
traceoffsetsignal = pyqtSignal(QPoint)
|
traceoffsetsignal = pyqtSignal(QPoint)
|
||||||
|
|
||||||
def starttrace(self, pos):
|
def starttrace(self, pos):
|
||||||
@ -42,6 +43,7 @@ class rangeadjust(Mainw):
|
|||||||
self.traceoffsetsignal.connect(self.traceoffset)
|
self.traceoffsetsignal.connect(self.traceoffset)
|
||||||
self.label = QLabel(self)
|
self.label = QLabel(self)
|
||||||
self.setstyle()
|
self.setstyle()
|
||||||
|
self.closesignal.connect(self.close)
|
||||||
self.tracepos = QPoint()
|
self.tracepos = QPoint()
|
||||||
self.drag_label = QLabel(self)
|
self.drag_label = QLabel(self)
|
||||||
self.drag_label.setGeometry(0, 0, 4000, 2000)
|
self.drag_label.setGeometry(0, 0, 4000, 2000)
|
||||||
|
@ -16,7 +16,7 @@ from gui.usefulwidget import (
|
|||||||
)
|
)
|
||||||
from gui.dynalang import LPushButton
|
from gui.dynalang import LPushButton
|
||||||
import qtawesome, gobject
|
import qtawesome, gobject
|
||||||
from myutils.ocrutil import imagesolve
|
from myutils.ocrutil import imagesolve, ocr_end, ocr_init
|
||||||
from myutils.wrapper import Singleton_close
|
from myutils.wrapper import Singleton_close
|
||||||
|
|
||||||
|
|
||||||
@ -79,6 +79,13 @@ def __label2(self):
|
|||||||
return self.threshold2label
|
return self.threshold2label
|
||||||
|
|
||||||
|
|
||||||
|
def __directinitend(engine, _ok):
|
||||||
|
if _ok:
|
||||||
|
ocr_init()
|
||||||
|
else:
|
||||||
|
ocr_end()
|
||||||
|
|
||||||
|
|
||||||
def initgridsources(self, names):
|
def initgridsources(self, names):
|
||||||
line = []
|
line = []
|
||||||
i = 0
|
i = 0
|
||||||
@ -111,7 +118,7 @@ def initgridsources(self, names):
|
|||||||
globalconfig["ocr"],
|
globalconfig["ocr"],
|
||||||
"ocrswitchs",
|
"ocrswitchs",
|
||||||
name,
|
name,
|
||||||
None,
|
__directinitend,
|
||||||
),
|
),
|
||||||
pair="ocrswitchs",
|
pair="ocrswitchs",
|
||||||
),
|
),
|
||||||
|
@ -970,7 +970,6 @@ def yuitsu_switch(parent, configdict, dictobjectn, key, callback, checked):
|
|||||||
for k in dictobject:
|
for k in dictobject:
|
||||||
configdict[k]["use"] = k == key
|
configdict[k]["use"] = k == key
|
||||||
dictobject[k].setChecked(k == key)
|
dictobject[k].setChecked(k == key)
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
callback(key, checked)
|
callback(key, checked)
|
||||||
|
|
||||||
|
@ -86,20 +86,12 @@ _ocrengine = None
|
|||||||
|
|
||||||
def ocr_end():
|
def ocr_end():
|
||||||
global _ocrengine, _nowuseocr
|
global _ocrengine, _nowuseocr
|
||||||
try:
|
|
||||||
_ocrengine.end()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
_nowuseocr = None
|
_nowuseocr = None
|
||||||
_ocrengine = None
|
_ocrengine = None
|
||||||
|
|
||||||
|
|
||||||
def ocr_run(qimage: QImage):
|
def ocr_init():
|
||||||
image = qimage2binary(qimage, "PNG")
|
|
||||||
if not image:
|
|
||||||
return ""
|
|
||||||
global _nowuseocr, _ocrengine
|
global _nowuseocr, _ocrengine
|
||||||
|
|
||||||
use = None
|
use = None
|
||||||
for k in globalconfig["ocr"]:
|
for k in globalconfig["ocr"]:
|
||||||
if globalconfig["ocr"][k]["use"] == True and os.path.exists(
|
if globalconfig["ocr"][k]["use"] == True and os.path.exists(
|
||||||
@ -108,17 +100,23 @@ def ocr_run(qimage: QImage):
|
|||||||
use = k
|
use = k
|
||||||
break
|
break
|
||||||
if use is None:
|
if use is None:
|
||||||
return ""
|
raise Exception("no engine")
|
||||||
|
if _nowuseocr == use:
|
||||||
|
return
|
||||||
|
_ocrengine = None
|
||||||
|
_nowuseocr = None
|
||||||
|
aclass = importlib.import_module("ocrengines." + use).OCR
|
||||||
|
_ocrengine = aclass(use)
|
||||||
|
_nowuseocr = use
|
||||||
|
|
||||||
|
|
||||||
|
def ocr_run(qimage: QImage):
|
||||||
|
image = qimage2binary(qimage, "PNG")
|
||||||
|
if not image:
|
||||||
|
return ""
|
||||||
|
global _nowuseocr, _ocrengine
|
||||||
try:
|
try:
|
||||||
if _nowuseocr != use:
|
ocr_init()
|
||||||
try:
|
|
||||||
_ocrengine.end()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
aclass = importlib.import_module("ocrengines." + use).OCR
|
|
||||||
_ocrengine = aclass(use)
|
|
||||||
_nowuseocr = use
|
|
||||||
text = _ocrengine._private_ocr(image)
|
text = _ocrengine._private_ocr(image)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, ArgsEmptyExc):
|
if isinstance(e, ArgsEmptyExc):
|
||||||
@ -126,7 +124,12 @@ def ocr_run(qimage: QImage):
|
|||||||
else:
|
else:
|
||||||
print_exc()
|
print_exc()
|
||||||
msg = stringfyerror(e)
|
msg = stringfyerror(e)
|
||||||
msg = "<msg_error_refresh>" + _TR(globalconfig["ocr"][use]["name"]) + " " + msg
|
msg = (
|
||||||
|
"<msg_error_refresh>"
|
||||||
|
+ (_TR(globalconfig["ocr"][_nowuseocr]["name"]) if _nowuseocr else "")
|
||||||
|
+ " "
|
||||||
|
+ msg
|
||||||
|
)
|
||||||
text = msg
|
text = msg
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
@ -12,9 +12,6 @@ class baseocr(commonbase):
|
|||||||
def ocr(self, imagebinary):
|
def ocr(self, imagebinary):
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
def end(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -189,7 +189,7 @@ def question(dialog: QDialog):
|
|||||||
|
|
||||||
|
|
||||||
class OCR(baseocr):
|
class OCR(baseocr):
|
||||||
def end(self):
|
def __del__(self):
|
||||||
self._ocr.trydestroy()
|
self._ocr.trydestroy()
|
||||||
|
|
||||||
def initocr(self):
|
def initocr(self):
|
||||||
|
@ -68,7 +68,7 @@ class OCR(baseocr):
|
|||||||
)
|
)
|
||||||
return wechatocr_path, wechat_path
|
return wechatocr_path, wechat_path
|
||||||
|
|
||||||
def end(self):
|
def __del__(self):
|
||||||
|
|
||||||
wcocr_destroy = self.wcocr.wcocr_destroy
|
wcocr_destroy = self.wcocr.wcocr_destroy
|
||||||
wcocr_destroy.argtypes = (c_void_p,)
|
wcocr_destroy.argtypes = (c_void_p,)
|
||||||
|
@ -2,9 +2,10 @@ import time
|
|||||||
from myutils.config import globalconfig
|
from myutils.config import globalconfig
|
||||||
import winsharedutils
|
import winsharedutils
|
||||||
from gui.rangeselect import rangeadjust
|
from gui.rangeselect import rangeadjust
|
||||||
from myutils.ocrutil import imageCut, ocr_run, ocr_end
|
from myutils.ocrutil import imageCut, ocr_run, ocr_end, ocr_init
|
||||||
import time, gobject
|
import time, gobject
|
||||||
from qtsymbols import *
|
from qtsymbols import *
|
||||||
|
from traceback import print_exc
|
||||||
from textsource.textsourcebase import basetext
|
from textsource.textsourcebase import basetext
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +35,10 @@ def compareImage(img1: QImage, img2):
|
|||||||
class ocrtext(basetext):
|
class ocrtext(basetext):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
try:
|
||||||
|
ocr_init()
|
||||||
|
except:
|
||||||
|
print_exc()
|
||||||
self.screen = QApplication.primaryScreen()
|
self.screen = QApplication.primaryScreen()
|
||||||
self.savelastimg = []
|
self.savelastimg = []
|
||||||
self.savelastrecimg = []
|
self.savelastrecimg = []
|
||||||
@ -178,6 +183,6 @@ class ocrtext(basetext):
|
|||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
globalconfig["ocrregions"] = [_.getrect() for _ in self.range_ui]
|
globalconfig["ocrregions"] = [_.getrect() for _ in self.range_ui]
|
||||||
[_.close() for _ in self.range_ui]
|
[_.closesignal.emit() for _ in self.range_ui]
|
||||||
super().end()
|
super().end()
|
||||||
ocr_end()
|
ocr_end()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user