mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
...
This commit is contained in:
parent
31b5f45be3
commit
29cb1bc03a
@ -62,7 +62,7 @@ class noundictconfigdialog1(LDialog):
|
|||||||
|
|
||||||
self.model = LStandardItemModel()
|
self.model = LStandardItemModel()
|
||||||
self.model.setHorizontalHeaderLabels(label)
|
self.model.setHorizontalHeaderLabels(label)
|
||||||
table = TableViewW(self)
|
table = TableViewW(self, copypaste=True, updown=True)
|
||||||
table.setModel(self.model)
|
table.setModel(self.model)
|
||||||
table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
|
table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
|
||||||
table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
|
table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
|
||||||
@ -72,7 +72,6 @@ class noundictconfigdialog1(LDialog):
|
|||||||
table.horizontalHeader().setSectionResizeMode(
|
table.horizontalHeader().setSectionResizeMode(
|
||||||
0, QHeaderView.ResizeMode.ResizeToContents
|
0, QHeaderView.ResizeMode.ResizeToContents
|
||||||
)
|
)
|
||||||
table.setsimplemenu()
|
|
||||||
|
|
||||||
self.table = table
|
self.table = table
|
||||||
for row, item in enumerate(reflist):
|
for row, item in enumerate(reflist):
|
||||||
@ -122,19 +121,24 @@ class noundictconfigdialog1(LDialog):
|
|||||||
|
|
||||||
def __setindexwidget(self, index: QModelIndex, data):
|
def __setindexwidget(self, index: QModelIndex, data):
|
||||||
if index.column() == 0:
|
if index.column() == 0:
|
||||||
|
data = {"regex": data.lower() == "true"}
|
||||||
self.table.setIndexWidget(index, getsimpleswitch(data, "regex"))
|
self.table.setIndexWidget(index, getsimpleswitch(data, "regex"))
|
||||||
if index.column() == 1:
|
elif index.column() == 1:
|
||||||
|
data = {"escape": data.lower() == "true"}
|
||||||
self.table.setIndexWidget(index, getsimpleswitch(data, "escape"))
|
self.table.setIndexWidget(index, getsimpleswitch(data, "escape"))
|
||||||
|
else:
|
||||||
|
self.table.model().setItem(index.row(), index.column(), QStandardItem(data))
|
||||||
|
|
||||||
def __getindexwidgetdata(self, index: QModelIndex):
|
def __getindexwidgetdata(self, index: QModelIndex):
|
||||||
if index.column() == 0:
|
if index.column() == 0:
|
||||||
return {"regex": self.table.indexWidgetX(index).isChecked()}
|
return self.table.indexWidgetX(index).isChecked()
|
||||||
if index.column() == 1:
|
if index.column() == 1:
|
||||||
return {"escape": self.table.indexWidgetX(index).isChecked()}
|
return self.table.indexWidgetX(index).isChecked()
|
||||||
|
return self.table.safetext(index)
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
def __check(row):
|
def __check(row):
|
||||||
k = self.model.item(row, 2).text()
|
k = self.table.safetext(row, 2)
|
||||||
if k == "":
|
if k == "":
|
||||||
return ""
|
return ""
|
||||||
switch = self.table.indexWidgetX(row, 0).isChecked()
|
switch = self.table.indexWidgetX(row, 0).isChecked()
|
||||||
@ -144,8 +148,8 @@ class noundictconfigdialog1(LDialog):
|
|||||||
self.table.dedumpmodel(__check)
|
self.table.dedumpmodel(__check)
|
||||||
self.reflist.clear()
|
self.reflist.clear()
|
||||||
for row in range(self.model.rowCount()):
|
for row in range(self.model.rowCount()):
|
||||||
k = self.model.item(row, 2).text()
|
k = self.table.safetext(row, 2)
|
||||||
v = self.model.item(row, 3).text()
|
v = self.table.safetext(row, 3)
|
||||||
switch = self.table.indexWidgetX(row, 0)
|
switch = self.table.indexWidgetX(row, 0)
|
||||||
es = self.table.indexWidgetX(row, 1)
|
es = self.table.indexWidgetX(row, 1)
|
||||||
self.reflist.append(
|
self.reflist.append(
|
||||||
@ -321,7 +325,7 @@ class yuyinzhidingsetting(LDialog):
|
|||||||
|
|
||||||
self.model = LStandardItemModel()
|
self.model = LStandardItemModel()
|
||||||
self.model.setHorizontalHeaderLabels(["正则", "条件", "目标", "指定为"])
|
self.model.setHorizontalHeaderLabels(["正则", "条件", "目标", "指定为"])
|
||||||
table = TableViewW(self)
|
table = TableViewW(self, updown=True, copypaste=False)
|
||||||
table.setModel(self.model)
|
table.setModel(self.model)
|
||||||
table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
|
table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
|
||||||
table.horizontalHeader().setSectionResizeMode(
|
table.horizontalHeader().setSectionResizeMode(
|
||||||
@ -333,7 +337,6 @@ class yuyinzhidingsetting(LDialog):
|
|||||||
table.horizontalHeader().setSectionResizeMode(
|
table.horizontalHeader().setSectionResizeMode(
|
||||||
0, QHeaderView.ResizeMode.ResizeToContents
|
0, QHeaderView.ResizeMode.ResizeToContents
|
||||||
)
|
)
|
||||||
table.setsimplemenu({"copypaste": False})
|
|
||||||
|
|
||||||
self.table = table
|
self.table = table
|
||||||
for row, item in enumerate(reflist):
|
for row, item in enumerate(reflist):
|
||||||
@ -386,7 +389,7 @@ class yuyinzhidingsetting(LDialog):
|
|||||||
rows = self.model.rowCount()
|
rows = self.model.rowCount()
|
||||||
self.reflist.clear()
|
self.reflist.clear()
|
||||||
for row in range(rows):
|
for row in range(rows):
|
||||||
k = self.model.item(row, 2).text()
|
k = self.table.safetext(row, 2)
|
||||||
switch = self.table.indexWidgetX(row, 0)
|
switch = self.table.indexWidgetX(row, 0)
|
||||||
con = self.table.indexWidgetX(row, 1)
|
con = self.table.indexWidgetX(row, 1)
|
||||||
con2 = self.table.indexWidgetX(row, 3)
|
con2 = self.table.indexWidgetX(row, 3)
|
||||||
@ -732,14 +735,14 @@ class postconfigdialog_(LDialog):
|
|||||||
|
|
||||||
if isinstance(self.configdict, dict):
|
if isinstance(self.configdict, dict):
|
||||||
for row in range(rows):
|
for row in range(rows):
|
||||||
text = self.model.item(row, 0).text()
|
text = self.table.safetext(row, 0)
|
||||||
self.configdict[text] = self.model.item(row, 1).text()
|
self.configdict[text] = self.table.safetext(row, 1)
|
||||||
elif isinstance(self.configdict, list):
|
elif isinstance(self.configdict, list):
|
||||||
for row in range(rows):
|
for row in range(rows):
|
||||||
text = self.model.item(row, 0).text()
|
text = self.table.safetext(row, 0)
|
||||||
item = {}
|
item = {}
|
||||||
for _i, key in enumerate(self.dictkeys):
|
for _i, key in enumerate(self.dictkeys):
|
||||||
item[key] = self.model.item(row, _i).text()
|
item[key] = self.table.safetext(row, _i)
|
||||||
self.configdict.append(item)
|
self.configdict.append(item)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
@ -769,11 +772,10 @@ class postconfigdialog_(LDialog):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
model.setHorizontalHeaderLabels(headers)
|
model.setHorizontalHeaderLabels(headers)
|
||||||
table = TableViewW(self)
|
table = TableViewW(self, copypaste=True, updown=True)
|
||||||
table.setModel(model)
|
table.setModel(model)
|
||||||
table.setWordWrap(False)
|
table.setWordWrap(False)
|
||||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
||||||
table.setsimplemenu()
|
|
||||||
button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"])
|
button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"])
|
||||||
self.table = table
|
self.table = table
|
||||||
button.btn1clicked.connect(table.insertplainrow)
|
button.btn1clicked.connect(table.insertplainrow)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from qtsymbols import *
|
from qtsymbols import *
|
||||||
import os, platform, functools, uuid, json, math
|
import os, platform, functools, uuid, json, math, csv, io
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
import windows, qtawesome, winsharedutils, gobject
|
import windows, qtawesome, winsharedutils, gobject
|
||||||
from webviewpy import webview_native_handle_kind_t, Webview, declare_library_path
|
from webviewpy import webview_native_handle_kind_t, Webview, declare_library_path
|
||||||
@ -87,11 +87,16 @@ class FocusDoubleSpin(QDoubleSpinBox):
|
|||||||
|
|
||||||
|
|
||||||
class TableViewW(QTableView):
|
class TableViewW(QTableView):
|
||||||
def __init__(self, *argc) -> None:
|
def __init__(self, *argc, updown=False, copypaste=False) -> None:
|
||||||
super().__init__(*argc)
|
super().__init__(*argc)
|
||||||
self.setSelectionMode(QAbstractItemView.SelectionMode.ContiguousSelection)
|
self.setSelectionMode(QAbstractItemView.SelectionMode.ContiguousSelection)
|
||||||
|
self.copypaste = copypaste
|
||||||
|
self.updown = updown
|
||||||
|
if updown or copypaste:
|
||||||
|
self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||||
|
self.customContextMenuRequested.connect(self.showmenu)
|
||||||
|
|
||||||
def showmenu(self, info, pos):
|
def showmenu(self, pos):
|
||||||
r = self.currentIndex().row()
|
r = self.currentIndex().row()
|
||||||
if r < 0:
|
if r < 0:
|
||||||
return
|
return
|
||||||
@ -100,9 +105,10 @@ class TableViewW(QTableView):
|
|||||||
down = LAction("下移")
|
down = LAction("下移")
|
||||||
copy = LAction("复制")
|
copy = LAction("复制")
|
||||||
paste = LAction("粘贴")
|
paste = LAction("粘贴")
|
||||||
menu.addAction(up)
|
if self.updown:
|
||||||
menu.addAction(down)
|
menu.addAction(up)
|
||||||
if info.get("copypaste", True):
|
menu.addAction(down)
|
||||||
|
if self.copypaste:
|
||||||
menu.addAction(copy)
|
menu.addAction(copy)
|
||||||
menu.addAction(paste)
|
menu.addAction(paste)
|
||||||
action = menu.exec(self.cursor().pos())
|
action = menu.exec(self.cursor().pos())
|
||||||
@ -115,11 +121,19 @@ class TableViewW(QTableView):
|
|||||||
elif action == paste:
|
elif action == paste:
|
||||||
self.pastetable()
|
self.pastetable()
|
||||||
|
|
||||||
def setsimplemenu(self, info=None):
|
def keyPressEvent(self, e):
|
||||||
self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
if self.copypaste:
|
||||||
if info is None:
|
if e.modifiers() == Qt.KeyboardModifier.ControlModifier:
|
||||||
info = {}
|
if e.key() == Qt.Key.Key_C:
|
||||||
self.customContextMenuRequested.connect(functools.partial(self.showmenu, info))
|
self.copytable()
|
||||||
|
elif e.key() == Qt.Key.Key_V:
|
||||||
|
self.pastetable()
|
||||||
|
else:
|
||||||
|
super().keyPressEvent(e)
|
||||||
|
else:
|
||||||
|
super().keyPressEvent(e)
|
||||||
|
else:
|
||||||
|
super().keyPressEvent(e)
|
||||||
|
|
||||||
def insertplainrow(self, row=0):
|
def insertplainrow(self, row=0):
|
||||||
self.model().insertRow(
|
self.model().insertRow(
|
||||||
@ -211,7 +225,8 @@ class TableViewW(QTableView):
|
|||||||
|
|
||||||
def getindexwidgetdata(self, index: QModelIndex): ...
|
def getindexwidgetdata(self, index: QModelIndex): ...
|
||||||
|
|
||||||
def setindexwidget(self, index, data): ...
|
def setindexwidget(self, index, data):
|
||||||
|
self.model().setItem(index.row(), index.column(), QStandardItem(data))
|
||||||
|
|
||||||
def safetext(self, row_or_index, col=None, mybewidget=False):
|
def safetext(self, row_or_index, col=None, mybewidget=False):
|
||||||
if col is None:
|
if col is None:
|
||||||
@ -229,50 +244,47 @@ class TableViewW(QTableView):
|
|||||||
return _1
|
return _1
|
||||||
|
|
||||||
def copytable(self) -> str:
|
def copytable(self) -> str:
|
||||||
if len(self.selectedIndexes()) <= 1:
|
|
||||||
return winsharedutils.clipboard_set(self.safetext(self.currentIndex()))
|
|
||||||
_data = []
|
_data = []
|
||||||
minr = minc = 999999999
|
lastrow = -1
|
||||||
maxr = maxc = 0
|
|
||||||
for index in self.selectedIndexes():
|
for index in self.selectedIndexes():
|
||||||
minr = min(minr, index.row())
|
if index.row() != lastrow:
|
||||||
minc = min(minc, index.column())
|
_data.append([])
|
||||||
maxr = max(maxr, index.row())
|
lastrow = index.row()
|
||||||
maxc = max(maxc, index.column())
|
_data[-1].append(self.safetext(index, mybewidget=True))
|
||||||
_data.append(self.safetext(index, mybewidget=True))
|
output = io.StringIO()
|
||||||
data = {
|
|
||||||
"data": _data,
|
csv_writer = csv.writer(output, delimiter="\t")
|
||||||
"row": maxr - minr + 1,
|
for row in _data:
|
||||||
"col": maxc - minc + 1,
|
csv_writer.writerow(row)
|
||||||
}
|
csv_str = output.getvalue()
|
||||||
winsharedutils.clipboard_set(json.dumps(data, ensure_ascii=False))
|
output.close()
|
||||||
|
winsharedutils.clipboard_set(csv_str)
|
||||||
|
|
||||||
def pastetable(self):
|
def pastetable(self):
|
||||||
string = winsharedutils.clipboard_get()
|
string = winsharedutils.clipboard_get()
|
||||||
|
current = self.currentIndex()
|
||||||
try:
|
try:
|
||||||
js = json.loads(string)
|
csv_file = io.StringIO(string)
|
||||||
current = self.currentIndex()
|
csv_reader = csv.reader(csv_file, delimiter="\t")
|
||||||
for _ in range(js["row"]):
|
my_list = list(csv_reader)
|
||||||
|
csv_file.close()
|
||||||
|
if len(my_list) == 1 and len(my_list[0]) == 1:
|
||||||
|
self.model().itemFromIndex(current).setText(my_list[0][0])
|
||||||
|
return
|
||||||
|
for j, line in enumerate(my_list):
|
||||||
self.insertplainrow(current.row() + 1)
|
self.insertplainrow(current.row() + 1)
|
||||||
for i, data in enumerate(js.get("data", [])):
|
for j, line in enumerate(my_list):
|
||||||
c = current.column() + i % js["col"]
|
for i in range(len(line)):
|
||||||
if c >= self.model().columnCount():
|
data = line[i]
|
||||||
continue
|
c = current.column() + i
|
||||||
if isinstance(data, str):
|
if c >= self.model().columnCount():
|
||||||
self.model().setItem(
|
continue
|
||||||
current.row() + 1 + i // js["col"], c, QStandardItem(data)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.model().setItem(
|
|
||||||
current.row() + 1 + i // js["col"], c, QStandardItem("")
|
|
||||||
)
|
|
||||||
self.setindexwidget(
|
self.setindexwidget(
|
||||||
self.model().index(current.row() + 1 + i // js["col"], c), data
|
self.model().index(current.row() + 1 + j, c), data
|
||||||
)
|
)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print_exc()
|
print_exc()
|
||||||
self.model().itemFromIndex(self.currentIndex()).setText(string)
|
self.model().itemFromIndex(current).setText(string)
|
||||||
|
|
||||||
|
|
||||||
def getQMessageBox(
|
def getQMessageBox(
|
||||||
|
@ -130,7 +130,7 @@ class common:
|
|||||||
ff.write(_content)
|
ff.write(_content)
|
||||||
|
|
||||||
def dispatchdownloadtask(self, url):
|
def dispatchdownloadtask(self, url):
|
||||||
if url is None:
|
if not url:
|
||||||
return None
|
return None
|
||||||
__routine = f"cache/metadata/{self.typename}"
|
__routine = f"cache/metadata/{self.typename}"
|
||||||
if self.typename == "vndb":
|
if self.typename == "vndb":
|
||||||
|
@ -144,7 +144,7 @@ def getinfosbyvid(proxy, vid):
|
|||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
title=gettitlefromjs(js["results"][0]),
|
title=gettitlefromjs(js["results"][0]),
|
||||||
img=js["results"][0]["image"]["url"],
|
img=js["results"][0]["image"]["url"] if js["results"][0]["image"] else None,
|
||||||
sc=imgs,
|
sc=imgs,
|
||||||
dev=dev,
|
dev=dev,
|
||||||
tags=sorted(tags, key=lambda x: -rates[tags.index(x)]),
|
tags=sorted(tags, key=lambda x: -rates[tags.index(x)]),
|
||||||
|
@ -28,8 +28,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
|
|||||||
include(generate_product_version)
|
include(generate_product_version)
|
||||||
|
|
||||||
set(VERSION_MAJOR 5)
|
set(VERSION_MAJOR 5)
|
||||||
set(VERSION_MINOR 37)
|
set(VERSION_MINOR 38)
|
||||||
set(VERSION_PATCH 2)
|
set(VERSION_PATCH 0)
|
||||||
|
|
||||||
add_library(pch pch.cpp)
|
add_library(pch pch.cpp)
|
||||||
target_precompile_headers(pch PUBLIC pch.h)
|
target_precompile_headers(pch PUBLIC pch.h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user