mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
repair
This commit is contained in:
parent
0ab032c15a
commit
9e746507d3
@ -2493,6 +2493,7 @@ class mdict(cishubase):
|
||||
|
||||
for url in src_matches + href_matches:
|
||||
oked = False
|
||||
iscss = url.lower().endswith(".css")
|
||||
try:
|
||||
try:
|
||||
with open(os.path.join(base, url), "rb") as f:
|
||||
@ -2506,7 +2507,8 @@ class mdict(cishubase):
|
||||
file_content = index.mdd_lookup(url1)[0]
|
||||
except:
|
||||
func = url.split(r"://")[0]
|
||||
|
||||
if func == "entry":
|
||||
continue
|
||||
url1 = url.split(r"://")[1]
|
||||
url1 = url1.replace("/", "\\")
|
||||
|
||||
@ -2530,16 +2532,20 @@ class mdict(cishubase):
|
||||
)
|
||||
file_content = None
|
||||
oked = True
|
||||
|
||||
else:
|
||||
print(url)
|
||||
except:
|
||||
file_content = None
|
||||
if file_content:
|
||||
base64_content = base64.b64encode(file_content).decode("utf-8")
|
||||
html_content = html_content.replace(
|
||||
url, f"data:application/octet-stream;base64,{base64_content}"
|
||||
)
|
||||
if iscss:
|
||||
html_content = html_content.replace(
|
||||
url, f"data:text/css;base64,{base64_content}"
|
||||
)
|
||||
else:
|
||||
html_content = html_content.replace(
|
||||
url, f"data:application/octet-stream;base64,{base64_content}"
|
||||
)
|
||||
elif not oked:
|
||||
print(url)
|
||||
return html_content
|
||||
|
@ -2,13 +2,12 @@ import functools
|
||||
from myutils.config import globalconfig, static_data, _TR
|
||||
from myutils.winsyshotkey import SystemHotkey, registerException
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from PyQt5.QtWidgets import QKeySequenceEdit, QLabel
|
||||
import winsharedutils
|
||||
import gobject, windows
|
||||
from gui.usefulwidget import getsimpleswitch
|
||||
from PyQt5.QtWidgets import QLabel
|
||||
from gui.usefulwidget import getsimpleswitch, getsimplekeyseq
|
||||
from myutils.hwnd import grabwindow
|
||||
from myutils.utils import getimageformat
|
||||
from myutils.utils import getimageformat, parsekeystringtomodvkcode, unsupportkey
|
||||
|
||||
|
||||
def setTab_quick_direct(self):
|
||||
@ -62,21 +61,6 @@ def setTab_quick(self):
|
||||
self.tabadd_lazy(self.tab_widget, ("快捷按键"), lambda: setTab_quick_lazy(self))
|
||||
|
||||
|
||||
class CustomKeySequenceEdit(QKeySequenceEdit):
|
||||
changeedvent = pyqtSignal(str)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(CustomKeySequenceEdit, self).__init__(parent)
|
||||
|
||||
def keyPressEvent(self, QKeyEvent):
|
||||
super(CustomKeySequenceEdit, self).keyPressEvent(QKeyEvent)
|
||||
value = self.keySequence()
|
||||
if len(value.toString()):
|
||||
self.clearFocus()
|
||||
self.changeedvent.emit(value.toString().replace("Meta", "Win"))
|
||||
self.setKeySequence(QKeySequence(value))
|
||||
|
||||
|
||||
def setTab_quick_lazy(self):
|
||||
|
||||
grids = [
|
||||
@ -93,10 +77,6 @@ def setTab_quick_lazy(self):
|
||||
for name in globalconfig["quick_setting"]["all"]:
|
||||
if name not in self.bindfunctions:
|
||||
continue
|
||||
key1 = CustomKeySequenceEdit(
|
||||
QKeySequence(globalconfig["quick_setting"]["all"][name]["keystring"])
|
||||
)
|
||||
key1.changeedvent.connect(functools.partial(__changekeynew, self, name))
|
||||
|
||||
grids.append(
|
||||
[
|
||||
@ -106,7 +86,14 @@ def setTab_quick_lazy(self):
|
||||
"use",
|
||||
callback=functools.partial(fanyiselect, self, name),
|
||||
),
|
||||
(key1, 2),
|
||||
(
|
||||
getsimplekeyseq(
|
||||
globalconfig["quick_setting"]["all"][name],
|
||||
"keystring",
|
||||
functools.partial(regist_or_not_key, self, name),
|
||||
),
|
||||
2,
|
||||
),
|
||||
(self.referlabels[name], 4),
|
||||
]
|
||||
)
|
||||
@ -127,40 +114,6 @@ def fanyiselect(self, who, checked):
|
||||
regist_or_not_key(self, who)
|
||||
|
||||
|
||||
class unsupportkey(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def parsekeystringtomodvkcode(keystring):
|
||||
keys = []
|
||||
mode = 0
|
||||
if keystring[-1] == "+":
|
||||
keys += ["+"]
|
||||
keystring = keystring[:-2]
|
||||
ksl = keystring.split("+")
|
||||
ksl = ksl + keys
|
||||
unsupports = []
|
||||
if ksl[-1].upper() in static_data["vkcode_map"]:
|
||||
vkcode = static_data["vkcode_map"][ksl[-1].upper()]
|
||||
else:
|
||||
unsupports.append(ksl[-1])
|
||||
|
||||
for k in ksl[:-1]:
|
||||
if k.upper() in static_data["mod_map"]:
|
||||
mode = mode | static_data["mod_map"][k.upper()]
|
||||
else:
|
||||
unsupports.append(k)
|
||||
if len(unsupports):
|
||||
raise unsupportkey(unsupports)
|
||||
return mode, vkcode
|
||||
|
||||
|
||||
def __changekeynew(self, name, keystring):
|
||||
globalconfig["quick_setting"]["all"][name]["keystring"] = keystring
|
||||
|
||||
regist_or_not_key(self, name)
|
||||
|
||||
|
||||
def regist_or_not_key(self, name):
|
||||
self.referlabels[name].setText("")
|
||||
|
||||
|
@ -17,13 +17,13 @@ from PyQt5.QtWidgets import (
|
||||
from myutils.hwnd import grabwindow
|
||||
|
||||
from urllib.parse import quote
|
||||
from PyQt5.QtGui import QPixmap, QImage, QImageWriter
|
||||
from PyQt5.QtGui import QPixmap, QImage
|
||||
from traceback import print_exc
|
||||
import requests, json, time
|
||||
from PyQt5.QtCore import pyqtSignal, Qt
|
||||
import qtawesome, functools, os, base64
|
||||
import gobject, uuid, windows
|
||||
from myutils.utils import getimageformat
|
||||
from myutils.utils import getimageformat, parsekeystringtomodvkcode, unsupportkey
|
||||
from myutils.config import globalconfig, _TR, static_data
|
||||
import myutils.ankiconnect as anki
|
||||
from gui.usefulwidget import (
|
||||
@ -34,7 +34,7 @@ from gui.usefulwidget import (
|
||||
getspinbox,
|
||||
getlineedit,
|
||||
getsimpleswitch,
|
||||
getsimplecombobox,
|
||||
getsimplekeyseq,
|
||||
getcolorbutton,
|
||||
tabadd_lazy,
|
||||
)
|
||||
@ -296,7 +296,9 @@ class AnkiWindow(QWidget):
|
||||
example = self.example.toPlainText()
|
||||
if globalconfig["ankiconnect"]["boldword"]:
|
||||
if self.example.hiras is None:
|
||||
self.example.hiras = gobject.baseobject.translation_ui.parsehira(example)
|
||||
self.example.hiras = gobject.baseobject.translation_ui.parsehira(
|
||||
example
|
||||
)
|
||||
collect = []
|
||||
for hira in self.example.hiras:
|
||||
if hira["orig"] == word or hira.get("origorig", None) == word:
|
||||
@ -400,11 +402,11 @@ class AnkiWindow(QWidget):
|
||||
)
|
||||
|
||||
layout.addRow(
|
||||
_TR("自动TTS_1"),
|
||||
_TR("自动TTS"),
|
||||
getsimpleswitch(globalconfig["ankiconnect"], "autoruntts"),
|
||||
)
|
||||
layout.addRow(
|
||||
_TR("自动TTS_2"),
|
||||
_TR("自动TTS_例句"),
|
||||
getsimpleswitch(globalconfig["ankiconnect"], "autoruntts2"),
|
||||
)
|
||||
layout.addRow(
|
||||
@ -417,23 +419,33 @@ class AnkiWindow(QWidget):
|
||||
)
|
||||
|
||||
layout.addRow(
|
||||
_TR("录音时模拟按键_1"),
|
||||
getsimpleswitch(globalconfig["ankiconnect"]["simulate_key"]["1"], "use"),
|
||||
)
|
||||
layout.addRow(
|
||||
_TR("录音时模拟按键_1_VirtualKeyCode"),
|
||||
getspinbox(
|
||||
0, 9999, globalconfig["ankiconnect"]["simulate_key"]["1"], "keycode"
|
||||
_TR("录音时模拟按键"),
|
||||
getboxlayout(
|
||||
[
|
||||
getsimpleswitch(
|
||||
globalconfig["ankiconnect"]["simulate_key"]["1"], "use"
|
||||
),
|
||||
getsimplekeyseq(
|
||||
globalconfig["ankiconnect"]["simulate_key"]["1"], "keystring"
|
||||
),
|
||||
],
|
||||
margin0=True,
|
||||
makewidget=True,
|
||||
),
|
||||
)
|
||||
layout.addRow(
|
||||
_TR("录音时模拟按键_2"),
|
||||
getsimpleswitch(globalconfig["ankiconnect"]["simulate_key"]["2"], "use"),
|
||||
)
|
||||
layout.addRow(
|
||||
_TR("录音时模拟按键_2_VirtualKeyCode"),
|
||||
getspinbox(
|
||||
0, 9999, globalconfig["ankiconnect"]["simulate_key"]["2"], "keycode"
|
||||
_TR("录音时模拟按键_例句"),
|
||||
getboxlayout(
|
||||
[
|
||||
getsimpleswitch(
|
||||
globalconfig["ankiconnect"]["simulate_key"]["2"], "use"
|
||||
),
|
||||
getsimplekeyseq(
|
||||
globalconfig["ankiconnect"]["simulate_key"]["2"], "keystring"
|
||||
),
|
||||
],
|
||||
margin0=True,
|
||||
makewidget=True,
|
||||
),
|
||||
)
|
||||
return wid
|
||||
@ -444,9 +456,20 @@ class AnkiWindow(QWidget):
|
||||
return
|
||||
windows.SetForegroundWindow(gobject.baseobject.textsource.hwnd)
|
||||
time.sleep(0.1)
|
||||
key = globalconfig["ankiconnect"]["simulate_key"][i]["keycode"]
|
||||
windows.keybd_event(key, 0, 0, 0)
|
||||
windows.keybd_event(key, 0, windows.KEYEVENTF_KEYUP, 0)
|
||||
try:
|
||||
modes, vkcode = parsekeystringtomodvkcode(
|
||||
globalconfig["ankiconnect"]["simulate_key"][i]["keystring"], modes=True
|
||||
)
|
||||
except unsupportkey as e:
|
||||
print("不支持的键")
|
||||
return
|
||||
for mode in modes:
|
||||
windows.keybd_event(mode, 0, 0, 0)
|
||||
windows.keybd_event(vkcode, 0, 0, 0)
|
||||
time.sleep(0.1)
|
||||
windows.keybd_event(vkcode, 0, windows.KEYEVENTF_KEYUP, 0)
|
||||
for mode in modes:
|
||||
windows.keybd_event(mode, 0, windows.KEYEVENTF_KEYUP, 0)
|
||||
|
||||
def startorendrecord(self, i, target: QLineEdit, idx):
|
||||
if idx == 1:
|
||||
|
@ -1002,6 +1002,8 @@ class QUnFrameWindow(resizableframeless):
|
||||
for button in center:
|
||||
button.move(int(leftstart), 0)
|
||||
leftstart += button.width()
|
||||
for button in self.showbuttons:
|
||||
button.show()
|
||||
|
||||
def callwrap(self, call, _):
|
||||
try:
|
||||
|
@ -11,7 +11,10 @@ from PyQt5.QtWidgets import (
|
||||
QWidget,
|
||||
QLayout,
|
||||
)
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from PyQt5.QtWidgets import QKeySequenceEdit, QLabel
|
||||
from PyQt5.QtGui import QFontDatabase
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
|
||||
from webviewpy import (
|
||||
webview_native_handle_kind_t,
|
||||
@ -625,6 +628,32 @@ class mshtmlWidget(QWidget):
|
||||
return html
|
||||
|
||||
|
||||
class CustomKeySequenceEdit(QKeySequenceEdit):
|
||||
changeedvent = pyqtSignal(str)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(CustomKeySequenceEdit, self).__init__(parent)
|
||||
|
||||
def keyPressEvent(self, QKeyEvent):
|
||||
super(CustomKeySequenceEdit, self).keyPressEvent(QKeyEvent)
|
||||
value = self.keySequence()
|
||||
if len(value.toString()):
|
||||
self.clearFocus()
|
||||
self.changeedvent.emit(value.toString().replace("Meta", "Win"))
|
||||
self.setKeySequence(QKeySequence(value))
|
||||
|
||||
|
||||
def getsimplekeyseq(dic, key, callback=None):
|
||||
key1 = CustomKeySequenceEdit(QKeySequence(dic[key]))
|
||||
|
||||
def __(_d, _k, cb, s):
|
||||
_d[_k] = s
|
||||
if cb:
|
||||
cb()
|
||||
|
||||
key1.changeedvent.connect(functools.partial(__, dic, key, callback))
|
||||
return key1
|
||||
|
||||
class auto_select_webview(QWidget):
|
||||
on_load = pyqtSignal(str)
|
||||
|
||||
|
@ -594,3 +594,35 @@ def loadpostsettingwindowmethod(name):
|
||||
return tryprint(Process.get_setting_window)
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
class unsupportkey(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def parsekeystringtomodvkcode(keystring, modes=False):
|
||||
keys = []
|
||||
mode = 0
|
||||
_modes = []
|
||||
if keystring[-1] == "+":
|
||||
keys += ["+"]
|
||||
keystring = keystring[:-2]
|
||||
ksl = keystring.split("+")
|
||||
ksl = ksl + keys
|
||||
unsupports = []
|
||||
if ksl[-1].upper() in static_data["vkcode_map"]:
|
||||
vkcode = static_data["vkcode_map"][ksl[-1].upper()]
|
||||
else:
|
||||
unsupports.append(ksl[-1])
|
||||
|
||||
for k in ksl[:-1]:
|
||||
if k.upper() in static_data["mod_map"]:
|
||||
mode = mode | static_data["mod_map"][k.upper()]
|
||||
_modes.append(static_data["mod_map"][k.upper()])
|
||||
else:
|
||||
unsupports.append(k)
|
||||
if len(unsupports):
|
||||
raise unsupportkey(unsupports)
|
||||
if modes:
|
||||
mode = _modes
|
||||
return mode, vkcode
|
||||
|
@ -187,11 +187,11 @@
|
||||
"simulate_key": {
|
||||
"1": {
|
||||
"use": false,
|
||||
"keycode": 120
|
||||
"keystring": ""
|
||||
},
|
||||
"2": {
|
||||
"use": false,
|
||||
"keycode": 120
|
||||
"keystring": ""
|
||||
}
|
||||
},
|
||||
"autocrop": false,
|
||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
||||
|
||||
set(VERSION_MAJOR 2)
|
||||
set(VERSION_MINOR 52)
|
||||
set(VERSION_PATCH 7)
|
||||
set(VERSION_PATCH 8)
|
||||
|
||||
add_library(pch pch.cpp)
|
||||
target_precompile_headers(pch PUBLIC pch.h)
|
||||
|
Loading…
x
Reference in New Issue
Block a user