This commit is contained in:
恍兮惚兮 2024-12-01 16:11:33 +08:00
parent 377b6a9470
commit b6d6058a68
6 changed files with 36 additions and 38 deletions

View File

@ -1,7 +1,7 @@
set(VERSION_MAJOR 6)
set(VERSION_MINOR 9)
set(VERSION_PATCH 3)
set(VERSION_PATCH 4)
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)

View File

@ -948,16 +948,18 @@ class MAINUI:
)
@threader
def clickwordcallback(self, word):
def clickwordcallback(self, word, append=False):
if globalconfig["usewordorigin"] == False:
word = word["orig"]
else:
word = word.get("origorig", word["orig"])
if globalconfig["usecopyword"]:
winsharedutils.clipboard_set(word)
winsharedutils.clipboard_set(
(winsharedutils.clipboard_get() + word) if append else word
)
if globalconfig["usesearchword"]:
self.searchwordW.search_word.emit(word)
self.searchwordW.search_word.emit(word, append)
def __dontshowintaborsetbackdrop(self, widget):
window_flags = widget.windowFlags()

View File

@ -846,7 +846,7 @@ class DynamicTreeModel(QStandardItemModel):
if not self.data(index, isWordNode):
return
gobject.baseobject.searchwordW.search_word.emit(
self.itemFromIndex(index).text()
self.itemFromIndex(index).text(), False
)
@ -976,7 +976,7 @@ class showdiction(LMainWindow):
class searchwordW(closeashidewindow):
search_word = pyqtSignal(str)
search_word = pyqtSignal(str, bool)
show_dict_result = pyqtSignal(float, str, str)
search_word_in_new_window = pyqtSignal(str)
@ -1143,7 +1143,9 @@ class searchwordW(closeashidewindow):
self.tabks = []
self.setCentralWidget(ww)
self.textOutput = auto_select_webview(self, True)
self.textOutput.add_menu(0, _TR("查词"), self.search_word.emit)
self.textOutput.add_menu(
0, _TR("查词"), lambda w: self.search_word.emit(w, False)
)
self.textOutput.add_menu(
1, _TR("在新窗口中查词"), threader(self.search_word_in_new_window.emit)
)
@ -1201,11 +1203,13 @@ class searchwordW(closeashidewindow):
res.insert(idx, {"dict": k, "content": v})
return res
def __click_word_search_function(self, word):
def __click_word_search_function(self, word, append):
self.showNormal()
if self.state != 2:
return
word = word.strip()
if append:
word = self.searchtext.text() + word
self.searchtext.setText(word)
self.search(word)

View File

@ -23,7 +23,9 @@ class Qlabel_c(QLabel):
try:
if self.pr:
if event.button() == Qt.MouseButton.LeftButton:
self.callback()
self.callback(False)
elif event.button() == Qt.MouseButton.RightButton:
self.callback(True)
except:
print_exc()
self.pr = False
@ -111,9 +113,9 @@ class TextBrowser(QWidget, dataget):
menu.addAction(tts)
menu.addSeparator()
menu.addAction(copy)
action = menu.exec(self.mapToGlobal(p))
action = menu.exec(QCursor.pos())
if action == search:
gobject.baseobject.searchwordW.search_word.emit(curr)
gobject.baseobject.searchwordW.search_word.emit(curr, False)
elif action == copy:
winsharedutils.clipboard_set(curr)
elif action == tts:
@ -658,13 +660,9 @@ class TextBrowser(QWidget, dataget):
if isfenciclick:
self.searchmasklabels_clicked[labeli].setGeometry(*pos1)
self.searchmasklabels_clicked[labeli].show()
clickfunction = word.get("clickfunction", None)
if clickfunction:
self.searchmasklabels_clicked[labeli].callback = clickfunction
else:
self.searchmasklabels_clicked[labeli].callback = functools.partial(
gobject.baseobject.clickwordcallback, word
)
self.searchmasklabels_clicked[labeli].callback = functools.partial(
gobject.baseobject.clickwordcallback, word
)
if isshow_fenci and color:
self.searchmasklabels[labeli].setGeometry(*pos1)
self.searchmasklabels[labeli].setStyleSheet(

View File

@ -45,14 +45,12 @@
if (!_call)
_call = console.log;
_call(h)
window.__resolve_h = h
}
function safe_calllunaclickedword(word) {
let _call = window.calllunaclickedword;
if (!_call)
_call = console.log;
_call(word)
window.__resolve_word = word
}
</script>
<script>

View File

@ -54,14 +54,22 @@ class TextBrowser(QWidget, dataget):
)
)
windows.SetWindowLongPtr(webviewhwnd, windows.GWLP_WNDPROC, self.wndproc)
self.webivewwidget.add_menu(0, _TR("朗读"), gobject.baseobject.read_text)
self.webivewwidget.add_menu(0, _TR("翻译"), gobject.baseobject.textgetmethod)
self.webivewwidget.add_menu(
0,
_TR("朗读"),
lambda w: gobject.baseobject.read_text(w.replace("\n", "").strip()),
)
self.webivewwidget.add_menu(
0,
_TR("翻译"),
lambda w: gobject.baseobject.textgetmethod(w.replace("\n", "").strip()),
)
self.webivewwidget.add_menu(
0,
_TR("查词"),
threader(
lambda w: gobject.baseobject.searchwordW.search_word.emit(
w.replace("\n", "").strip()
w.replace("\n", "").strip(), False
)
),
)
@ -76,13 +84,14 @@ class TextBrowser(QWidget, dataget):
self.masklabel_top = QLabel(self)
self.masklabel_top.setMouseTracking(True)
# self.masklabel_bottom.setStyleSheet('background-color:red')
self.saveclickfunction = {}
self.webivewwidget.navigate(
os.path.abspath(r"LunaTranslator\rendertext\webview.html")
)
self.webivewwidget.set_transparent_background()
self.webivewwidget.dropfilecallback.connect(self.dropfilecallback)
self.webivewwidget.bind("calllunaclickedword", self.calllunaclickedword)
self.webivewwidget.bind(
"calllunaclickedword", gobject.baseobject.clickwordcallback
)
self.webivewwidget.bind("calllunaheightchange", self.calllunaheightchange)
self.saveiterclasspointer = {}
self.isfirst = True
@ -190,13 +199,6 @@ class TextBrowser(QWidget, dataget):
)
)
def calllunaclickedword(self, wordinfo):
clickfunction = wordinfo.get("clickfunction", None)
if clickfunction:
self.saveclickfunction.get(clickfunction)()
else:
gobject.baseobject.clickwordcallback(wordinfo)
# native api end
def iter_append(self, iter_context_class, origin, atcenter, name, text, color):
@ -269,12 +271,6 @@ class TextBrowser(QWidget, dataget):
isfenciclick=isfenciclick,
line_height=line_height,
)
for _tag in tag:
clickfunction = _tag.get("clickfunction", None)
if clickfunction:
func = "luna" + str(uuid.uuid4()).replace("-", "_")
_tag["clickfunction"] = func
self.saveclickfunction[func] = clickfunction
self.create_internal_rubytext(style, styleargs, _id, tag, args)
else:
sig = "LUNASHOWHTML"