This commit is contained in:
恍兮惚兮 2024-11-01 17:31:10 +08:00
parent e4b7c07207
commit e4160fa4ee
7 changed files with 86 additions and 83 deletions

View File

@ -4,7 +4,7 @@ from collections import OrderedDict
from traceback import print_exc from traceback import print_exc
import qtawesome, windows, winsharedutils, gobject import qtawesome, windows, winsharedutils, gobject
from myutils.config import savehook_new_data, static_data, globalconfig, _TR from myutils.config import savehook_new_data, static_data, globalconfig, _TR
from myutils.utils import checkchaos, get_time_stamp, dynamiclink from myutils.utils import checkchaos, get_time_stamp, dynamiclink, is_ascii_control
from myutils.wrapper import Singleton_close from myutils.wrapper import Singleton_close
from gui.dialog_savedgame import dialog_setting_game from gui.dialog_savedgame import dialog_setting_game
from gui.usefulwidget import ( from gui.usefulwidget import (
@ -151,7 +151,6 @@ class PatternValidator(QValidator):
return QValidator.State.Invalid, input_str, pos return QValidator.State.Invalid, input_str, pos
class searchhookparam(LDialog): class searchhookparam(LDialog):
def safehex(self, string, default): def safehex(self, string, default):
try: try:
@ -751,32 +750,18 @@ class hookselect(closeashidewindow):
except: except:
print_exc() print_exc()
def gethide(self, res): def gethide(self, res: str):
hide = False
if self.checkfilt_notascii.isChecked(): if self.checkfilt_notascii.isChecked():
try: if res.isascii():
res.encode("ascii") return True
hide = True
except:
pass
if self.checkfilt_notshiftjis.isChecked(): if self.checkfilt_notshiftjis.isChecked():
if checkchaos(res): if checkchaos(res):
hide = True return True
if self.checkfilt_notcontrol.isChecked(): if self.checkfilt_notcontrol.isChecked():
lres = list(res) for r in res:
for r in lres: if is_ascii_control(r):
_ord = ord(r) return True
if ( return False
(_ord >= 0x21 and _ord <= 0x2F)
or (_ord >= 0x3A and _ord <= 0x40)
or (_ord >= 0x5B and _ord <= 0x60)
or (_ord >= 0x7B and _ord <= 0x7E)
):
hide = True
break
return hide
def searchtextfunc2(self): def searchtextfunc2(self):
searchtext = self.searchtext2.text() searchtext = self.searchtext2.text()
@ -784,11 +769,9 @@ class hookselect(closeashidewindow):
for index in range(len(self.allres)): for index in range(len(self.allres)):
_index = len(self.allres) - 1 - index _index = len(self.allres) - 1 - index
resbatch = self.allres[list(self.allres.keys())[_index]] res = "\n".join(self.allres[list(self.allres.keys())[_index]])
hide = all( hide = (searchtext not in res) or self.gethide(res)
[(searchtext not in res) or self.gethide(res) for res in resbatch]
)
self.tttable2.setRowHidden(_index, hide) self.tttable2.setRowHidden(_index, hide)
def searchtextfunc(self): def searchtextfunc(self):

View File

@ -34,6 +34,7 @@ from gui.usefulwidget import (
getIconButton, getIconButton,
saveposwindow, saveposwindow,
tabadd_lazy, tabadd_lazy,
LRButton,
) )
from gui.dynalang import ( from gui.dynalang import (
LPushButton, LPushButton,
@ -454,6 +455,8 @@ class AnkiWindow(QWidget):
self.editpath.textChanged.connect(self.wrappedpixmap) self.editpath.textChanged.connect(self.wrappedpixmap)
self.example = FQPlainTextEdit() self.example = FQPlainTextEdit()
self.zhuyinedit = FQPlainTextEdit() self.zhuyinedit = FQPlainTextEdit()
self.wordedit = FQLineEdit()
self.wordedit.textChanged.connect(self.wordedit_t)
self.example.hiras = None self.example.hiras = None
def __(): def __():
@ -494,6 +497,12 @@ class AnkiWindow(QWidget):
) )
folder_open3 = QPushButton(qtawesome.icon("fa.folder-open"), "") folder_open3 = QPushButton(qtawesome.icon("fa.folder-open"), "")
folder_open3.clicked.connect(functools.partial(self.selecfile2, self.editpath)) folder_open3.clicked.connect(functools.partial(self.selecfile2, self.editpath))
def createadd():
btn = LRButton("添加")
btn.clicked.connect(functools.partial(self.errorwrap, False))
btn.rightclick.connect(functools.partial(self.errorwrap, True))
return btn
layout.addLayout( layout.addLayout(
getboxlayout( getboxlayout(
[ [
@ -523,6 +532,11 @@ class AnkiWindow(QWidget):
), ),
] ]
), ),
getboxlayout(
[LLabel("单词"), self.wordedit],
QHBoxLayout,
margin0=True,
),
getboxlayout( getboxlayout(
[LLabel("注音"), self.zhuyinedit], [LLabel("注音"), self.zhuyinedit],
QVBoxLayout, QVBoxLayout,
@ -586,6 +600,7 @@ class AnkiWindow(QWidget):
] ]
), ),
self.viewimagelabel, self.viewimagelabel,
createadd
], ],
QVBoxLayout, QVBoxLayout,
), ),
@ -593,20 +608,6 @@ class AnkiWindow(QWidget):
) )
) )
class LRButton(LPushButton):
rightclick = pyqtSignal()
def mouseReleaseEvent(self, ev: QMouseEvent) -> None:
if self.rect().contains(ev.pos()):
if ev.button() == Qt.MouseButton.RightButton:
self.rightclick.emit()
return super().mouseReleaseEvent(ev)
btn = LRButton("添加")
btn.clicked.connect(functools.partial(self.errorwrap, False))
btn.rightclick.connect(functools.partial(self.errorwrap, True))
layout.addWidget(btn)
self.__ocrsettext.connect(self.example.appendPlainText) self.__ocrsettext.connect(self.example.appendPlainText)
self.reset("") self.reset("")
@ -644,14 +645,17 @@ class AnkiWindow(QWidget):
html = "<ruby>" + html + "</ruby>" html = "<ruby>" + html + "</ruby>"
return html return html
def reset(self, text): def wordedit_t(self, text):
self.currentword = text
if text and len(text): if text and len(text):
self.zhuyinedit.setPlainText( self.zhuyinedit.setPlainText(
self.makerubyhtml(gobject.baseobject.parsehira(text)) self.makerubyhtml(gobject.baseobject.parsehira(text))
) )
else: else:
self.zhuyinedit.clear() self.zhuyinedit.clear()
def reset(self, text):
self.currentword = text
self.wordedit.setText(text)
self.editpath.clear() self.editpath.clear()
self.audiopath.clear() self.audiopath.clear()
self.audiopath_sentence.clear() self.audiopath_sentence.clear()
@ -915,10 +919,9 @@ class showdiction(LMainWindow):
def __init__(self, parent: QWidget): def __init__(self, parent: QWidget):
super(showdiction, self).__init__(parent) super(showdiction, self).__init__(parent)
wordfilter = QHBoxLayout() wordfilter = QHBoxLayout()
word = QLineEdit() self.word = FQLineEdit()
self.word = word self.word.returnPressed.connect(self.setwordfilter)
word.returnPressed.connect(self.setwordfilter) wordfilter.addWidget(self.word)
wordfilter.addWidget(word)
butn = getIconButton(self.setwordfilter, "fa.filter") butn = getIconButton(self.setwordfilter, "fa.filter")
wordfilter.addWidget(butn) wordfilter.addWidget(butn)

View File

@ -2362,3 +2362,12 @@ class FQLineEdit(QLineEdit):
# 点击浏览器后,无法重新获取焦点。 # 点击浏览器后,无法重新获取焦点。
windows.SetFocus(int(self.winId())) windows.SetFocus(int(self.winId()))
return super().mousePressEvent(a0) return super().mousePressEvent(a0)
class LRButton(LPushButton):
rightclick = pyqtSignal()
def mouseReleaseEvent(self, ev: QMouseEvent) -> None:
if self.rect().contains(ev.pos()):
if ev.button() == Qt.MouseButton.RightButton:
self.rightclick.emit()
return super().mouseReleaseEvent(ev)

View File

@ -1,16 +1,6 @@
from collections import defaultdict from collections import defaultdict
import re import re
from myutils.utils import cinranges
def inrange(n, s, e):
return n >= s and n <= e
def inranges(n, *argc):
for s, e in argc:
if inrange(n, s, e):
return True
return False
def guess(string: str): def guess(string: str):
@ -19,8 +9,8 @@ def guess(string: str):
if string.isascii(): if string.isascii():
return "en" return "en"
checkers = { checkers = {
"ru": lambda c: inranges( "ru": lambda c: cinranges(
ord(c), c,
(0x0400, 0x04FF), (0x0400, 0x04FF),
(0x0500, 0x052F), (0x0500, 0x052F),
(0x2DE0, 0x2DFF), (0x2DE0, 0x2DFF),
@ -30,8 +20,8 @@ def guess(string: str):
(0x1D2C, 0x1D5F), (0x1D2C, 0x1D5F),
(0x1D780, 0x1D7AF), (0x1D780, 0x1D7AF),
), ),
"ko": lambda c: inranges( "ko": lambda c: cinranges(
ord(c), c,
(0x1100, 0x11FF), (0x1100, 0x11FF),
(0x3130, 0x318F), (0x3130, 0x318F),
(0xAC00, 0xD7AF), (0xAC00, 0xD7AF),
@ -39,8 +29,8 @@ def guess(string: str):
(0xD7B0, 0xD7FF), (0xD7B0, 0xD7FF),
), ),
"ja": { "ja": {
lambda c: inranges( lambda c: cinranges(
ord(c), c,
(0x3040, 0x309F), (0x3040, 0x309F),
(0x30A0, 0x30FF), (0x30A0, 0x30FF),
(0xFF65, 0xFF9F), (0xFF65, 0xFF9F),
@ -49,19 +39,19 @@ def guess(string: str):
(0x31A0, 0x31BF), (0x31A0, 0x31BF),
(0x3000, 0x303F), (0x3000, 0x303F),
): 20, ): 20,
lambda c: inranges( lambda c: cinranges(
ord(c), c,
(0x4E00, 0x9FA5), (0x4E00, 0x9FA5),
): 4, ): 4,
}, },
"zh": { "zh": {
lambda c: inranges( lambda c: cinranges(
ord(c), c,
(0x4E00, 0x9FA5), (0x4E00, 0x9FA5),
): 5 ): 5
}, },
"ar": lambda c: inranges( "ar": lambda c: cinranges(
ord(c), c,
(0x0600, 0x06FF), (0x0600, 0x06FF),
(0x0750, 0x077F), (0x0750, 0x077F),
(0x08A0, 0x08FF), (0x08A0, 0x08FF),
@ -73,8 +63,8 @@ def guess(string: str):
(0x06F0, 0x06F9), (0x06F0, 0x06F9),
), ),
"en": { "en": {
lambda c: inranges( lambda c: cinranges(
ord(c), c,
(0x0000, 0x00FF), (0x0000, 0x00FF),
): 0.2 ): 0.2
}, },

View File

@ -10,6 +10,8 @@ from myutils.utils import (
getlanguagespace, getlanguagespace,
parsemayberegexreplace, parsemayberegexreplace,
safe_escape, safe_escape,
is_ascii_symbo,
is_ascii_control
) )
from myutils.config import ( from myutils.config import (
postprocessconfig, postprocessconfig,
@ -280,13 +282,7 @@ def _remove_symbo(line):
newline = "" newline = ""
for r in line: for r in line:
_ord = ord(r) if is_ascii_symbo(r):
if (
(_ord >= 0x21 and _ord <= 0x2F)
or (_ord >= 0x3A and _ord <= 0x40)
or (_ord >= 0x5B and _ord <= 0x60)
or (_ord >= 0x7B and _ord <= 0x7E)
):
continue continue
newline += r newline += r
return newline return newline
@ -295,8 +291,7 @@ def _remove_symbo(line):
def _remove_control(line): def _remove_control(line):
newline = "" newline = ""
for r in line: for r in line:
_ord = ord(r) if is_ascii_control(r):
if _ord <= 0x1F or (_ord >= 0x7F and _ord < 0xA0):
continue continue
newline += r newline += r
return newline return newline

View File

@ -1042,3 +1042,26 @@ def dynamicapiname(apiuid):
return globalconfig["fanyi"][apiuid].get( return globalconfig["fanyi"][apiuid].get(
"name_self_set", globalconfig["fanyi"][apiuid]["name"] "name_self_set", globalconfig["fanyi"][apiuid]["name"]
) )
def inrange(n, s, e):
return n >= s and n <= e
def inranges(n, *argc):
for s, e in argc:
if inrange(n, s, e):
return True
return False
def cinranges(n, *argc):
return inranges(ord(n), *argc)
def is_ascii_symbo(c: str):
return cinranges(c, (0x21, 0x2F), (0x3A, 0x40), (0x5B, 0x60), (0x7B, 0x7E))
def is_ascii_control(c: str):
return cinranges(c, (0, 0x1F), (0x7F, 0xA0))

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 5) set(VERSION_MAJOR 5)
set(VERSION_MINOR 53) set(VERSION_MINOR 53)
set(VERSION_PATCH 4) set(VERSION_PATCH 5)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)