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