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
import qtawesome, windows, winsharedutils, gobject
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 gui.dialog_savedgame import dialog_setting_game
from gui.usefulwidget import (
@ -151,7 +151,6 @@ class PatternValidator(QValidator):
return QValidator.State.Invalid, input_str, pos
class searchhookparam(LDialog):
def safehex(self, string, default):
try:
@ -751,32 +750,18 @@ class hookselect(closeashidewindow):
except:
print_exc()
def gethide(self, res):
hide = False
def gethide(self, res: str):
if self.checkfilt_notascii.isChecked():
try:
res.encode("ascii")
hide = True
except:
pass
if res.isascii():
return True
if self.checkfilt_notshiftjis.isChecked():
if checkchaos(res):
hide = True
return True
if self.checkfilt_notcontrol.isChecked():
lres = list(res)
for r in lres:
_ord = ord(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)
):
hide = True
break
return hide
for r in res:
if is_ascii_control(r):
return True
return False
def searchtextfunc2(self):
searchtext = self.searchtext2.text()
@ -784,11 +769,9 @@ class hookselect(closeashidewindow):
for index in range(len(self.allres)):
_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(
[(searchtext not in res) or self.gethide(res) for res in resbatch]
)
hide = (searchtext not in res) or self.gethide(res)
self.tttable2.setRowHidden(_index, hide)
def searchtextfunc(self):

View File

@ -34,6 +34,7 @@ from gui.usefulwidget import (
getIconButton,
saveposwindow,
tabadd_lazy,
LRButton,
)
from gui.dynalang import (
LPushButton,
@ -454,6 +455,8 @@ class AnkiWindow(QWidget):
self.editpath.textChanged.connect(self.wrappedpixmap)
self.example = FQPlainTextEdit()
self.zhuyinedit = FQPlainTextEdit()
self.wordedit = FQLineEdit()
self.wordedit.textChanged.connect(self.wordedit_t)
self.example.hiras = None
def __():
@ -494,6 +497,12 @@ class AnkiWindow(QWidget):
)
folder_open3 = QPushButton(qtawesome.icon("fa.folder-open"), "")
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(
getboxlayout(
[
@ -523,6 +532,11 @@ class AnkiWindow(QWidget):
),
]
),
getboxlayout(
[LLabel("单词"), self.wordedit],
QHBoxLayout,
margin0=True,
),
getboxlayout(
[LLabel("注音"), self.zhuyinedit],
QVBoxLayout,
@ -586,6 +600,7 @@ class AnkiWindow(QWidget):
]
),
self.viewimagelabel,
createadd
],
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.reset("")
@ -644,14 +645,17 @@ class AnkiWindow(QWidget):
html = "<ruby>" + html + "</ruby>"
return html
def reset(self, text):
self.currentword = text
def wordedit_t(self, text):
if text and len(text):
self.zhuyinedit.setPlainText(
self.makerubyhtml(gobject.baseobject.parsehira(text))
)
else:
self.zhuyinedit.clear()
def reset(self, text):
self.currentword = text
self.wordedit.setText(text)
self.editpath.clear()
self.audiopath.clear()
self.audiopath_sentence.clear()
@ -915,10 +919,9 @@ class showdiction(LMainWindow):
def __init__(self, parent: QWidget):
super(showdiction, self).__init__(parent)
wordfilter = QHBoxLayout()
word = QLineEdit()
self.word = word
word.returnPressed.connect(self.setwordfilter)
wordfilter.addWidget(word)
self.word = FQLineEdit()
self.word.returnPressed.connect(self.setwordfilter)
wordfilter.addWidget(self.word)
butn = getIconButton(self.setwordfilter, "fa.filter")
wordfilter.addWidget(butn)

View File

@ -2362,3 +2362,12 @@ class FQLineEdit(QLineEdit):
# 点击浏览器后,无法重新获取焦点。
windows.SetFocus(int(self.winId()))
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
import re
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
from myutils.utils import cinranges
def guess(string: str):
@ -19,8 +9,8 @@ def guess(string: str):
if string.isascii():
return "en"
checkers = {
"ru": lambda c: inranges(
ord(c),
"ru": lambda c: cinranges(
c,
(0x0400, 0x04FF),
(0x0500, 0x052F),
(0x2DE0, 0x2DFF),
@ -30,8 +20,8 @@ def guess(string: str):
(0x1D2C, 0x1D5F),
(0x1D780, 0x1D7AF),
),
"ko": lambda c: inranges(
ord(c),
"ko": lambda c: cinranges(
c,
(0x1100, 0x11FF),
(0x3130, 0x318F),
(0xAC00, 0xD7AF),
@ -39,8 +29,8 @@ def guess(string: str):
(0xD7B0, 0xD7FF),
),
"ja": {
lambda c: inranges(
ord(c),
lambda c: cinranges(
c,
(0x3040, 0x309F),
(0x30A0, 0x30FF),
(0xFF65, 0xFF9F),
@ -49,19 +39,19 @@ def guess(string: str):
(0x31A0, 0x31BF),
(0x3000, 0x303F),
): 20,
lambda c: inranges(
ord(c),
lambda c: cinranges(
c,
(0x4E00, 0x9FA5),
): 4,
},
"zh": {
lambda c: inranges(
ord(c),
lambda c: cinranges(
c,
(0x4E00, 0x9FA5),
): 5
},
"ar": lambda c: inranges(
ord(c),
"ar": lambda c: cinranges(
c,
(0x0600, 0x06FF),
(0x0750, 0x077F),
(0x08A0, 0x08FF),
@ -73,8 +63,8 @@ def guess(string: str):
(0x06F0, 0x06F9),
),
"en": {
lambda c: inranges(
ord(c),
lambda c: cinranges(
c,
(0x0000, 0x00FF),
): 0.2
},

View File

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

View File

@ -1042,3 +1042,26 @@ def dynamicapiname(apiuid):
return globalconfig["fanyi"][apiuid].get(
"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_MINOR 53)
set(VERSION_PATCH 4)
set(VERSION_PATCH 5)
add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h)