From 3c1103ab7e84acb364b8e63d22dec91302c20638 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: Wed, 5 Jun 2024 01:59:04 +0800 Subject: [PATCH] .. --- LunaTranslator/LunaTranslator/cishu/mdict.py | 82 ++++++++++++-------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/LunaTranslator/LunaTranslator/cishu/mdict.py b/LunaTranslator/LunaTranslator/cishu/mdict.py index 0114e252..1c626eb4 100644 --- a/LunaTranslator/LunaTranslator/cishu/mdict.py +++ b/LunaTranslator/LunaTranslator/cishu/mdict.py @@ -2283,6 +2283,34 @@ import re class mdict(cishubase): + def getdistance(self, f): + _ = self.extraconf[f] + + distance = _["distance"] + if distance == -1: + distance = self.config["distance"] + return distance + + def gettitle(self, f, index): + _ = self.extraconf[f] + title = _["title"] + if title is None: + t = os.path.basename(f)[:-4] + if index._title.strip() != "": + t1 = index._title.strip() + if (t1.isascii()) and (t.isascii()): + t = t1 + elif not t1.isascii(): + t = t1 + title = t + return title + + def getpriority(self, f): + return self.extraconf[f]["priority"] + + def getFoldFlow(self, f): + return self.extraconf[f]["FoldFlow"] + def init_once_mdx(self, f): if not os.path.isfile(f): return @@ -2296,24 +2324,14 @@ class mdict(cishubase): "distance", -1 ) # -1是跟随mdict全局distance,否则使用私有distance _["title"] = _.get("title", None) # None是使用默认显示名,否则使用自定义显示名 + _["FoldFlow"] = _.get( + "FoldFlow", False + ) # None是使用默认显示名,否则使用自定义显示名 if os.path.exists(f): try: index = IndexBuilder(f) - title = _["title"] - if title is None: - t = os.path.basename(f)[:-4] - if index._title.strip() != "": - t1 = index._title.strip() - if (t1.isascii()) and (t.isascii()): - t = t1 - elif not t1.isascii(): - t = t1 - title = t - distance = _["distance"] - if distance == -1: - distance = self.config["distance"] - self.builders.append((f, index, title, distance, _["priority"])) + self.builders.append((f, index)) except: print(f) @@ -2327,18 +2345,11 @@ class mdict(cishubase): self.extraconf = json.loads(ff.read()) except: self.extraconf = {} - try: - with open("userconfig/mdict_config2.json", "r", encoding="utf8") as ff: - self.extraconf2 = json.loads(ff.read()) - except: - self.extraconf2 = {} self.sql = None paths = self.config["paths"] self.builders = [] self.dedump = set() - self.FoldFlow = self.extraconf2.get("FoldFlow", False) - self.extraconf2["FoldFlow"] = self.FoldFlow for f in paths: if f.strip() == "": continue @@ -2356,11 +2367,6 @@ class mdict(cishubase): ff.write(json.dumps(self.extraconf, ensure_ascii=False, indent=4)) except: pass - try: - with open("userconfig/mdict_config2.json", "w", encoding="utf8") as ff: - ff.write(json.dumps(self.extraconf2, ensure_ascii=False, indent=4)) - except: - pass def querycomplex(self, word, distance, index): results = [] @@ -2701,10 +2707,10 @@ class mdict(cishubase): return allres def searchthread(self, allres, i, word): - f, index, title, distance, priority = self.builders[i] + f, index = self.builders[i] results = [] try: - keys = self.querycomplex(word, distance, index.get_mdx_keys) + keys = self.querycomplex(word, self.getdistance(f), index.get_mdx_keys) # print(keys) for k in keys: __safe = [] @@ -2717,13 +2723,20 @@ class mdict(cishubase): for i in range(len(results)): results[i] = self.repairtarget(index, os.path.dirname(f), results[i]) if len(results): - allres.append((priority, title, "".join(results))) + allres.append( + ( + self.getpriority(f), + self.getFoldFlow(f), + self.gettitle(f, index), + "".join(results), + ) + ) def generatehtml_tabswitch(self, allres): btns = [] contents = [] idx = 0 - for _, title, res in allres: + for _, foldflow, title, res in allres: idx += 1 btns.append( f"""""" @@ -2831,10 +2844,11 @@ if (content.style.display === 'block') { } }""" lis = [] - extra = "display: block;" - if self.FoldFlow: - extra = "display: none;" - for _, title, res in allres: + + for _, foldflow, title, res in allres: + extra = "display: block;" + if foldflow: + extra = "display: none;" uid = str(uuid.uuid4()) lis.append( rf"""