mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-01 10:04:12 +08:00
qweb
This commit is contained in:
parent
cc84f37544
commit
5fa8f1a8a6
@ -22,12 +22,14 @@
|
|||||||
if (!_call)
|
if (!_call)
|
||||||
_call = console.log;
|
_call = console.log;
|
||||||
_call(h)
|
_call(h)
|
||||||
|
window.__resolve_h = h
|
||||||
}
|
}
|
||||||
function safe_calllunaclickedword(word) {
|
function safe_calllunaclickedword(word) {
|
||||||
let _call = window.calllunaclickedword;
|
let _call = window.calllunaclickedword;
|
||||||
if (!_call)
|
if (!_call)
|
||||||
_call = console.log;
|
_call = console.log;
|
||||||
_call(word)
|
_call(word)
|
||||||
|
window.__resolve_word = word
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
@ -242,6 +244,7 @@
|
|||||||
ele.appendChild(ruby)
|
ele.appendChild(ruby)
|
||||||
ele.appendChild(document.createElement('br'))
|
ele.appendChild(document.createElement('br'))
|
||||||
})
|
})
|
||||||
|
safe_calllunaheightchange(document.getElementById(rootdivid).offsetHeight)
|
||||||
|
|
||||||
}
|
}
|
||||||
function _clear_all() {
|
function _clear_all() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from PyQt5.QtWidgets import QWidget
|
from PyQt5.QtWidgets import QWidget
|
||||||
from qtsymbols import *
|
from qtsymbols import *
|
||||||
from rendertext.somefunctions import dataget
|
from rendertext.somefunctions import dataget
|
||||||
import gobject, uuid, json, os
|
import gobject, uuid, json, os, functools
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from myutils.config import globalconfig
|
from myutils.config import globalconfig
|
||||||
from gui.usefulwidget import WebivewWidget, QWebWrap, saveposwindow
|
from gui.usefulwidget import WebivewWidget, QWebWrap, saveposwindow
|
||||||
@ -46,6 +46,7 @@ class TextBrowser(QWidget, dataget):
|
|||||||
self.webivewwidget.bind("calllunaheightchange", self.calllunaheightchange)
|
self.webivewwidget.bind("calllunaheightchange", self.calllunaheightchange)
|
||||||
self.saveiterclasspointer = {}
|
self.saveiterclasspointer = {}
|
||||||
self.isfirst = True
|
self.isfirst = True
|
||||||
|
self._qweb_query_word()
|
||||||
|
|
||||||
def _qwmenu(self, pos):
|
def _qwmenu(self, pos):
|
||||||
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
|
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
|
||||||
@ -71,7 +72,7 @@ class TextBrowser(QWidget, dataget):
|
|||||||
def __init__(_self) -> None:
|
def __init__(_self) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
gobject.baseobject.settin_ui,
|
gobject.baseobject.settin_ui,
|
||||||
poslist=globalconfig["qwebinspectgeo"]
|
poslist=globalconfig["qwebinspectgeo"],
|
||||||
)
|
)
|
||||||
_self.setWindowTitle("Inspect")
|
_self.setWindowTitle("Inspect")
|
||||||
_self.internal = QWebEngineView(_self)
|
_self.internal = QWebEngineView(_self)
|
||||||
@ -125,18 +126,7 @@ class TextBrowser(QWidget, dataget):
|
|||||||
self.debugeval(
|
self.debugeval(
|
||||||
f'create_internal_text("{style}","{styleargs}","{_id}","{text}","{args}");'
|
f'create_internal_text("{style}","{styleargs}","{_id}","{text}","{args}");'
|
||||||
)
|
)
|
||||||
self._qweb_proactive_queryheigh()
|
self._qweb_query_h()
|
||||||
|
|
||||||
def _qweb_proactive_queryheigh(self):
|
|
||||||
if not isinstance(self.webivewwidget, QWebWrap):
|
|
||||||
return
|
|
||||||
|
|
||||||
def __xxx(h):
|
|
||||||
self.calllunaheightchange(h)
|
|
||||||
|
|
||||||
self.webivewwidget.eval(
|
|
||||||
'document.getElementById("luna_root_div").offsetHeight', __xxx
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_internal_rubytext(self, style, styleargs, _id, tag, args):
|
def create_internal_rubytext(self, style, styleargs, _id, tag, args):
|
||||||
tag = quote(json.dumps(tag))
|
tag = quote(json.dumps(tag))
|
||||||
@ -146,18 +136,48 @@ class TextBrowser(QWidget, dataget):
|
|||||||
f'create_internal_rubytext("{style}","{styleargs}","{_id}","{tag}","{args}");'
|
f'create_internal_rubytext("{style}","{styleargs}","{_id}","{tag}","{args}");'
|
||||||
)
|
)
|
||||||
|
|
||||||
self._qweb_proactive_queryheigh()
|
self._qweb_query_h()
|
||||||
|
|
||||||
# js api end
|
# js api end
|
||||||
# native api
|
# native api
|
||||||
|
def _qweb_query_value_callback(self, name, callback):
|
||||||
|
|
||||||
|
def __receiver(callback, value):
|
||||||
|
if not value:
|
||||||
|
return
|
||||||
|
self.webivewwidget.eval(f"{name}=null")
|
||||||
|
callback(value)
|
||||||
|
|
||||||
|
self.webivewwidget.eval(name, functools.partial(__receiver, callback))
|
||||||
|
|
||||||
|
def _qweb_query_h(self):
|
||||||
|
if not isinstance(self.webivewwidget, QWebWrap):
|
||||||
|
return
|
||||||
|
self._qweb_query_value_callback("window.__resolve_h", self.calllunaheightchange)
|
||||||
|
|
||||||
|
def _qweb_query_word(self):
|
||||||
|
if not isinstance(self.webivewwidget, QWebWrap):
|
||||||
|
return
|
||||||
|
t = QTimer(self)
|
||||||
|
t.setInterval(100)
|
||||||
|
|
||||||
|
def __intervaledqueryword():
|
||||||
|
|
||||||
|
self._qweb_query_value_callback(
|
||||||
|
"window.__resolve_word", self.calllunaclickedword
|
||||||
|
)
|
||||||
|
|
||||||
|
t.timeout.connect(__intervaledqueryword)
|
||||||
|
t.timeout.emit()
|
||||||
|
t.start()
|
||||||
|
|
||||||
def calllunaheightchange(self, h):
|
def calllunaheightchange(self, h):
|
||||||
self.contentsChanged.emit(
|
self.contentsChanged.emit(
|
||||||
QSize(self.width(), int(h * self.webivewwidget.get_zoom()))
|
QSize(self.width(), int(h * self.webivewwidget.get_zoom()))
|
||||||
)
|
)
|
||||||
|
|
||||||
def calllunaclickedword(self, packedwordinfo):
|
def calllunaclickedword(self, wordinfo):
|
||||||
gobject.baseobject.clickwordcallback(packedwordinfo, False)
|
gobject.baseobject.clickwordcallback(wordinfo, False)
|
||||||
|
|
||||||
# native api end
|
# native api end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user