Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import subprocess

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
Expand Down Expand Up @@ -184,6 +186,17 @@ def clickSettin(self) :
self.range_ui.close()
self.settin_ui.show()

# 启动本地 OCR
def startLocalOCR(self):
args = ["START"]
cmd = self.yaml["ocr_cmd_path"]
if isinstance(cmd, list):
for arg in cmd:
args.append(str(arg))
else:
args.append(str(cmd))
args.append(str(self.yaml["port"]))
subprocess.Popen(args, shell=True)

# 自动打开本地OCR
def autoOpenOfflineOCR(self) :
Expand All @@ -193,7 +206,7 @@ def autoOpenOfflineOCR(self) :
if not utils.port.detectPort(self.yaml["port"]) :
try :
# 启动本地OCR
os.startfile(self.yaml["ocr_cmd_path"])
self.startLocalOCR()
except Exception :
self.logger.error(format_exc())

Expand Down
2 changes: 1 addition & 1 deletion translator/ocr/dango.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def offlineOCR(object) :
# except Exception :
# object.logger.error(format_exc())

url = "http://127.0.0.1:6666/ocr/api"
url = "http://127.0.0.1:%d/ocr/api" % object.yaml["port"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url = f'http://127.0.0.1:{object.yaml["port"]}/ocr/api'

language = object.config["language"]
body = {
"ImagePath": image_path,
Expand Down
8 changes: 4 additions & 4 deletions ui/settin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2215,13 +2215,13 @@ def runOfflineOCR(self) :
utils.message.MessageBox("本地OCR运行失败",
"本地OCR已启动, 请不要重复运行! ")
else :
try :
try:
# 启动本地OCR
os.startfile(self.object.yaml["ocr_cmd_path"])
except FileNotFoundError :
self.object.startLocalOCR()
except FileNotFoundError:
utils.message.MessageBox("本地OCR运行失败",
"本地OCR还未安装, 请先安装! ")
except Exception :
except Exception:
self.logger.error(format_exc())
utils.message.MessageBox("本地OCR运行失败",
"原因: %s"%format_exc())
Expand Down
2 changes: 1 addition & 1 deletion utils/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def testOfflineOCR(object) :
QApplication.processEvents()
total_time = 0

url = "http://127.0.0.1:6666/ocr/api"
url = "http://127.0.0.1:%d/ocr/api" % object.yaml["port"]
body = {
"ImagePath": TEST_IMAGE_PATH,
"Language": "JAP"
Expand Down