This commit is contained in:
恍兮惚兮 2024-12-31 21:35:42 +08:00
parent ea72094e00
commit 1c17b4e17f

View File

@ -1,29 +1,109 @@
import gobject import gobject
import winrtutils import winrtutils, windows, re
from myutils.config import _TR, static_data import subprocess
from myutils.config import _TR
from myutils.utils import dynamiclink from myutils.utils import dynamiclink
from ocrengines.baseocrclass import baseocr from ocrengines.baseocrclass import baseocr
from qtsymbols import * from qtsymbols import *
from gui.dynalang import LPushButton, LLabel from gui.dynalang import LPushButton, LLabel
from myutils.utils import getlanguagespace from myutils.utils import getlanguagespace
from gui.dynalang import LPushButton, LFormLayout, LLabel
from gui.usefulwidget import SuperCombo, getboxlayout
import threading, qtawesome
def getallsupports():
_ = (
subprocess.run(
"powershell Get-WindowsCapability -Online | Where-Object { $_.Name -Like 'Language.OCR*' }",
stdout=subprocess.PIPE,
)
.stdout.decode()
.splitlines()
)
langs = []
langsinter = []
for i in range(len(_)):
if _[i].startswith("Name"):
if "Installed" in _[i + 1]:
continue
langs.append(re.search("Language.OCR~~~(.*?)~", _[i]).groups()[0])
langsinter.append(re.search("Language.OCR~~~(.*)", _[i]).group())
return langs, langsinter
class _SuperCombo(SuperCombo):
setlist = pyqtSignal(list, list)
def addItems(self, items, internals):
self.clear()
super().addItems(items, internals)
def loadlist(combo: _SuperCombo):
lang, inter = getallsupports()
combo.setlist.emit(lang, inter)
def installx(combo: _SuperCombo, btninstall):
if combo.currentIndex() == -1:
return
btninstall.setEnabled(False)
combo.setEnabled(False)
lang = combo.getIndexData(combo.currentIndex())
subprocess.run(
"powershell $Capability = Get-WindowsCapability -Online | Where-Object {{ $_.Name -Like '{}' }} | Add-WindowsCapability -Online".format(
lang
),
)
lang, inter = getallsupports()
combo.setlist.emit(lang, inter)
btninstall.setEnabled(True)
combo.setEnabled(True)
def question(): def question():
dialog = QWidget() dialog = QWidget()
formLayout = QHBoxLayout() formLayout = LFormLayout()
formLayout.setContentsMargins(0, 0, 0, 0) formLayout.setContentsMargins(0, 0, 0, 0)
dialog.setLayout(formLayout) dialog.setLayout(formLayout)
supportlang = QLabel() supportlang = QLabel()
supportlang.setText(", ".join([_[1] for _ in winrtutils.getlanguagelist()])) supportlang.setText(", ".join([_[1] for _ in winrtutils.getlanguagelist()]))
supportlang.setWordWrap(True)
formLayout.addRow("当前支持的语言", supportlang)
lst = []
if not windows.IsUserAnAdmin():
nopri = LLabel("权限不足,请以管理员权限运行!")
lst.append(nopri)
btndownload = LPushButton("添加语言包") btndownload = LPushButton("添加语言包")
btndownload.clicked.connect( btndownload.clicked.connect(
lambda: gobject.baseobject.openlink( lambda: gobject.baseobject.openlink(
dynamiclink("{docs_server}/#/zh/useapis/ocrapi?id=windowsocr") dynamiclink("{docs_server}/#/zh/useapis/ocrapi?id=windowsocr")
) )
) )
formLayout.addWidget(LLabel("当前支持的语言")) lst.append(btndownload)
formLayout.addWidget(supportlang) else:
formLayout.addWidget(btndownload) combo = _SuperCombo()
combo.setlist.connect(combo.addItems)
btninstall = LPushButton("添加")
btninstall.clicked.connect(
lambda: threading.Thread(target=installx, args=(combo, btninstall)).start()
)
lst.append(combo)
lst.append(btninstall)
threading.Thread(target=loadlist, args=(combo,)).start()
btndownload = QPushButton(icon=qtawesome.icon("fa.question"))
btndownload.clicked.connect(
lambda: gobject.baseobject.openlink(
dynamiclink("{docs_server}/#/zh/useapis/ocrapi?id=windowsocr")
)
)
lst.append(btndownload)
formLayout.addRow(
"添加语言包",
getboxlayout(lst, makewidget=True, margin0=True),
)
return dialog return dialog