Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Oct 24, 2024
1 parent 766c0e5 commit 5344ab4
Show file tree
Hide file tree
Showing 31 changed files with 257 additions and 36 deletions.
5 changes: 5 additions & 0 deletions src/LunaTranslator/cishu/cishubase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from myutils.proxy import getproxy


class DictTree:
def text(self) -> str: ...
def childrens(self) -> list: ...


class cishubase:
typename = None

Expand Down
18 changes: 17 additions & 1 deletion src/LunaTranslator/cishu/edict.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sqlite3, os
import winsharedutils, re
from myutils.utils import argsort, autosql
from cishu.cishubase import cishubase
from cishu.cishubase import cishubase, DictTree


class edict(cishubase):
Expand Down Expand Up @@ -41,3 +41,19 @@ def search(self, word):
saveres.append(x[0] + "<hr>" + re.sub("/EntL.*/", "", x[1][1:]))

return "<hr>".join(saveres)

def tree(self):
if not self.sql:
return

class DictTreeRoot(DictTree):
def __init__(self, ref) -> None:
self.ref = ref

def childrens(self):
c = []
for _ in self.ref.sql.execute("select text from surface").fetchall():
c.append(_[0])
return c

return DictTreeRoot(self)
15 changes: 14 additions & 1 deletion src/LunaTranslator/cishu/edict2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from myutils.utils import argsort
from traceback import print_exc
from cishu.cishubase import cishubase
from cishu.cishubase import cishubase, DictTree


class edict2(cishubase):
Expand Down Expand Up @@ -43,3 +43,16 @@ def search(self, word):
savew[ii] + "<hr>" + re.sub("/EntL.*/", "", self.save[savew[ii]][1:])
)
return "<hr>".join(saveres)

def tree(self):
if not self.save:
return

class DictTreeRoot(DictTree):
def __init__(self, ref) -> None:
self.ref = ref

def childrens(self):
return list(self.ref.save.keys())

return DictTreeRoot(self)
20 changes: 19 additions & 1 deletion src/LunaTranslator/cishu/linggesi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sqlite3
import winsharedutils
import os
from cishu.cishubase import cishubase
from cishu.cishubase import cishubase, DictTree


class linggesi(cishubase):
Expand Down Expand Up @@ -48,3 +48,21 @@ def search(self, word):
x = sorted(list(mp.keys()), key=lambda x: mp[x][1])[: self.config["max_num"]]
save = [w + "<hr>" + mp[w][0] for w in x]
return "<hr>".join(save)

def tree(self):
if not self.sql:
return

class DictTreeRoot(DictTree):
def __init__(self, ref) -> None:
self.ref = ref

def childrens(self):
c = []
for _ in self.ref.sql.execute(
"select word from entry"
).fetchall():
c.append(_[0])
return c

return DictTreeRoot(self)
41 changes: 37 additions & 4 deletions src/LunaTranslator/cishu/mdict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math, base64, uuid, gobject
import threading, time
from cishu.cishubase import DictTree


class FlexBuffer:
Expand Down Expand Up @@ -2032,11 +2032,11 @@ def getdistance(self, f):
distance = self.config["distance"]
return distance

def gettitle(self, f, index):
def gettitle(self, f, index: IndexBuilder):
_ = self.extraconf[f]
title = _["title"]
if title is None:
t = os.path.basename(f)[:-4]
t: str = os.path.basename(f)[:-4]
if index._title.strip() != "":
t1 = index._title.strip()
if (t1.isascii()) and (t.isascii()):
Expand Down Expand Up @@ -2086,7 +2086,6 @@ def init(self):
self.extraconf = json.loads(ff.read())
except:
self.extraconf = {}
self.sql = None
paths = self.config["paths"]

self.builders = []
Expand Down Expand Up @@ -2629,3 +2628,37 @@ def search(self, word):
return self.generatehtml_tabswitch(allres)
elif self.config["stylehv"] == 1:
return self.generatehtml_flow(allres)

def tree(self):
if len(self.builders) == 0:
return

class everydict(DictTree):
def __init__(self, ref, f, index: IndexBuilder) -> None:
self.f = f
self.index = index
self.ref = ref

def text(self):
return self.ref.gettitle(self.f, self.index)

def childrens(self) -> list:
return self.index.get_mdx_keys("*")

class DictTreeRoot(DictTree):
def __init__(self, ref) -> None:
self.ref = ref

def childrens(self):
saves = []
for f, index in self.ref.builders:
saves.append(
(self.ref.getpriority(f), everydict(self.ref, f, index))
)
saves.sort(key=lambda x: x[0])
i = []
for _, _i in saves:
i.append(_i)
return i

return DictTreeRoot(self)
21 changes: 19 additions & 2 deletions src/LunaTranslator/cishu/xiaoxueguan.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sqlite3, os, re
import winsharedutils
from myutils.utils import argsort, autosql

from cishu.cishubase import cishubase
from cishu.cishubase import cishubase, DictTree


class xiaoxueguan(cishubase):
Expand Down Expand Up @@ -48,3 +47,21 @@ def search(self, word: str):
srt = argsort(dis)[: self.config["max_num"]]
save = ["<span h>" + exp[i][1].replace("\\n", "") for i in srt]
return "<hr>".join(save)

def tree(self):
if not self.sql:
return

class DictTreeRoot(DictTree):
def __init__(self, ref) -> None:
self.ref = ref

def childrens(self):
c = []
for _ in self.ref.sql.execute(
"select word from xiaoxueguanrizhong"
).fetchall():
c.append(_[0])
return c

return DictTreeRoot(self)
2 changes: 0 additions & 2 deletions src/LunaTranslator/gui/dialog_savedgame_v3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget
from qtsymbols import *
import os, functools, uuid, threading, shutil, time
from traceback import print_exc
Expand Down
7 changes: 7 additions & 0 deletions src/LunaTranslator/gui/setting_cishu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
auto_select_webview,
)
from gui.setting_display_text import on_not_find_qweb
from gui.showword import showdiction


def setTabcishu(self, basel):
Expand Down Expand Up @@ -220,6 +221,10 @@ def setTabcishu_l(self):
lambda: gobject.baseobject.searchwordW.showsignal.emit(),
"fa.search",
),
D_getIconButton(
lambda: showdiction(self).show(),
"fa.book",
),
"",
"辞书显示顺序",
D_getIconButton(
Expand All @@ -235,12 +240,14 @@ def setTabcishu_l(self):
1,
),
"",
"",
("点击单词复制"),
(
D_getsimpleswitch(globalconfig, "usecopyword"),
1,
),
"",
"",
("使用原型查询"),
(
D_getsimpleswitch(globalconfig, "usewordorigin"),
Expand Down
96 changes: 95 additions & 1 deletion src/LunaTranslator/gui/showword.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
saveposwindow,
tabadd_lazy,
)
from gui.dynalang import LPushButton, LLabel, LTabWidget, LTabBar, LFormLayout, LLabel
from gui.dynalang import (
LPushButton,
LLabel,
LTabWidget,
LTabBar,
LFormLayout,
LLabel,
LMainWindow,
)


def getimageformatlist():
Expand Down Expand Up @@ -750,6 +758,92 @@ def sizeHint(self):
return self.savesizehint


from cishu.cishubase import DictTree

DictNodeRole = Qt.ItemDataRole.UserRole + 1
DeterminedhasChildren = DictNodeRole + 1
isWordNode = DeterminedhasChildren + 1


class DynamicTreeModel(QStandardItemModel):
def __init__(self):
super().__init__()

def hasChildren(self, index):
if self.data(index, isWordNode):
return False
_DeterminedhasChildren = self.data(index, DeterminedhasChildren)
if _DeterminedhasChildren is not None:
return _DeterminedhasChildren
return self.data(index, DictNodeRole) is not None

def loadChildren(self, index: QModelIndex):
if not index.isValid():
return
if self.data(index, isWordNode):
return
if self.data(index, DeterminedhasChildren) is not None:
return
node: DictTree = self.data(index, DictNodeRole)
if not node:
return
childs = node.childrens()
self.setData(index, len(childs) > 0, DeterminedhasChildren)
thisitem = self.itemFromIndex(index)
for c in childs:
if isinstance(c, str):
t = c
has = False
else:
t = c.text()
has = True
item = QStandardItem(t)
if has:
item.setData(c, DictNodeRole)
else:
item.setData(True, isWordNode)
thisitem.appendRow([item])

def onDoubleClicked(self, index: QModelIndex):
if not self.data(index, isWordNode):
return
gobject.baseobject.searchwordW.search_word.emit(self.itemFromIndex(index).text(), False)

class showdiction(LMainWindow):
def __init__(self, parent):
super(showdiction, self).__init__(parent)
self.resize(400, parent.height())
self.setWindowTitle("查看")
self.tree = QTreeView(self)
self.tree.setHeaderHidden(True)
self.tree.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
self.setCentralWidget(self.tree)

self.model = DynamicTreeModel()
self.tree.setModel(self.model)
self.tree.expanded.connect(self.model.loadChildren)
root = self.model.invisibleRootItem()
self.tree.doubleClicked.connect(self.model.onDoubleClicked)
good = False
for k in globalconfig["cishuvisrank"]:
cishu = gobject.baseobject.cishus[k]

if not hasattr(cishu, "tree"):
continue
try:
tree = cishu.tree()
except:
continue
if not tree:
continue

item = QStandardItem(globalconfig["cishu"][k]["name"])
item.setData(tree, DictNodeRole)
root.appendRow([item])
good = True
root.setData(good, DeterminedhasChildren)


class searchwordW(closeashidewindow):
search_word = pyqtSignal(str, bool)
show_dict_result = pyqtSignal(float, str, str)
Expand Down
4 changes: 2 additions & 2 deletions src/LunaTranslator/qtsymbols.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
try:
from PyQt5 import QtSvg
from PyQt5.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QAction,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider,QToolTip,QGroupBox,QGraphicsOpacityEffect,QStackedWidget,QStyledItemDelegate,QStyleOptionViewItem,QFontDialog
from PyQt5.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QAction,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider,QToolTip,QGroupBox,QGraphicsOpacityEffect,QStackedWidget,QStyledItemDelegate,QStyleOptionViewItem,QFontDialog,QTreeView
from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent,QTextLayout, QTextOption,QDragEnterEvent, QDropEvent,QTransform
from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl,QPropertyAnimation,QLocale,QSignalBlocker
isqt5 = True
Expand All @@ -11,7 +11,7 @@ class LineHeightTypes:
#from traceback import print_exc
#print_exc()
from PyQt6 import QtSvg
from PyQt6.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider,QToolTip,QGroupBox,QGraphicsOpacityEffect,QStackedWidget
from PyQt6.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider,QToolTip,QGroupBox,QGraphicsOpacityEffect,QStackedWidget,QTreeView
from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent,QTextLayout, QTextOption
from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation,QUrl,QPropertyAnimation,QLocale
isqt5 = False
Expand Down
3 changes: 2 additions & 1 deletion src/files/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,5 +810,6 @@
"百度翻译开放平台": "بايدو ترجمة منصة مفتوحة",
"百度智能云": "بايدو سحابة ذكية",
"(支持gpt词典)": "( دعم قاموس GPT )",
"日志": "سجل ."
"日志": "سجل .",
"查看": "عرض ."
}
3 changes: 2 additions & 1 deletion src/files/lang/cht.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,5 +810,6 @@
"百度翻译开放平台": "百度翻譯開放平台",
"百度智能云": "百度智慧雲",
"(支持gpt词典)": "(支援 GPT 詞典)",
"日志": "日誌"
"日志": "日誌",
"查看": "查看"
}
3 changes: 2 additions & 1 deletion src/files/lang/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,5 +810,6 @@
"百度翻译开放平台": "Baidu Translation Open Platform",
"百度智能云": "Cloud AI Baidu",
"(支持gpt词典)": "(Podporuje GPT slovník)",
"日志": "deník"
"日志": "deník",
"查看": "viz"
}
3 changes: 2 additions & 1 deletion src/files/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,5 +810,6 @@
"百度翻译开放平台": "Baidu Translation Open Platform",
"百度智能云": "Baidu AI Cloud",
"(支持gpt词典)": "(Unterstützt GPT Wörterbuch)",
"日志": "Journal"
"日志": "Journal",
"查看": "siehe"
}
Loading

0 comments on commit 5344ab4

Please sign in to comment.