Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Dec 1, 2024
1 parent 377b6a9 commit b6d6058
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cpp/version.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 5 additions & 3 deletions py/LunaTranslator/LunaTranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,16 +948,18 @@ def setdarkandbackdrop(self, widget, dark):
)

@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()
Expand Down
12 changes: 8 additions & 4 deletions py/LunaTranslator/gui/showword.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def onDoubleClicked(self, index: QModelIndex):
if not self.data(index, isWordNode):
return
gobject.baseobject.searchwordW.search_word.emit(
self.itemFromIndex(index).text()
self.itemFromIndex(index).text(), False
)


Expand Down Expand Up @@ -976,7 +976,7 @@ def __init__(self, parent: QWidget):


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)

Expand Down Expand Up @@ -1143,7 +1143,9 @@ def __(idx):
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)
)
Expand Down Expand Up @@ -1201,11 +1203,13 @@ def generate_dictionarys(self):
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)
Expand Down
18 changes: 8 additions & 10 deletions py/LunaTranslator/rendertext/textbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def mouseReleaseEvent(self, event: QMouseEvent):
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
Expand Down Expand Up @@ -111,9 +113,9 @@ def showmenu(self, p):
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:
Expand Down Expand Up @@ -658,13 +660,9 @@ def _add_searchlabel(self, isfenciclick, isshow_fenci, labeli, pos1, word, color
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(
Expand Down
2 changes: 0 additions & 2 deletions py/LunaTranslator/rendertext/webview.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
32 changes: 14 additions & 18 deletions py/LunaTranslator/rendertext/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ def __init__(self, parent) -> None:
)
)
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
)
),
)
Expand All @@ -76,13 +84,14 @@ def __init__(self, parent) -> None:
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
Expand Down Expand Up @@ -190,13 +199,6 @@ def calllunaheightchange(self, h):
)
)

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):
Expand Down Expand Up @@ -269,12 +271,6 @@ def _webview_append(
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"
Expand Down

0 comments on commit b6d6058

Please sign in to comment.