diff --git a/cpp/version.cmake b/cpp/version.cmake index 9aac2a28..12205cc9 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 17) -set(VERSION_PATCH 5) +set(VERSION_PATCH 6) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) diff --git a/py/LunaTranslator/gui/showword.py b/py/LunaTranslator/gui/showword.py index 9136174c..4cf53786 100644 --- a/py/LunaTranslator/gui/showword.py +++ b/py/LunaTranslator/gui/showword.py @@ -2,7 +2,7 @@ from qtsymbols import * import json, time, functools, os, base64, uuid from urllib.parse import quote from traceback import print_exc -import qtawesome, requests, gobject, windows +import qtawesome, requests, gobject, windows, hashlib import myutils.ankiconnect as anki from myutils.hwnd import grabwindow from myutils.config import globalconfig, static_data, _TR @@ -20,6 +20,8 @@ from gui.usefulwidget import ( statusbutton, getQMessageBox, auto_select_webview, + WebivewWidget, + mshtmlWidget, getboxlayout, getspinbox, getsimplecombobox, @@ -36,16 +38,7 @@ from gui.usefulwidget import ( tabadd_lazy, VisLFormLayout, ) -from gui.dynalang import ( - LPushButton, - LLabel, - LTabWidget, - LTabBar, - LFormLayout, - LLabel, - LMainWindow, - LAction, -) +from gui.dynalang import LPushButton, LLabel, LTabWidget, LTabBar, LAction from myutils.audioplayer import bass_code_cast @@ -1069,6 +1062,70 @@ class showdiction(QWidget): root.setData(len(rows) > 0, DeterminedhasChildren) +class showwordfastwebview(auto_select_webview): + def reloaddata(self): + if isinstance(self.internal, mshtmlWidget): + super().reloaddata() + + def _maybecreate_internal(self): + self.needreset = True + super()._maybecreate_internal() + if isinstance(self.internal, WebivewWidget): + if self.lastaction: + super().reloaddata() + else: + self.setframework() + + def __init__(self, parent, dyna=False): + self.needreset = False + super().__init__(parent, dyna) + self.on_load.connect(self.checkurlchange) + + def setframework(self, html=None): + path = os.path.join(os.path.dirname(__file__), "showwordfast.html") + if html: + with open(path, "r", encoding="utf8") as ff: + html = ff.read().replace( + '
', + '
{}
'.format(html), + ) + md5 = hashlib.md5(html.encode("utf8", errors="ignore")).hexdigest() + path = gobject.gettempdir(md5 + ".html") + with open(path, "w", encoding="utf8") as ff: + ff.write(html) + self.internal.navigate(os.path.abspath(path)) + + def checkurlchange(self, url: str): + if url == "about:blank": + pass + elif not url.startswith("file:"): + self.needreset = True + + def setHtml(self, html): + # webview2 sethtml谜之很慢,navigate和eval比较快 + if isinstance(self.internal, mshtmlWidget): + super().setHtml(html) + elif isinstance(self.internal, WebivewWidget): + self.lastaction = 1, html + self.internal.set_zoom(self.internalsavedzoom) + if self.needreset: + self.needreset = False + self.setframework(html) + else: + self.internal.eval("_clear_all()") + self.internal.eval("_set_extra_html('{}')".format(quote(html))) + + def clear(self): + if isinstance(self.internal, mshtmlWidget): + super().clear() + elif isinstance(self.internal, WebivewWidget): + self.lastaction = None + if self.needreset: + self.needreset = False + self.setframework() + self.internal.eval("_clear_all()") + + class searchwordW(closeashidewindow): search_word = pyqtSignal(str, bool) show_dict_result = pyqtSignal(float, str, str) @@ -1144,7 +1201,8 @@ class searchwordW(closeashidewindow): html = self.cache_results[self.tabks[idx]] except: return - self.textOutput.setHtml("" + html) + html = "" + html + self.textOutput.setHtml(html) def searchwinnewwindow(self, word): @@ -1251,7 +1309,7 @@ class searchwordW(closeashidewindow): self.tab.currentChanged.connect(__) self.tabks = [] self.setCentralWidget(ww) - self.textOutput = auto_select_webview(self, True) + self.textOutput = showwordfastwebview(self, True) self.textOutput.add_menu( 0, _TR("查词"), lambda w: self.search_word.emit(w, False) ) @@ -1401,7 +1459,6 @@ class searchwordW(closeashidewindow): self.tabks.clear() self.textOutput.clear() self.cache_results.clear() - self.thisps.clear() self.hasclicked = False pxx = 999 diff --git a/py/LunaTranslator/gui/showwordfast.html b/py/LunaTranslator/gui/showwordfast.html new file mode 100644 index 00000000..191ee3f2 --- /dev/null +++ b/py/LunaTranslator/gui/showwordfast.html @@ -0,0 +1,47 @@ + + + + + + +
+ + + \ No newline at end of file diff --git a/py/LunaTranslator/gui/usefulwidget.py b/py/LunaTranslator/gui/usefulwidget.py index b37cd4b6..05591858 100644 --- a/py/LunaTranslator/gui/usefulwidget.py +++ b/py/LunaTranslator/gui/usefulwidget.py @@ -1,5 +1,5 @@ from qtsymbols import * -import os, re, functools, uuid, json, math, csv, io, pickle +import os, re, functools, hashlib, json, math, csv, io, pickle from traceback import print_exc import windows, qtawesome, winsharedutils, gobject from webviewpy import webview_native_handle_kind_t, Webview @@ -1503,6 +1503,10 @@ class auto_select_webview(QWidget): on_load = pyqtSignal(str) on_ZoomFactorChanged = pyqtSignal(float) + def eval(self, js): + self.internal.eval(js) + self.evals.append(js) + def bind(self, funcname, function): self.bindinfo.append((funcname, function)) self.internal.bind(funcname, function) @@ -1527,7 +1531,8 @@ class auto_select_webview(QWidget): if len(html) < self.internal.html_limit: self.internal.setHtml(html) else: - lastcachehtml = gobject.gettempdir(str(uuid.uuid4()) + ".html") + md5 = hashlib.md5(html.encode("utf8", errors="ignore")).hexdigest() + lastcachehtml = gobject.gettempdir(md5 + ".html") with open(lastcachehtml, "w", encoding="utf8") as ff: ff.write(html) self.internal.navigate(lastcachehtml) @@ -1542,6 +1547,7 @@ class auto_select_webview(QWidget): def __init__(self, parent, dyna=False) -> None: super().__init__(parent) self.addmenuinfo = [] + self.evals = [] self.bindinfo = [] self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self.internal = None @@ -1571,6 +1577,15 @@ class auto_select_webview(QWidget): self.internal.on_load.connect(self.on_load) self.internal.on_ZoomFactorChanged.connect(self.internalzoomchanged) self.layout().addWidget(self.internal) + for _ in self.addmenuinfo: + self.internal.add_menu(*_) + for _ in self.bindinfo: + self.internal.bind(*_) + for _ in self.evals: + self.internal.eval(_) + self.reloaddata() + + def reloaddata(self): if self.lastaction: action, arg = self.lastaction if action == 0: @@ -1579,10 +1594,6 @@ class auto_select_webview(QWidget): self.setHtml(arg) else: self.clear() - for _ in self.addmenuinfo: - self.internal.add_menu(*_) - for _ in self.bindinfo: - self.internal.bind(*_) def _createwebview(self): contex = globalconfig["usewebview"] diff --git a/py/files/defaultconfig/static_data.json b/py/files/defaultconfig/static_data.json index 929aee70..2cab9efb 100644 --- a/py/files/defaultconfig/static_data.json +++ b/py/files/defaultconfig/static_data.json @@ -275,7 +275,7 @@ }, { "name": "unidic", - "link": "https://clrd.ninjal.ac.jp/unidic/en/" + "link": "https://clrd.ninjal.ac.jp/unidic/" } ] },