mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
anki自动在例句中加粗原单词 (#765)
* feature: (Anki) automatically highlight words in examples * fix: (Anki) tts with example sentence
This commit is contained in:
parent
db3ff84804
commit
0d033e1b3d
@ -149,8 +149,11 @@ class AnkiWindow(QWidget):
|
|||||||
|
|
||||||
def langdu2(self):
|
def langdu2(self):
|
||||||
if gobject.baseobject.reader:
|
if gobject.baseobject.reader:
|
||||||
|
example_text = self.example.toPlainText()
|
||||||
|
example_text = example_text.replace("<b>", "")
|
||||||
|
example_text = example_text.replace("</b>", "")
|
||||||
gobject.baseobject.reader.ttscallback(
|
gobject.baseobject.reader.ttscallback(
|
||||||
self.example.toPlainText(),
|
example_text,
|
||||||
functools.partial(self.callbacktts, self.audiopath_sentence),
|
functools.partial(self.callbacktts, self.audiopath_sentence),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -737,7 +740,7 @@ class selectviewer(QWidget):
|
|||||||
|
|
||||||
|
|
||||||
class searchwordW(closeashidewindow):
|
class searchwordW(closeashidewindow):
|
||||||
getnewsentencesignal = pyqtSignal(str, bool)
|
getnewsentencesignal = pyqtSignal(str, str, bool)
|
||||||
showtabsignal = pyqtSignal(float, str, str)
|
showtabsignal = pyqtSignal(float, str, str)
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@ -846,16 +849,19 @@ class searchwordW(closeashidewindow):
|
|||||||
res.insert(idx, {"source": k, "content": v})
|
res.insert(idx, {"source": k, "content": v})
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def getnewsentence(self, sentence, append):
|
def getnewsentence(self, sentence, sentence_trans, append):
|
||||||
sentence = sentence.strip()
|
sentence = sentence.strip()
|
||||||
|
sentence_trans = sentence_trans.strip()
|
||||||
self.showNormal()
|
self.showNormal()
|
||||||
if append:
|
if append:
|
||||||
sentence = self.searchtext.text() + sentence
|
sentence = self.searchtext.text() + sentence
|
||||||
self.searchtext.setText(sentence)
|
self.searchtext.setText(sentence)
|
||||||
|
|
||||||
self.search(sentence)
|
self.search(sentence)
|
||||||
|
example_text = gobject.baseobject.currenttext
|
||||||
self.ankiwindow.example.setPlainText(gobject.baseobject.currenttext)
|
if sentence_trans in example_text:
|
||||||
|
example_text = example_text.replace(sentence_trans, f"<b>{sentence_trans}</b>")
|
||||||
|
self.ankiwindow.example.setPlainText(example_text)
|
||||||
if globalconfig["ankiconnect"]["autoruntts"]:
|
if globalconfig["ankiconnect"]["autoruntts"]:
|
||||||
self.ankiwindow.langdu()
|
self.ankiwindow.langdu()
|
||||||
if globalconfig["ankiconnect"]["autoruntts2"]:
|
if globalconfig["ankiconnect"]["autoruntts2"]:
|
||||||
|
@ -238,6 +238,7 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
if hira:
|
if hira:
|
||||||
|
|
||||||
def callback(word, append):
|
def callback(word, append):
|
||||||
|
word_in_sentence = word["orig"]
|
||||||
if globalconfig["usewordorigin"] == False:
|
if globalconfig["usewordorigin"] == False:
|
||||||
word = word["orig"]
|
word = word["orig"]
|
||||||
else:
|
else:
|
||||||
@ -252,7 +253,7 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
winsharedutils.clipboard_set(word)
|
winsharedutils.clipboard_set(word)
|
||||||
if globalconfig["usesearchword"]:
|
if globalconfig["usesearchword"]:
|
||||||
gobject.baseobject.searchwordW.getnewsentencesignal.emit(
|
gobject.baseobject.searchwordW.getnewsentencesignal.emit(
|
||||||
word, append
|
word, word_in_sentence, append
|
||||||
)
|
)
|
||||||
|
|
||||||
self.translate_text.addsearchwordmask(hira, text, callback)
|
self.translate_text.addsearchwordmask(hira, text, callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user