This commit is contained in:
恍兮惚兮 2024-05-22 15:08:46 +08:00
parent 114dcfd6f3
commit 60b64948f9
7 changed files with 37 additions and 15 deletions

View File

@ -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

View File

@ -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),),

View File

@ -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 = []

View File

@ -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(

View File

@ -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),),

View File

@ -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)
)

View File

@ -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: