1
This commit is contained in:
恍兮惚兮 2024-04-10 23:24:35 +08:00
parent e45d650697
commit 77b48845a1
26 changed files with 516 additions and 56 deletions

View File

@ -1,4 +1,4 @@
import functools, time import functools, time, qtawesome
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QPushButton, QPushButton,
QDialog, QDialog,
@ -32,7 +32,16 @@ from PyQt5.QtWidgets import (
QAction, QAction,
QTabBar, QTabBar,
) )
from PyQt5.QtGui import QIntValidator, QResizeEvent, QPixmap, QPainter from PyQt5.QtGui import (
QCloseEvent,
QIntValidator,
QPaintEvent,
QResizeEvent,
QPixmap,
QPainter,
QPen,
QColor,
)
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from gui.usefulwidget import ( from gui.usefulwidget import (
getsimplecombobox, getsimplecombobox,
@ -117,11 +126,11 @@ class ItemWidget(QWidget):
# margin = ( # margin = (
# self.itemw - self.imgw # self.itemw - self.imgw
# ) // 2 # globalconfig['dialog_savegame_layout']['margin'] # ) // 2 # globalconfig['dialog_savegame_layout']['margin']
margin=globalconfig["dialog_savegame_layout"]["margin"] margin = globalconfig["dialog_savegame_layout"]["margin"]
textH=globalconfig["dialog_savegame_layout"]["textH"] textH = globalconfig["dialog_savegame_layout"]["textH"]
self.imgw = self.itemw-2*margin self.imgw = self.itemw - 2 * margin
self.imgh = self.itemh-textH-2*margin self.imgh = self.itemh - textH - 2 * margin
# #
self.setFixedSize(QSize(self.itemw, self.itemh)) self.setFixedSize(QSize(self.itemw, self.itemh))
self.setFocusPolicy(Qt.StrongFocus) self.setFocusPolicy(Qt.StrongFocus)
self.maskshowfileexists = QLabel(self) self.maskshowfileexists = QLabel(self)
@ -129,11 +138,11 @@ class ItemWidget(QWidget):
layout = QVBoxLayout() layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
self._img = IMGWidget(self.imgw, self.imgh, pixmap) self._img = IMGWidget(self.imgw, self.imgh, pixmap)
_w=QWidget() _w = QWidget()
_w.setStyleSheet('background-color: rgba(255,255,255, 0);') _w.setStyleSheet("background-color: rgba(255,255,255, 0);")
wrap=QVBoxLayout() wrap = QVBoxLayout()
_w.setLayout(wrap) _w.setLayout(wrap)
_w.setFixedHeight(self.imgh+2*margin) _w.setFixedHeight(self.imgh + 2 * margin)
wrap.setContentsMargins(margin, margin, margin, margin) wrap.setContentsMargins(margin, margin, margin, margin)
wrap.addWidget(self._img) wrap.addWidget(self._img)
layout.addWidget(_w) layout.addWidget(_w)
@ -186,13 +195,14 @@ class IMGWidget(QLabel):
pixmap = QPixmap(self.size()) pixmap = QPixmap(self.size())
pixmap.fill(Qt.transparent) pixmap.fill(Qt.transparent)
painter = QPainter(pixmap) painter = QPainter(pixmap)
painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.setRenderHint(QPainter.SmoothPixmapTransform)
painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QPainter.Antialiasing)
painter.drawPixmap(self.getrect(), self.pix) painter.drawPixmap(self.getrect(), self.pix)
painter.end() painter.end()
self.setPixmap(pixmap) self.setPixmap(pixmap)
self.setFixedSize(pixmap.size()) self.setFixedSize(pixmap.size())
def getrect(self): def getrect(self):
size = self.adaptsize(self.pix.size()) size = self.adaptsize(self.pix.size())
rect = QRect() rect = QRect()
@ -525,6 +535,14 @@ class browserdialog(QDialog):
self.browser.navigate(link) self.browser.navigate(link)
def getvndbrealtags(vndbtags_naive):
vndbtags = []
for tagid in vndbtags_naive:
if tagid in globalconfig["vndbcache"]["tagid2name"]:
vndbtags.append(globalconfig["vndbcache"]["tagid2name"][tagid])
return vndbtags
@Singleton @Singleton
class dialog_setting_game(QDialog): class dialog_setting_game(QDialog):
def selectexe(self): def selectexe(self):
@ -611,7 +629,7 @@ class dialog_setting_game(QDialog):
vndbid.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) vndbid.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
vndbid.textEdited.connect(functools.partial(vidchangedtask, exepath)) vndbid.textEdited.connect(functools.partial(vidchangedtask, exepath))
statiswids = [ statiswids = [
QLabel(_TR("统计信息")), QLabel(_TR("统计信息")),
getcolorbutton( getcolorbutton(
@ -630,6 +648,13 @@ class dialog_setting_game(QDialog):
icon="fa.book", icon="fa.book",
constcolor="#FF69B4", constcolor="#FF69B4",
), ),
getcolorbutton(
"",
"",
lambda: vidchangedtask(exepath, savehook_new_data[exepath]["vid"]),
icon="fa.refresh",
constcolor="#FF69B4",
),
] ]
formLayout.addLayout(getboxlayout(statiswids)) formLayout.addLayout(getboxlayout(statiswids))
editpath = QLineEdit(exepath) editpath = QLineEdit(exepath)
@ -725,10 +750,65 @@ class dialog_setting_game(QDialog):
methodtab.addTab(self.gethooktab(exepath), "HOOK") methodtab.addTab(self.gethooktab(exepath), "HOOK")
methodtab.addTab(self.getpretranstab(exepath), _TR("预翻译")) methodtab.addTab(self.getpretranstab(exepath), _TR("预翻译"))
methodtab.addTab(self.getttssetting(exepath), _TR("语音")) methodtab.addTab(self.getttssetting(exepath), _TR("语音"))
methodtab.addTab(self.getlabelsetting(exepath), _TR("标签"))
formLayout.addWidget(methodtab) formLayout.addWidget(methodtab)
self.show() self.show()
def getlabelsetting(self, exepath):
_w = QWidget()
formLayout = QVBoxLayout()
# formLayout.setAlignment(Qt.AlignTop)
_w.setLayout(formLayout)
formLayout.setContentsMargins(0, 0, 0, 0)
self.labelflow = ScrollFlow()
def newitem(text, removeable):
qw = tagitem(text, removeable)
def __(_qw, t):
_qw.remove()
i = savehook_new_data[exepath]["usertags"].index(t)
self.labelflow.removeidx(i)
savehook_new_data[exepath]["usertags"].remove(t)
if removeable:
qw.removesignal.connect(functools.partial(__, qw))
def _lbclick(t):
self.parent().tagswidget.addTag(t)
qw.labelclicked.connect(_lbclick)
self.labelflow.addwidget(qw)
for tag in savehook_new_data[exepath]["usertags"]:
newitem(tag, True)
for tag in getvndbrealtags(savehook_new_data[exepath]["vndbtags"]):
newitem(tag, False)
formLayout.addWidget(self.labelflow)
_dict = {"new": 0}
formLayout.addWidget(self.labelflow)
button = QPushButton(_TR("添加"))
def _add(_):
tag = globalconfig["labelset"][_dict["new"]]
if tag not in savehook_new_data[exepath]["usertags"]:
savehook_new_data[exepath]["usertags"].append(tag)
newitem(tag, True)
button.clicked.connect(_add)
formLayout.addLayout(
getboxlayout(
[
getsimplecombobox(globalconfig["labelset"], _dict, "new"),
button,
]
)
)
return _w
def getttssetting(self, exepath): def getttssetting(self, exepath):
_w = QWidget() _w = QWidget()
formLayout = QVBoxLayout() formLayout = QVBoxLayout()
@ -922,8 +1002,8 @@ class dialog_syssetting(QDialog):
("itemh", "高度"), ("itemh", "高度"),
# ("imgw", "图片宽度"), # ("imgw", "图片宽度"),
# ("imgh", "图片高度"), # ("imgh", "图片高度"),
('margin','边距'), ("margin", "边距"),
('textH','文字区高度') ("textH", "文字区高度"),
]: ]:
formLayout.addRow( formLayout.addRow(
(_TR(name)), (_TR(name)),
@ -1013,6 +1093,7 @@ class dialog_statistic(QDialog):
threading.Thread(target=self.refresh).start() threading.Thread(target=self.refresh).start()
@threader
def startgame(game): def startgame(game):
try: try:
if os.path.exists(game): if os.path.exists(game):
@ -1096,6 +1177,199 @@ def startgame(game):
print_exc() print_exc()
@Singleton_close
class labelsetedit(QDialog):
def __init__(self, p) -> None:
super().__init__(p)
try:
self.setWindowTitle(_TR("标签集"))
model = QStandardItemModel()
model.setHorizontalHeaderLabels(
_TRL(
[
"删除",
"标签",
]
)
)
self.hcmodel = model
table = QTableView()
table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
table.horizontalHeader().setStretchLastSection(True)
# table.setEditTriggers(QAbstractItemView.NoEditTriggers);
table.setSelectionBehavior(QAbstractItemView.SelectRows)
table.setSelectionMode((QAbstractItemView.SingleSelection))
table.setWordWrap(False)
table.setModel(model)
self.hctable = table
for row, k in enumerate(globalconfig["labelset"]): # 2
self.newline(row, k)
formLayout = QVBoxLayout()
formLayout.addWidget(self.hctable)
button = QPushButton(_TR("添加行"))
button.clicked.connect(lambda _: self.newline(0, ""))
formLayout.addWidget(button)
self.setLayout(formLayout)
self.show()
except:
print_exc()
def clicked2(self):
try:
globalconfig["labelset"].pop(self.hctable.currentIndex().row())
self.hcmodel.removeRow(self.hctable.currentIndex().row())
except:
pass
def closeEvent(self, a0: QCloseEvent) -> None:
rows = self.hcmodel.rowCount()
rowoffset = 0
dedump = set()
globalconfig["labelset"].clear()
for row in range(rows):
k = self.hcmodel.item(row, 1).text()
if k == "" or k in dedump:
rowoffset += 1
continue
globalconfig["labelset"].append(k)
dedump.add(k)
def newline(self, row, k):
self.hcmodel.insertRow(row, [QStandardItem(), QStandardItem(k)])
self.hctable.setIndexWidget(
self.hcmodel.index(row, 0),
getcolorbutton(
"", "", self.clicked2, icon="fa.times", constcolor="#FF69B4"
),
)
class ClickableLabel(QLabel):
def __init__(self, parent=None):
super().__init__(parent)
self.setClickable(True)
def setClickable(self, clickable):
self._clickable = clickable
def mousePressEvent(self, event):
if self._clickable and event.button() == Qt.LeftButton:
self.clicked.emit()
clicked = pyqtSignal()
class tagitem(QWidget):
removesignal = pyqtSignal(str)
labelclicked = pyqtSignal(str)
def remove(self):
self.hide()
_lay = self.layout()
_ws = []
for i in range(_lay.count()):
witem = _lay.itemAt(i)
_ws.append(witem.widget())
for w in _ws:
_lay.removeWidget(w)
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
border_color = Qt.black
border_width = 1
pen = QPen(border_color)
pen.setWidth(border_width)
painter.setPen(pen)
painter.drawRect(self.rect())
def __init__(self, tag, removeable=True) -> None:
super().__init__()
tagLayout = QHBoxLayout()
tagLayout.setContentsMargins(0, 0, 0, 0)
self.setLayout(tagLayout)
lb = ClickableLabel(tag)
lb.clicked.connect(lambda: self.labelclicked.emit(tag))
tagLayout.addWidget(lb)
if removeable:
button = getcolorbutton(
None,
None,
lambda: self.removesignal.emit(tag), # self.removeTag(tag),
qicon=qtawesome.icon(
"fa.times",
color="#FF69B4",
),
sizefixed=True,
)
tagLayout.addWidget(button)
class TagWidget(QWidget):
tagschanged = pyqtSignal(tuple)
def __init__(self, parent=None):
super().__init__(parent)
self.tags = []
layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(QLabel(_TR("标签")))
self.setLayout(layout)
self.lineEdit = QLineEdit()
self.lineEdit.returnPressed.connect(lambda: self.addTag(self.lineEdit.text()))
layout.addWidget(self.lineEdit)
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.tag2widget = {}
layout.addWidget(
getcolorbutton(
"",
"",
lambda _: labelsetedit(parent),
icon="fa.gear",
constcolor="#FF69B4",
),
)
def addTag(self, tag):
try:
if not tag:
return
if tag in self.tag2widget:
return
self.tags.append(tag)
qw = tagitem(tag)
qw.removesignal.connect(self.removeTag)
layout = self.layout()
# layout.insertLayout(layout.count() - 1, tagLayout)
layout.insertWidget(layout.count() - 2, qw)
self.tag2widget[tag] = qw
self.lineEdit.clear()
self.lineEdit.setFocus()
self.tagschanged.emit(tuple(self.tag2widget.keys()))
except:
print_exc()
def removeTag(self, tag):
_w = self.tag2widget[tag]
_w.remove()
self.layout().removeWidget(_w)
self.tag2widget.pop(tag)
self.lineEdit.setFocus()
self.tagschanged.emit(tuple(self.tag2widget.keys()))
@Singleton_close @Singleton_close
class dialog_savedgame_new(saveposwindow): class dialog_savedgame_new(saveposwindow):
def startgame(self, game): def startgame(self, game):
@ -1143,6 +1417,35 @@ class dialog_savedgame_new(saveposwindow):
if len(savehook_new_list): if len(savehook_new_list):
self.flow.l._item_list[0].widget().setFocus() self.flow.l._item_list[0].widget().setFocus()
def tagschanged(self, tags):
checkexists = _TR("存在") in tags
if checkexists:
_ = list(tags)
_.remove(_TR("存在"))
tags = tuple(_)
self.formLayout.removeWidget(self.flow)
self.idxsave.clear()
self.flow = ScrollFlow()
self.formLayout.insertWidget(self.formLayout.count() - 1, self.flow)
for k in savehook_new_list:
if checkexists and os.path.exists(k) == False:
continue
# print(vndbtags)
notshow = False
for tag in tags:
if (
tag not in getvndbrealtags(savehook_new_data[k]["vndbtags"])
and tag not in savehook_new_data[k]["usertags"]
):
notshow = True
break
if notshow:
continue
self.newline(k)
self.idxsave.append(k)
QApplication.processEvents()
def __init__(self, parent) -> None: def __init__(self, parent) -> None:
super().__init__( super().__init__(
parent, parent,
@ -1153,11 +1456,14 @@ class dialog_savedgame_new(saveposwindow):
self.setWindowTitle(_TR("已保存游戏")) self.setWindowTitle(_TR("已保存游戏"))
if globalconfig["showintab_sub"]: if globalconfig["showintab_sub"]:
showintab(int(self.winId()), True) showintab(int(self.winId()), True)
formLayout = QVBoxLayout() # formLayout = QVBoxLayout()
self.tagswidget = TagWidget(self)
self.tagswidget.tagschanged.connect(self.tagschanged)
formLayout.addWidget(self.tagswidget)
self.flow = ScrollFlow() self.flow = ScrollFlow()
formLayout.addWidget(self.flow) formLayout.addWidget(self.flow)
self.formLayout = formLayout
buttonlayout = QHBoxLayout() buttonlayout = QHBoxLayout()
self.buttonlayout = buttonlayout self.buttonlayout = buttonlayout
self.savebutton = [] self.savebutton = []
@ -1178,14 +1484,10 @@ class dialog_savedgame_new(saveposwindow):
self.itemfocuschanged(False, None) self.itemfocuschanged(False, None)
self.show() self.show()
self.idxsave = [] self.idxsave = []
for i, k in enumerate(savehook_new_list): if globalconfig["hide_not_exists"]:
if globalconfig["hide_not_exists"] and os.path.exists(k) == False: self.tagswidget.addTag(_TR("存在"))
continue else:
self.newline(k) self.tagschanged(tuple())
self.idxsave.append(k)
if i == 0:
self.top1focus()
QApplication.processEvents()
def showsettingdialog(self): def showsettingdialog(self):
idx = self.idxsave.index(self.currentfocuspath) idx = self.idxsave.index(self.currentfocuspath)

View File

@ -141,6 +141,10 @@ def setTabcishu_l(self):
("点击单词复制", 5), ("点击单词复制", 5),
(getsimpleswitch(globalconfig, "usecopyword"), 1), (getsimpleswitch(globalconfig, "usecopyword"), 1),
], ],
[
("使用原型查询", 5),
(getsimpleswitch(globalconfig, "usewordorigin"), 1),
],
[], [],
[("辞书", 10)], [("辞书", 10)],
] ]

View File

@ -490,7 +490,7 @@ class Textbrowser:
) )
if callback: if callback:
self.searchmasklabels_clicked[labeli].callback = ( self.searchmasklabels_clicked[labeli].callback = (
functools.partial(callback, (word["orig"])) functools.partial(callback, (word))
) )
self.searchmasklabels_clicked[labeli + 1].setGeometry( self.searchmasklabels_clicked[labeli + 1].setGeometry(
@ -503,9 +503,7 @@ class Textbrowser:
if callback: if callback:
self.searchmasklabels_clicked[ self.searchmasklabels_clicked[
labeli + 1 labeli + 1
].callback = functools.partial( ].callback = functools.partial(callback, (word))
callback, (word["orig"])
)
if globalconfig["show_fenci"]: if globalconfig["show_fenci"]:
self.searchmasklabels[labeli].setGeometry(*pos1) self.searchmasklabels[labeli].setGeometry(*pos1)
@ -540,7 +538,7 @@ class Textbrowser:
self.searchmasklabels_clicked[labeli].show() self.searchmasklabels_clicked[labeli].show()
if callback: if callback:
self.searchmasklabels_clicked[labeli].callback = ( self.searchmasklabels_clicked[labeli].callback = (
functools.partial(callback, (word["orig"])) functools.partial(callback, word)
) )
if globalconfig["show_fenci"]: if globalconfig["show_fenci"]:
self.searchmasklabels[labeli].setGeometry(*pos1) self.searchmasklabels[labeli].setGeometry(*pos1)

View File

@ -273,6 +273,11 @@ class QUnFrameWindow(resizableframeless):
) and hira: ) and hira:
def callback(word): def callback(word):
if globalconfig["usewordorigin"] == False:
word = word["orig"]
else:
word = word.get("origorig", word["orig"])
if globalconfig["usecopyword"]: if globalconfig["usecopyword"]:
winsharedutils.clipboard_set(word) winsharedutils.clipboard_set(word)
if globalconfig["usesearchword"]: if globalconfig["usesearchword"]:

View File

@ -6,6 +6,7 @@ from PyQt5.QtWidgets import (
QMessageBox, QMessageBox,
QDialog, QDialog,
QLabel, QLabel,
QSizePolicy,
QHBoxLayout, QHBoxLayout,
) )
from PyQt5.QtGui import QCursor, QCloseEvent, QColor, QTextCursor from PyQt5.QtGui import QCursor, QCloseEvent, QColor, QTextCursor
@ -435,12 +436,16 @@ def getcolorbutton(
enable=True, enable=True,
transparent=True, transparent=True,
qicon=None, qicon=None,
sizefixed=False,
): ):
if qicon is None: if qicon is None:
qicon = qtawesome.icon(icon, color=constcolor if constcolor else d[key]) qicon = qtawesome.icon(icon, color=constcolor if constcolor else d[key])
b = QPushButton(qicon, "") b = QPushButton()
b.setIcon(qicon)
b.setEnabled(enable) b.setEnabled(enable)
b.setIconSize(QSize(20, 20)) b.setIconSize(QSize(20, 20))
if sizefixed:
b.setFixedSize(QSize(20, 20))
if transparent: if transparent:
b.setStyleSheet( b.setStyleSheet(
"""background-color: rgba(255, 255, 255, 0); """background-color: rgba(255, 255, 255, 0);
@ -449,6 +454,7 @@ def getcolorbutton(
font: 100 10pt;""" font: 100 10pt;"""
) )
b.clicked.connect(callback) b.clicked.connect(callback)
b.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
if name: if name:
setattr(parent, name, b) setattr(parent, name, b)
return b return b
@ -474,7 +480,7 @@ def getsimpleswitch(
b = MySwitch(sign=d[key], enable=enable) b = MySwitch(sign=d[key], enable=enable)
b.clicked.connect(functools.partial(callbackwrap, d, key, callback)) b.clicked.connect(functools.partial(callbackwrap, d, key, callback))
b.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
if pair: if pair:
if pair not in dir(parent): if pair not in dir(parent):
setattr(parent, pair, {}) setattr(parent, pair, {})

View File

@ -20,6 +20,9 @@ class hira:
for node, fields in self.kks.parse( for node, fields in self.kks.parse(
text, codec text, codec
): # self.kks.parseToNodeList(text): ): # self.kks.parseToNodeList(text):
kana = ""
pos1 = ""
origorig = None
if len(fields): if len(fields):
pos1 = fields[0] pos1 = fields[0]
if len(fields) > 29: if len(fields) > 29:
@ -28,26 +31,30 @@ class hira:
kana = fields[20] kana = fields[20]
elif 29 > len(fields) >= 26: elif 29 > len(fields) >= 26:
kana = fields[17] kana = fields[17]
origorig = fields[7]
elif len(fields) > 9: elif len(fields) > 9:
kana = fields[9] # 无kana用lform代替 kana = fields[9] # 无kana用lform代替
elif len(fields) == 9: elif len(fields) == 9:
kana = fields[8] # 7/8均可issues/514 kana = fields[8] # 7/8均可issues/514
else: else:
kana = "" kana = ""
else: if len(fields) >= 8:
kana = "" origorig = fields[7] # unsafe
pos1 = ""
l = 0 l = 0
if text[start] == "\n": if text[start] == "\n":
start += 1 start += 1
while str(node) not in text[start : start + l]: while str(node) not in text[start : start + l]:
l += 1 l += 1
orig = text[start : start + l] orig = text[start : start + l]
if origorig is None:
origorig = orig
start += l start += l
hira = kana # .translate(self.h2k) hira = kana # .translate(self.h2k)
if hira == "*": if hira == "*":
hira = "" hira = ""
# print(node.feature) # print(node.feature)
result.append({"orig": orig, "hira": hira, "cixing": pos1}) result.append(
{"orig": orig, "hira": hira, "cixing": pos1, "origorig": origorig}
)
return result return result

View File

@ -86,6 +86,8 @@ def getdefaultsavehook(gamepath, title=None):
"gamejsonfile": "", "gamejsonfile": "",
"gamesqlitefile": "", "gamesqlitefile": "",
"gamexmlfile": "", "gamexmlfile": "",
"vndbtags": [],
"usertags": [],
} }
if gamepath == "0": if gamepath == "0":
default["title"] = "No Game" default["title"] = "No Game"

View File

@ -125,9 +125,10 @@ def everymethodsthread():
vid = data.get("vid", None) vid = data.get("vid", None)
title = data.get("title", None) title = data.get("title", None)
namemap = data.get("namemap", None) namemap = data.get("namemap", None)
vndbtags = data.get("vndbtags", None)
if not vid: if not vid:
continue continue
print(data)
savehook_new_data[gamepath]["vid"] = int(vid[1:]) savehook_new_data[gamepath]["vid"] = int(vid[1:])
if saveimg and (not savehook_new_data[gamepath]["isimagepathusersetted"]): if saveimg and (not savehook_new_data[gamepath]["isimagepathusersetted"]):
savehook_new_data[gamepath]["imagepath"] = saveimg savehook_new_data[gamepath]["imagepath"] = saveimg
@ -137,7 +138,9 @@ def everymethodsthread():
savehook_new_data[gamepath]["infopath"] = saveinfo savehook_new_data[gamepath]["infopath"] = saveinfo
if namemap: if namemap:
savehook_new_data[gamepath]["namemap"] = namemap savehook_new_data[gamepath]["namemap"] = namemap
print(namemap) if vndbtags:
savehook_new_data[gamepath]["vndbtags"] = vndbtags
succ = True succ = True
break break
if succ == False: if succ == False:

View File

@ -2,6 +2,7 @@ import time, requests, re, os, hashlib
from myutils.proxy import getproxy from myutils.proxy import getproxy
from myutils.config import globalconfig from myutils.config import globalconfig
from threading import Thread from threading import Thread
from traceback import print_exc
def b64string(a): def b64string(a):
@ -82,6 +83,7 @@ def safegetvndbjson(url, json, getter):
try: try:
return getter(_.json()) return getter(_.json())
except: except:
# print_exc()
print(_.text) print(_.text)
return None return None
except: except:
@ -155,23 +157,74 @@ def getcharnamemapbyid(vid):
return namemap return namemap
def gettagnamebytagid(gid):
return safegetvndbjson(
"https://api.vndb.org/kana/tag",
{
"filters": [
"id",
"=",
gid,
],
"fields": "name",
},
lambda js: js["results"][0]["name"],
)
def getvntagsbyid(vid):
res = safegetvndbjson(
"https://api.vndb.org/kana/vn",
{
"filters": [
"id",
"=",
vid,
],
"fields": "tags.rating",
},
lambda js: js["results"][0]["tags"],
)
if not res:
return
tags = []
try:
for r in res:
tag = r["id"]
if tag not in globalconfig["vndbcache"]["tagid2name"]:
name = gettagnamebytagid(tag)
if name:
globalconfig["vndbcache"]["tagid2name"][tag] = name
tags.append(r["id"])
except:
pass
return tags
def searchforidimage(titleorid): def searchforidimage(titleorid):
print(titleorid) print(titleorid)
if os.path.exists("./cache/vndb") == False: if os.path.exists("./cache/vndb") == False:
os.mkdir("./cache/vndb") os.mkdir("./cache/vndb")
if isinstance(titleorid, str): if isinstance(titleorid, str):
vid = getvidbytitle(titleorid) vid = getvidbytitle(titleorid)
if not vid:
return {}
elif isinstance(titleorid, int): elif isinstance(titleorid, int):
vid = "v{}".format(titleorid) vid = "v{}".format(titleorid)
img = getimgbyid(vid) img = getimgbyid(vid)
title = gettitlebyid(vid) title = gettitlebyid(vid)
namemap = getcharnamemapbyid(vid) namemap = getcharnamemapbyid(vid)
vndbtags = getvntagsbyid(vid)
return { return {
"namemap": namemap, "namemap": namemap,
"title": title, "title": title,
"vid": vid, "vid": vid,
"infopath": vndbdowloadinfo(vid), "infopath": vndbdowloadinfo(vid),
"imagepath": vndbdownloadimg(img), "imagepath": vndbdownloadimg(img),
"vndbtags": vndbtags,
} }

View File

@ -688,6 +688,7 @@
"lighttheme":0, "lighttheme":0,
"usesearchword": false, "usesearchword": false,
"usecopyword":false, "usecopyword":false,
"usewordorigin":false,
"ttscommon": { "ttscommon": {
"rate": 1.0, "rate": 1.0,
"volume": 100.0, "volume": 100.0,
@ -1230,5 +1231,9 @@
"captureOffsetRight":0, "captureOffsetRight":0,
"captureOffsetBottom":0, "captureOffsetBottom":0,
"multiDisplayMode":false "multiDisplayMode":false
} },
"vndbcache":{
"tagid2name":{}
},
"labelset":[]
} }

View File

@ -1,5 +1,5 @@
{ {
"version":"v2.43.0", "version":"v2.45.0",
"themes":{ "themes":{
"dark":[ "dark":[
{"file":"dark1.qss","name":"PyQtDarkTheme"}, {"file":"dark1.qss","name":"PyQtDarkTheme"},

View File

@ -752,5 +752,10 @@
"拉伸": "امتدت", "拉伸": "امتدت",
"居中": "مركز", "居中": "مركز",
"边距": "هوامش", "边距": "هوامش",
"文字区高度": "ارتفاع منطقة النص" "文字区高度": "ارتفاع منطقة النص",
"标签": "علامة",
"存在": "موجود",
"标签集": "تسمية مجموعة",
"添加": "إضافة .",
"使用原型查询": "باستخدام نموذج الاستعلام"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "拉伸", "拉伸": "拉伸",
"居中": "居中", "居中": "居中",
"边距": "邊距", "边距": "邊距",
"文字区高度": "文字區高度" "文字区高度": "文字區高度",
"标签": "標籤",
"存在": "存在",
"标签集": "標籤集",
"添加": "添加",
"使用原型查询": "使用原型査詢"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "stretching", "拉伸": "stretching",
"居中": "Centered", "居中": "Centered",
"边距": "Margins", "边距": "Margins",
"文字区高度": "Text area height" "文字区高度": "Text area height",
"标签": "label",
"存在": "existence",
"标签集": "Label set",
"添加": "Add",
"使用原型查询": "Using prototype queries"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "Estiramiento", "拉伸": "Estiramiento",
"居中": "En el Centro", "居中": "En el Centro",
"边距": "Margen", "边距": "Margen",
"文字区高度": "Altura del área de texto" "文字区高度": "Altura del área de texto",
"标签": "Etiquetas",
"存在": "Existencia",
"标签集": "Conjunto de etiquetas",
"添加": "Añadir",
"使用原型查询": "Consulta con prototipo"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "Stretch", "拉伸": "Stretch",
"居中": "Centré", "居中": "Centré",
"边距": "Les marges", "边距": "Les marges",
"文字区高度": "Hauteur de la zone de texte" "文字区高度": "Hauteur de la zone de texte",
"标签": "Étiquettes",
"存在": "Présence",
"标签集": "Ensemble d'étiquettes",
"添加": "Ajouter",
"使用原型查询": "Utiliser une requête prototype"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "stretching", "拉伸": "stretching",
"居中": "Centrato", "居中": "Centrato",
"边距": "Margini", "边距": "Margini",
"文字区高度": "Altezza area testo" "文字区高度": "Altezza area testo",
"标签": "etichetta",
"存在": "esistenza",
"标签集": "Set di etichette",
"添加": "Aggiungi",
"使用原型查询": "Utilizzo di query prototipali"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "押し出し", "拉伸": "押し出し",
"居中": "中央揃え", "居中": "中央揃え",
"边距": "マージン", "边距": "マージン",
"文字区高度": "テキスト領域の高さ" "文字区高度": "テキスト領域の高さ",
"标签": "タブ",
"存在": "存在する",
"标签集": "ラベルセット",
"添加": "追加",
"使用原型查询": "プロトタイプクエリーの使用"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "스트레치", "拉伸": "스트레치",
"居中": "가운데", "居中": "가운데",
"边距": "여백", "边距": "여백",
"文字区高度": "문자 영역 높이" "文字区高度": "문자 영역 높이",
"标签": "레이블",
"存在": "존재",
"标签集": "태그 세트",
"添加": "추가",
"使用原型查询": "원형 조회 사용"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "rozciąganie", "拉伸": "rozciąganie",
"居中": "Wyśrodkowane", "居中": "Wyśrodkowane",
"边距": "Marginesy", "边距": "Marginesy",
"文字区高度": "Wysokość obszaru tekstu" "文字区高度": "Wysokość obszaru tekstu",
"标签": "etykieta",
"存在": "istnienie",
"标签集": "Zestaw etykiet",
"添加": "Dodaj",
"使用原型查询": "Korzystanie z prototypowych zapytań"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "Растяжка", "拉伸": "Растяжка",
"居中": "В центре", "居中": "В центре",
"边距": "Границы", "边距": "Границы",
"文字区高度": "Высота зоны" "文字区高度": "Высота зоны",
"标签": "Метки",
"存在": "Наличие",
"标签集": "Набор меток",
"添加": "Добавить",
"使用原型查询": "Использовать запрос прототипа"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "ยืดออก", "拉伸": "ยืดออก",
"居中": "ศูนย์กลาง", "居中": "ศูนย์กลาง",
"边距": "ขอบ", "边距": "ขอบ",
"文字区高度": "ความสูงของโซนคำ" "文字区高度": "ความสูงของโซนคำ",
"标签": "ป้ายกำกับ",
"存在": "การปรากฏตัว",
"标签集": "ชุดแท็ก",
"添加": "เพิ่ม",
"使用原型查询": "การใช้แบบสอบถามต้นแบบ"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "stretching", "拉伸": "stretching",
"居中": "Centered", "居中": "Centered",
"边距": "Margins", "边距": "Margins",
"文字区高度": "Metin alanının yüksekliği" "文字区高度": "Metin alanının yüksekliği",
"标签": "etiket",
"存在": "varlığı",
"标签集": "Etiket seti",
"添加": "Ekle",
"使用原型查询": "Prototip sorguları kullanılıyor"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "розтягування", "拉伸": "розтягування",
"居中": "З центром", "居中": "З центром",
"边距": "Марги", "边距": "Марги",
"文字区高度": "Висота області тексту" "文字区高度": "Висота області тексту",
"标签": "мітка",
"存在": "існування",
"标签集": "Встановлення мітки",
"添加": "Додати",
"使用原型查询": "Використання запитів прототипу"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "căng", "拉伸": "căng",
"居中": "Ở giữa", "居中": "Ở giữa",
"边距": "Viền", "边距": "Viền",
"文字区高度": "Chiều cao vùng văn bản" "文字区高度": "Chiều cao vùng văn bản",
"标签": "Trang chủ",
"存在": "Hiện diện",
"标签集": "Bộ thẻ",
"添加": "Thêm",
"使用原型查询": "Truy vấn với Prototype"
} }

View File

@ -752,5 +752,10 @@
"拉伸": "", "拉伸": "",
"居中": "", "居中": "",
"边距": "", "边距": "",
"文字区高度": "" "文字区高度": "",
"标签": "",
"存在": "",
"标签集": "",
"添加": "",
"使用原型查询": ""
} }