mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
opti
This commit is contained in:
parent
114dcfd6f3
commit
60b64948f9
@ -20,7 +20,7 @@ class cishubase:
|
||||
pass
|
||||
|
||||
@threader
|
||||
def safesearch(self, sentence):
|
||||
def safesearch(self, sentence, callback):
|
||||
try:
|
||||
if self.needinit:
|
||||
self.init()
|
||||
@ -32,7 +32,7 @@ class cishubase:
|
||||
self.needinit = True
|
||||
|
||||
if res and len(res):
|
||||
self.callback(res)
|
||||
callback(res)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
@ -15,7 +15,8 @@ class edict(cishubase):
|
||||
pass
|
||||
|
||||
def search(self, word):
|
||||
|
||||
if not self.sql:
|
||||
return
|
||||
x = self.sql.execute(
|
||||
"select text, entry_id from surface where text like ?",
|
||||
("%{}%".format(word),),
|
||||
|
@ -7,7 +7,7 @@ from cishu.cishubase import cishubase
|
||||
|
||||
class edict2(cishubase):
|
||||
def init(self):
|
||||
self.sql = None
|
||||
self.save = None
|
||||
try:
|
||||
path = self.config["path"]
|
||||
if os.path.exists(path):
|
||||
@ -25,7 +25,8 @@ class edict2(cishubase):
|
||||
print_exc()
|
||||
|
||||
def search(self, word):
|
||||
|
||||
if not self.save:
|
||||
return
|
||||
dis = 9999
|
||||
dis = []
|
||||
savew = []
|
||||
|
@ -29,7 +29,8 @@ class linggesi(cishubase):
|
||||
pass
|
||||
|
||||
def search(self, word):
|
||||
|
||||
if not self.sql:
|
||||
return
|
||||
mp = {}
|
||||
for sql in [self.sql, self.sql2]:
|
||||
x = sql.execute(
|
||||
|
@ -16,7 +16,8 @@ class xiaoxueguan(cishubase):
|
||||
pass
|
||||
|
||||
def search(self, word):
|
||||
|
||||
if not self.sql:
|
||||
return
|
||||
x = self.sql.execute(
|
||||
"select word,explanation from xiaoxueguanrizhong where word like ?",
|
||||
("%{}%".format(word),),
|
||||
|
@ -735,7 +735,7 @@ class selectviewer(QWidget):
|
||||
|
||||
class searchwordW(closeashidewindow):
|
||||
getnewsentencesignal = pyqtSignal(str, bool)
|
||||
showtabsignal = pyqtSignal(str, str)
|
||||
showtabsignal = pyqtSignal(float, str, str)
|
||||
|
||||
def __init__(self, parent):
|
||||
super(searchwordW, self).__init__(parent, globalconfig, "sw_geo")
|
||||
@ -745,7 +745,9 @@ class searchwordW(closeashidewindow):
|
||||
self.getnewsentencesignal.connect(self.getnewsentence)
|
||||
self.setWindowTitle(_TR("查词"))
|
||||
|
||||
def showresfun(self, k, res):
|
||||
def showresfun(self, timestamp, k, res):
|
||||
if self.current != timestamp:
|
||||
return
|
||||
self.cache_results[k] = res
|
||||
|
||||
thisp = globalconfig["cishu"][k]["args"]["priority"]
|
||||
@ -853,6 +855,8 @@ class searchwordW(closeashidewindow):
|
||||
grabwindow(self.ankiwindow.editpath.setText)
|
||||
|
||||
def search(self, sentence):
|
||||
current = time.time()
|
||||
self.current = current
|
||||
sentence = sentence.strip()
|
||||
if sentence == "":
|
||||
return
|
||||
@ -863,5 +867,6 @@ class searchwordW(closeashidewindow):
|
||||
self.textOutput.clear()
|
||||
self.cache_results.clear()
|
||||
for k, cishu in gobject.baseobject.cishus.items():
|
||||
cishu.callback = functools.partial(self.showtabsignal.emit, k)
|
||||
cishu.safesearch(sentence)
|
||||
cishu.safesearch(
|
||||
sentence, functools.partial(self.showtabsignal.emit, current, k)
|
||||
)
|
||||
|
@ -627,15 +627,27 @@ class auto_select_webview(QWidget):
|
||||
|
||||
def navigate(self, url):
|
||||
self._maybecreate()
|
||||
self.clearcache()
|
||||
self.internal.navigate(url)
|
||||
|
||||
def setHtml(self, html):
|
||||
self._maybecreate()
|
||||
self.internal.setHtml(html)
|
||||
self.clearcache()
|
||||
if len(html) < 1 * 1024 * 1024: # 1mb
|
||||
self.internal.setHtml(html)
|
||||
else:
|
||||
os.makedirs("cache/temp", exist_ok=True)
|
||||
self.lastcachehtml = os.path.abspath(
|
||||
"cache/temp/" + str(time.time()) + ".html"
|
||||
)
|
||||
with open(self.lastcachehtml, "w", encoding="utf8") as ff:
|
||||
ff.write(html)
|
||||
print("file://" + self.lastcachehtml.replace("\\", "/"))
|
||||
self.internal.navigate("file://" + self.lastcachehtml.replace("\\", "/"))
|
||||
|
||||
def navigate(self, url):
|
||||
self._maybecreate()
|
||||
self.internal.navigate(url)
|
||||
def clearcache(self):
|
||||
if self.lastcachehtml and os.path.exists(self.lastcachehtml):
|
||||
os.remove(self.lastcachehtml)
|
||||
|
||||
def __init__(self, parent) -> None:
|
||||
super().__init__(parent)
|
||||
@ -647,6 +659,7 @@ class auto_select_webview(QWidget):
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.setLayout(layout)
|
||||
self._maybecreate()
|
||||
self.lastcachehtml = None
|
||||
|
||||
def _maybecreate(self):
|
||||
if globalconfig["usewebview"] != self.contex:
|
||||
|
Loading…
x
Reference in New Issue
Block a user