From 7321a74d956d30cb719d42d63fea334645f4f319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:12:09 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/cishu/edict.py | 2 +- LunaTranslator/LunaTranslator/cishu/edict2.py | 2 +- LunaTranslator/LunaTranslator/cishu/jisho.py | 7 +- .../LunaTranslator/cishu/linggesi.py | 2 +- .../LunaTranslator/cishu/mojidict.py | 2 +- LunaTranslator/LunaTranslator/cishu/weblio.py | 10 +-- .../LunaTranslator/gui/setting_textinput.py | 9 ++- LunaTranslator/LunaTranslator/gui/showword.py | 69 ++++++++++++------- LunaTranslator/files/anki/back.html | 69 ++++++------------- LunaTranslator/files/anki/front.html | 21 ++---- LunaTranslator/files/anki/style.css | 1 - .../files/defaultconfig/config.json | 2 +- .../files/defaultconfig/static_data.json | 19 +++-- LunaTranslator/files/lang/ar.json | 3 +- LunaTranslator/files/lang/cht.json | 3 +- LunaTranslator/files/lang/cs.json | 3 +- LunaTranslator/files/lang/de.json | 3 +- LunaTranslator/files/lang/en.json | 3 +- LunaTranslator/files/lang/es.json | 3 +- LunaTranslator/files/lang/fr.json | 3 +- LunaTranslator/files/lang/it.json | 3 +- LunaTranslator/files/lang/ja.json | 3 +- LunaTranslator/files/lang/ko.json | 3 +- LunaTranslator/files/lang/nl.json | 3 +- LunaTranslator/files/lang/pl.json | 3 +- LunaTranslator/files/lang/pt.json | 3 +- LunaTranslator/files/lang/ru.json | 3 +- LunaTranslator/files/lang/sv.json | 3 +- LunaTranslator/files/lang/th.json | 3 +- LunaTranslator/files/lang/tr.json | 3 +- LunaTranslator/files/lang/uk.json | 3 +- LunaTranslator/files/lang/vi.json | 3 +- LunaTranslator/files/lang/zh.json | 3 +- plugins/CMakeLists.txt | 2 +- 34 files changed, 140 insertions(+), 137 deletions(-) diff --git a/LunaTranslator/LunaTranslator/cishu/edict.py b/LunaTranslator/LunaTranslator/cishu/edict.py index 33d53565..3a780a64 100644 --- a/LunaTranslator/LunaTranslator/cishu/edict.py +++ b/LunaTranslator/LunaTranslator/cishu/edict.py @@ -38,6 +38,6 @@ class edict(cishubase): x = self.sql.execute( "select word, content from entry where id =?", (_id,) ).fetchone() - saveres.append(x[0] + "
" + re.sub("/EntL.*/", "", x[1][1:])) + saveres.append(x[0] + "
" + re.sub("/EntL.*/", "", x[1][1:])) return "
".join(saveres) diff --git a/LunaTranslator/LunaTranslator/cishu/edict2.py b/LunaTranslator/LunaTranslator/cishu/edict2.py index 550a9a09..817bf243 100644 --- a/LunaTranslator/LunaTranslator/cishu/edict2.py +++ b/LunaTranslator/LunaTranslator/cishu/edict2.py @@ -40,6 +40,6 @@ class edict2(cishubase): srt = argsort(dis) for ii in srt[: self.config["max_num"]]: saveres.append( - savew[ii] + "
" + re.sub("/EntL.*/", "", self.save[savew[ii]][1:]) + savew[ii] + "
" + re.sub("/EntL.*/", "", self.save[savew[ii]][1:]) ) return "
".join(saveres) diff --git a/LunaTranslator/LunaTranslator/cishu/jisho.py b/LunaTranslator/LunaTranslator/cishu/jisho.py index 43a0aa08..7ff9c66a 100644 --- a/LunaTranslator/LunaTranslator/cishu/jisho.py +++ b/LunaTranslator/LunaTranslator/cishu/jisho.py @@ -99,9 +99,4 @@ class jisho(cishubase): ss = re.search('href="https://assets.jisho.org/assets/application(.*)"', html) stl = requests.get(ss.group()[6:-1], proxies=self.proxy).text - return ( - '
link

'.format( - url - ) - + f"{res}" - ) + return f"{res}" diff --git a/LunaTranslator/LunaTranslator/cishu/linggesi.py b/LunaTranslator/LunaTranslator/cishu/linggesi.py index ef3e4dce..044eacbc 100644 --- a/LunaTranslator/LunaTranslator/cishu/linggesi.py +++ b/LunaTranslator/LunaTranslator/cishu/linggesi.py @@ -46,5 +46,5 @@ class linggesi(cishubase): mp[w] = [xx, d] x = sorted(list(mp.keys()), key=lambda x: mp[x][1])[: self.config["max_num"]] - save = [w + "
" + mp[w][0] for w in x] + save = [w + "
" + mp[w][0] for w in x] return "
".join(save) diff --git a/LunaTranslator/LunaTranslator/cishu/mojidict.py b/LunaTranslator/LunaTranslator/cishu/mojidict.py index 1fa8fbcc..362ef8a3 100644 --- a/LunaTranslator/LunaTranslator/cishu/mojidict.py +++ b/LunaTranslator/LunaTranslator/cishu/mojidict.py @@ -628,7 +628,7 @@ class mojidict(cishubase): result = "" try: result += mojiclicksearch(self, word) - result += "
" + result += "
" except: pass try: diff --git a/LunaTranslator/LunaTranslator/cishu/weblio.py b/LunaTranslator/LunaTranslator/cishu/weblio.py index 7da28f87..98cec81c 100644 --- a/LunaTranslator/LunaTranslator/cishu/weblio.py +++ b/LunaTranslator/LunaTranslator/cishu/weblio.py @@ -23,11 +23,5 @@ class weblio(cishubase): xx = re.sub('class="(.*?)"', "", xx) _all.append(xx) - join = "
".join(_all) - if len(join): - return ( - '
link
'.format( - url - ) - + join - ) + join = "
".join(_all) + return join diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput.py b/LunaTranslator/LunaTranslator/gui/setting_textinput.py index 0a0c4598..6d610219 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput.py @@ -443,8 +443,7 @@ def filetranslate(self): [(functools.partial(createdownloadprogress, self), 0)], [], [ - "使用最快翻译而非指定翻译器", - D_getsimpleswitch(globalconfig["embedded"], "as_fast_as_posible"), + "指定翻译器", ( D_getsimplecombobox( alltransvis, @@ -452,9 +451,13 @@ def filetranslate(self): "translator_2", internal=alltrans, ), - 2, + 3, ), ], + [ + "使用最快翻译而非指定翻译器", + D_getsimpleswitch(globalconfig["embedded"], "as_fast_as_posible"), + ], ] return grids diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index 910d35d1..e630714a 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -155,19 +155,16 @@ class AnkiWindow(QWidget): def creattemplatetab(self, baselay): - layout = QHBoxLayout() - layout.setContentsMargins(0, 0, 0, 0) - layout.setSpacing(0) - wid = QWidget() - wid.setLayout(layout) - baselay.addWidget(wid) + spliter = QSplitter() + baselay.addWidget(spliter) edittemptab = LTabWidget() self.previewtab = LTabBar() revertbtn = LPushButton("恢复") revertbtn.clicked.connect(self.loadedits) savebtn = LPushButton("保存") savebtn.clicked.connect(self.saveedits) - layout.addLayout( + + spliter.addWidget( getboxlayout( [ edittemptab, @@ -175,6 +172,7 @@ class AnkiWindow(QWidget): ], lc=QVBoxLayout, margin0=True, + makewidget=True, ) ) @@ -182,11 +180,12 @@ class AnkiWindow(QWidget): self.htmlbrowser.setSizePolicy( QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding ) - layout.addLayout( + spliter.addWidget( getboxlayout( [self.previewtab, self.htmlbrowser], lc=QVBoxLayout, margin0=True, + makewidget=True, ) ) self.fronttext = FQPlainTextEdit() @@ -209,10 +208,17 @@ class AnkiWindow(QWidget): ): object.setPlainText(text) + def makedictionaryHTML(self, dictionarys): + if not dictionarys: + return "" + htmlcontents = "" + for iiii in range(len(dictionarys)): + htmlcontents += f'
{dictionarys[iiii]["content"]}
' + return htmlcontents + def loadfileds(self): word = self.currentword - explain = quote(json.dumps(self.refsearchw.generate_explains())) - + dictionarys = self.refsearchw.generate_dictionarys() remarks = self.remarks.toPlainText() example = self.example.toPlainText() if globalconfig["ankiconnect"]["boldword"]: @@ -226,10 +232,18 @@ class AnkiWindow(QWidget): collect.append(hira["orig"]) example = "".join(collect) ruby = self.ruby + dictionaryInfo = [] + dictionaryJson = {} + for _ in dictionarys: + dictionaryInfo.append( + {"dict": _["dict"], "name": globalconfig["cishu"][_["dict"]]["name"]} + ) + dictionaryJson[_["dict"]] = _["content"] fields = { "word": word, - "rubytext": ruby, - "explain": explain, + "rubytextHtml": ruby, + "dictionaryJson": quote(json.dumps(dictionaryJson)), + "dictionaryInfo": json.dumps(dictionaryInfo, ensure_ascii=False), "example_sentence": example.replace("\n", "
"), "remarks": remarks.replace("\n", "
"), } @@ -275,9 +289,9 @@ class AnkiWindow(QWidget): else: encoded_string3 = "" fields = { - "audio": encoded_string2, - "audio_sentence": encoded_string3, - "image": encoded_string, + "audio_for_word": encoded_string2, + "audio_for_example_sentence": encoded_string3, + "screenshot": encoded_string, } return fields @@ -584,15 +598,23 @@ class AnkiWindow(QWidget): if res != "": item.setText(res) + def makerubyhtml(self, ruby): + if not ruby: + return "" + html = "" + for i in range(len(ruby)): + html += ruby[i]["orig"] + if ruby[i]["orig"] != ruby[i]["hira"]: + html += "" + ruby[i]["hira"] + "" + else: + html += "" + html = "" + html + "" + return html + def reset(self, text): self.currentword = text if text and len(text): - self.ruby = quote( - json.dumps( - gobject.baseobject.parsehira(text), - ensure_ascii=False, - ) - ) + self.ruby = self.makerubyhtml(gobject.baseobject.parsehira(text)) else: self.ruby = "" self.editpath.clear() @@ -905,7 +927,7 @@ class searchwordW(closeashidewindow): self.searchtext.text(), True, gobject.baseobject.audioplayer.timestamp ) - def generate_explains(self): + def generate_dictionarys(self): res = [] tabks = [] for k, v in self.cache_results.items(): @@ -919,9 +941,8 @@ class searchwordW(closeashidewindow): for i in tabks: if i >= thisp: idx += 1 - k = _TR(globalconfig["cishu"][k]["name"]) tabks.append(thisp) - res.insert(idx, {"source": k, "content": v}) + res.insert(idx, {"dict": k, "content": v}) return res def __click_word_search_function(self, word, append): diff --git a/LunaTranslator/files/anki/back.html b/LunaTranslator/files/anki/back.html index efdbf6f8..2d9f8719 100644 --- a/LunaTranslator/files/anki/back.html +++ b/LunaTranslator/files/anki/back.html @@ -1,25 +1,14 @@
-
{{audio}}
-
{{audio_sentence}}
+
{{audio_for_word}}
+
{{audio_for_example_sentence}}
{{ word }}
-
+
{{ rubytextHtml }}
+ -