This commit is contained in:
恍兮惚兮 2025-01-07 01:01:15 +08:00
parent ac0806e8e5
commit facbf0c400
5 changed files with 137 additions and 22 deletions

View File

@ -1,7 +1,7 @@
set(VERSION_MAJOR 6) set(VERSION_MAJOR 6)
set(VERSION_MINOR 17) set(VERSION_MINOR 17)
set(VERSION_PATCH 5) set(VERSION_PATCH 6)
set(VERSION_REVISION 0) set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)

View File

@ -2,7 +2,7 @@ from qtsymbols import *
import json, time, functools, os, base64, uuid import json, time, functools, os, base64, uuid
from urllib.parse import quote from urllib.parse import quote
from traceback import print_exc from traceback import print_exc
import qtawesome, requests, gobject, windows import qtawesome, requests, gobject, windows, hashlib
import myutils.ankiconnect as anki import myutils.ankiconnect as anki
from myutils.hwnd import grabwindow from myutils.hwnd import grabwindow
from myutils.config import globalconfig, static_data, _TR from myutils.config import globalconfig, static_data, _TR
@ -20,6 +20,8 @@ from gui.usefulwidget import (
statusbutton, statusbutton,
getQMessageBox, getQMessageBox,
auto_select_webview, auto_select_webview,
WebivewWidget,
mshtmlWidget,
getboxlayout, getboxlayout,
getspinbox, getspinbox,
getsimplecombobox, getsimplecombobox,
@ -36,16 +38,7 @@ from gui.usefulwidget import (
tabadd_lazy, tabadd_lazy,
VisLFormLayout, VisLFormLayout,
) )
from gui.dynalang import ( from gui.dynalang import LPushButton, LLabel, LTabWidget, LTabBar, LAction
LPushButton,
LLabel,
LTabWidget,
LTabBar,
LFormLayout,
LLabel,
LMainWindow,
LAction,
)
from myutils.audioplayer import bass_code_cast from myutils.audioplayer import bass_code_cast
@ -1069,6 +1062,70 @@ class showdiction(QWidget):
root.setData(len(rows) > 0, DeterminedhasChildren) 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(
'<div id="luna_root_div"></div>',
'<div id="luna_root_div">{}</div>'.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): class searchwordW(closeashidewindow):
search_word = pyqtSignal(str, bool) search_word = pyqtSignal(str, bool)
show_dict_result = pyqtSignal(float, str, str) show_dict_result = pyqtSignal(float, str, str)
@ -1144,7 +1201,8 @@ class searchwordW(closeashidewindow):
html = self.cache_results[self.tabks[idx]] html = self.cache_results[self.tabks[idx]]
except: except:
return return
self.textOutput.setHtml("<style>body{margin:0}</style>" + html) html = "<style>body{margin:0}</style>" + html
self.textOutput.setHtml(html)
def searchwinnewwindow(self, word): def searchwinnewwindow(self, word):
@ -1251,7 +1309,7 @@ class searchwordW(closeashidewindow):
self.tab.currentChanged.connect(__) self.tab.currentChanged.connect(__)
self.tabks = [] self.tabks = []
self.setCentralWidget(ww) self.setCentralWidget(ww)
self.textOutput = auto_select_webview(self, True) self.textOutput = showwordfastwebview(self, True)
self.textOutput.add_menu( self.textOutput.add_menu(
0, _TR("查词"), lambda w: self.search_word.emit(w, False) 0, _TR("查词"), lambda w: self.search_word.emit(w, False)
) )
@ -1401,7 +1459,6 @@ class searchwordW(closeashidewindow):
self.tabks.clear() self.tabks.clear()
self.textOutput.clear() self.textOutput.clear()
self.cache_results.clear() self.cache_results.clear()
self.thisps.clear() self.thisps.clear()
self.hasclicked = False self.hasclicked = False
pxx = 999 pxx = 999

View File

@ -0,0 +1,47 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style>
@media (prefers-color-scheme: dark) {
:root {
color-scheme: dark;
}
body {
background-color: rgb(44, 44, 44);
color: white;
}
}
</style>
</head>
<div id="luna_root_div"></div>
<script>
const rootdivid = 'luna_root_div';
function _clear_all() {
document.getElementById(rootdivid).innerHTML = "";
}
function _runScript(script) {
let newScript = document.createElement('script');
newScript.innerHTML = script.innerHTML;
let src = script.getAttribute('src');
if (src) newScript.setAttribute('src', src);
document.head.appendChild(newScript);
document.head.removeChild(newScript);
}
function _setHTMLWithScript(container, rawHTML) {
container.innerHTML = rawHTML;
let scripts = container.querySelectorAll('script');
for (let script of scripts) {
_runScript(script);
}
}
function _set_extra_html(htmlx) {
_setHTMLWithScript(document.getElementById(rootdivid), decodeURIComponent(htmlx))
}
</script>
</html>

View File

@ -1,5 +1,5 @@
from qtsymbols import * 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 from traceback import print_exc
import windows, qtawesome, winsharedutils, gobject import windows, qtawesome, winsharedutils, gobject
from webviewpy import webview_native_handle_kind_t, Webview from webviewpy import webview_native_handle_kind_t, Webview
@ -1503,6 +1503,10 @@ class auto_select_webview(QWidget):
on_load = pyqtSignal(str) on_load = pyqtSignal(str)
on_ZoomFactorChanged = pyqtSignal(float) on_ZoomFactorChanged = pyqtSignal(float)
def eval(self, js):
self.internal.eval(js)
self.evals.append(js)
def bind(self, funcname, function): def bind(self, funcname, function):
self.bindinfo.append((funcname, function)) self.bindinfo.append((funcname, function))
self.internal.bind(funcname, function) self.internal.bind(funcname, function)
@ -1527,7 +1531,8 @@ class auto_select_webview(QWidget):
if len(html) < self.internal.html_limit: if len(html) < self.internal.html_limit:
self.internal.setHtml(html) self.internal.setHtml(html)
else: 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: with open(lastcachehtml, "w", encoding="utf8") as ff:
ff.write(html) ff.write(html)
self.internal.navigate(lastcachehtml) self.internal.navigate(lastcachehtml)
@ -1542,6 +1547,7 @@ class auto_select_webview(QWidget):
def __init__(self, parent, dyna=False) -> None: def __init__(self, parent, dyna=False) -> None:
super().__init__(parent) super().__init__(parent)
self.addmenuinfo = [] self.addmenuinfo = []
self.evals = []
self.bindinfo = [] self.bindinfo = []
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
self.internal = None self.internal = None
@ -1571,6 +1577,15 @@ class auto_select_webview(QWidget):
self.internal.on_load.connect(self.on_load) self.internal.on_load.connect(self.on_load)
self.internal.on_ZoomFactorChanged.connect(self.internalzoomchanged) self.internal.on_ZoomFactorChanged.connect(self.internalzoomchanged)
self.layout().addWidget(self.internal) 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: if self.lastaction:
action, arg = self.lastaction action, arg = self.lastaction
if action == 0: if action == 0:
@ -1579,10 +1594,6 @@ class auto_select_webview(QWidget):
self.setHtml(arg) self.setHtml(arg)
else: else:
self.clear() self.clear()
for _ in self.addmenuinfo:
self.internal.add_menu(*_)
for _ in self.bindinfo:
self.internal.bind(*_)
def _createwebview(self): def _createwebview(self):
contex = globalconfig["usewebview"] contex = globalconfig["usewebview"]

View File

@ -275,7 +275,7 @@
}, },
{ {
"name": "unidic", "name": "unidic",
"link": "https://clrd.ninjal.ac.jp/unidic/en/" "link": "https://clrd.ninjal.ac.jp/unidic/"
} }
] ]
}, },