From 95010beaff7217dec3799ae451c099653ba6df1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Fri, 27 Dec 2024 00:18:56 +0800 Subject: [PATCH] . --- py/LunaTranslator/cishu/mdict.py | 2 +- py/LunaTranslator/gui/showword.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/py/LunaTranslator/cishu/mdict.py b/py/LunaTranslator/cishu/mdict.py index 619bd40b78..df8bf4ac5e 100644 --- a/py/LunaTranslator/cishu/mdict.py +++ b/py/LunaTranslator/cishu/mdict.py @@ -2693,7 +2693,7 @@ def text(self): return self.ref.gettitle(self.f, self.index) def childrens(self) -> list: - return self.index.get_mdx_keys("*") + return sorted(list(set(self.index.get_mdx_keys("*")))) class DictTreeRoot(DictTree): def __init__(self, ref) -> None: diff --git a/py/LunaTranslator/gui/showword.py b/py/LunaTranslator/gui/showword.py index c22aa331f2..9565804101 100644 --- a/py/LunaTranslator/gui/showword.py +++ b/py/LunaTranslator/gui/showword.py @@ -831,18 +831,15 @@ def loadChildren(self, index: QModelIndex): self.setData(index, len(childs) > 0, DeterminedhasChildren) thisitem = self.itemFromIndex(index) maketuples = tuple((tuple(_) for _ in globalconfig["wordlabel"])) - dump = set() + rows = [] for c in childs: if isinstance(c, str): - if c in dump: - continue - dump.add(c) t = c has = False else: t = c.text() has = True - item = QStandardItem(t) + item = QStandardItem(t.replace("\n", "")) if has: item.setData(c, DictNodeRole) else: @@ -852,8 +849,9 @@ def loadChildren(self, index: QModelIndex): item.setData( QBrush(Qt.GlobalColor.cyan), Qt.ItemDataRole.BackgroundRole ) - thisitem.appendRow([item]) - self.ref(index) + rows.append(item) + thisitem.appendRows(rows) + self.ref(index, True) def onDoubleClicked(self, index: QModelIndex): if not self.data(index, isWordNode): @@ -874,8 +872,10 @@ def keyPressEvent(self, e: QKeyEvent): class showdiction(QWidget): - def setwordfilter(self, index=None): + def setwordfilter(self, index=None, first=False): w = self.word.text() + if (not w) and first: + return if index is None: item = self.model.invisibleRootItem() index = self.model.indexFromItem(self.model.invisibleRootItem()) @@ -979,7 +979,7 @@ def refresh(self): if len(cishus) == 1: try: for node in cishus[0].tree().childrens(): - item = QStandardItem(node.text()) + item = QStandardItem(node.text().replace("\n", "")) item.setData(node, DictNodeRole) rows.append(item) except: