This commit is contained in:
恍兮惚兮 2024-09-18 18:58:25 +08:00
parent 29cb1bc03a
commit bb60981033
5 changed files with 86 additions and 56 deletions

View File

@ -1,7 +1,7 @@
from qtsymbols import * from qtsymbols import *
import functools, importlib import functools, importlib
from traceback import print_exc from traceback import print_exc
import qtawesome, os, gobject import qtawesome, os, gobject, json
from myutils.config import globalconfig, _TR from myutils.config import globalconfig, _TR
from myutils.utils import makehtml from myutils.utils import makehtml
from myutils.wrapper import Singleton_close from myutils.wrapper import Singleton_close
@ -97,8 +97,8 @@ class noundictconfigdialog1(LDialog):
button4.clicked.connect(clicked4) button4.clicked.connect(clicked4)
search.addWidget(button4) search.addWidget(button4)
table.getindexwidgetdata = self.__getindexwidgetdata table.getindexdata = self.__getindexwidgetdata
table.setindexwidget = self.__setindexwidget table.setindexdata = self.__setindexwidget
self.table = table self.table = table
button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"]) button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"])
table.insertplainrow = lambda row: self.newline( table.insertplainrow = lambda row: self.newline(
@ -134,30 +134,30 @@ class noundictconfigdialog1(LDialog):
return self.table.indexWidgetX(index).isChecked() return self.table.indexWidgetX(index).isChecked()
if index.column() == 1: if index.column() == 1:
return self.table.indexWidgetX(index).isChecked() return self.table.indexWidgetX(index).isChecked()
return self.table.safetext(index) return self.model.itemFromIndex(index).text()
def apply(self): def apply(self):
def __check(row): def __check(row):
k = self.table.safetext(row, 2) k = self.table.getdata(row, 2)
if k == "": if k == "":
return "" return ""
switch = self.table.indexWidgetX(row, 0).isChecked() switch = self.table.getdata(row, 0)
es = self.table.indexWidgetX(row, 1).isChecked() es = self.table.getdata(row, 1)
return (switch, es, k) return (switch, es, k)
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.table.safetext(row, 2) k = self.table.getdata(row, 2)
v = self.table.safetext(row, 3) v = self.table.getdata(row, 3)
switch = self.table.indexWidgetX(row, 0) switch = self.table.getdata(row, 0)
es = self.table.indexWidgetX(row, 1) es = self.table.getdata(row, 1)
self.reflist.append( self.reflist.append(
{ {
"key": k, "key": k,
"value": v, "value": v,
"escape": es.isChecked(), "escape": es,
"regex": switch.isChecked(), "regex": switch,
} }
) )
@ -325,7 +325,7 @@ class yuyinzhidingsetting(LDialog):
self.model = LStandardItemModel() self.model = LStandardItemModel()
self.model.setHorizontalHeaderLabels(["正则", "条件", "目标", "指定为"]) self.model.setHorizontalHeaderLabels(["正则", "条件", "目标", "指定为"])
table = TableViewW(self, updown=True, copypaste=False) table = TableViewW(self, updown=True, copypaste=True)
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(
@ -337,7 +337,11 @@ class yuyinzhidingsetting(LDialog):
table.horizontalHeader().setSectionResizeMode( table.horizontalHeader().setSectionResizeMode(
0, QHeaderView.ResizeMode.ResizeToContents 0, QHeaderView.ResizeMode.ResizeToContents
) )
table.getindexdata = self.__getindexwidgetdata
table.setindexdata = self.__setindexwidget
table.insertplainrow = lambda row: self.newline(
row, {"key": "", "condition": 0, "regex": False, "target": "skip"}
)
self.table = table self.table = table
for row, item in enumerate(reflist): for row, item in enumerate(reflist):
self.newline(row, item) self.newline(row, item)
@ -365,13 +369,7 @@ class yuyinzhidingsetting(LDialog):
button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"]) button = threebuttons(texts=["添加行", "删除行", "上移", "下移", "立即应用"])
def clicked1(): button.btn1clicked.connect(functools.partial(self.table.insertplainrow, 0))
self.newline(
0, {"key": "", "condition": 0, "regex": False, "target": "skip"}
)
button.btn1clicked.connect(clicked1)
button.btn2clicked.connect(table.removeselectedrows) button.btn2clicked.connect(table.removeselectedrows)
button.btn5clicked.connect(self.apply) button.btn5clicked.connect(self.apply)
button.btn3clicked.connect(functools.partial(table.moverank, -1)) button.btn3clicked.connect(functools.partial(table.moverank, -1))
@ -384,21 +382,55 @@ class yuyinzhidingsetting(LDialog):
self.resize(QSize(600, 400)) self.resize(QSize(600, 400))
self.show() self.show()
def __setindexwidget(self, index: QModelIndex, data):
if index.column() == 0:
data = {"regex": data.lower() == "true"}
self.table.setIndexWidget(index, getsimpleswitch(data, "regex"))
elif index.column() == 1:
try:
data = int(data)
except:
data = 0
data = {"condition": data}
self.table.setIndexWidget(
index, getsimplecombobox(["首尾", "包含"], data, "condition")
)
elif index.column() == 3:
if data in ["default", "skip"]:
pass
else:
try:
data = json.loads(data)
except:
data = "default"
self.table.setIndexWidget(index, self.createacombox({"target": data}))
else:
self.table.model().setItem(index.row(), index.column(), QStandardItem(data))
def __getindexwidgetdata(self, index: QModelIndex):
if index.column() == 0:
return self.table.indexWidgetX(index).isChecked()
if index.column() == 1:
return self.table.indexWidgetX(index).currentIndex()
if index.column() == 3:
return self.table.indexWidgetX(index).target
return self.model.itemFromIndex(index).text()
def apply(self): def apply(self):
self.table.dedumpmodel(2) self.table.dedumpmodel(2)
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.table.safetext(row, 2) k = self.table.getdata(row, 2)
switch = self.table.indexWidgetX(row, 0) switch = self.table.getdata(row, 0)
con = self.table.indexWidgetX(row, 1) con = self.table.getdata(row, 1)
con2 = self.table.indexWidgetX(row, 3) con2 = self.table.getdata(row, 3)
self.reflist.append( self.reflist.append(
{ {
"key": k, "key": k,
"condition": con.currentIndex(), "condition": con,
"regex": switch.isChecked(), "regex": switch,
"target": con2.target, "target": con2,
} }
) )
@ -735,14 +767,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.table.safetext(row, 0) text = self.table.getdata(row, 0)
self.configdict[text] = self.table.safetext(row, 1) self.configdict[text] = self.table.getdata(row, 1)
elif isinstance(self.configdict, list): elif isinstance(self.configdict, list):
for row in range(rows): for row in range(rows):
text = self.table.safetext(row, 0) text = self.table.getdata(row, 0)
item = {} item = {}
for _i, key in enumerate(self.dictkeys): for _i, key in enumerate(self.dictkeys):
item[key] = self.table.safetext(row, _i) item[key] = self.table.getdata(row, _i)
self.configdict.append(item) self.configdict.append(item)
else: else:
raise raise

View File

@ -113,8 +113,8 @@ class triggereditor(LDialog):
rows = self.hcmodel.rowCount() rows = self.hcmodel.rowCount()
self.list.clear() self.list.clear()
for row in range(rows): for row in range(rows):
i0 = self.hctable.indexWidgetX(row, 0).currentIndex() i0 = self.hctable.getdata(row, 0)
i1 = self.hctable.indexWidgetX(row, 1).currentIndex() i1 = self.hctable.getdata(row, 1)
self.list.append({"vkey": self.vkeys[i0], "event": i1}) self.list.append({"vkey": self.vkeys[i0], "event": i1})
def click1(self): def click1(self):

View File

@ -147,7 +147,7 @@ class TableViewW(QTableView):
needremoves = [] needremoves = []
for row in range(rows): for row in range(rows):
if isinstance(col, int): if isinstance(col, int):
k = self.safetext(row, col) k = self.getdata(row, col)
elif callable(col): elif callable(col):
k = col(row) k = col(row)
if k == "" or k in dedump: if k == "" or k in dedump:
@ -223,25 +223,21 @@ class TableViewW(QTableView):
if isinstance(m, LStandardItemModel): if isinstance(m, LStandardItemModel):
m.updatelangtext() m.updatelangtext()
def getindexwidgetdata(self, index: QModelIndex): ... def getindexdata(self, index):
return self.model().itemFromIndex(index).text()
def setindexwidget(self, index, data): def setindexdata(self, index, data):
self.model().setItem(index.row(), index.column(), QStandardItem(data)) self.model().setItem(index.row(), index.column(), QStandardItem(data))
def safetext(self, row_or_index, col=None, mybewidget=False): def getdata(self, row_or_index, col=None):
if col is None: if col is None:
index: QModelIndex = row_or_index index: QModelIndex = row_or_index
else: else:
index = self.model().index(row_or_index, col) index = self.model().index(row_or_index, col)
if mybewidget:
w = self.indexWidget(index)
if w is not None:
return self.getindexwidgetdata(index)
_1 = self.model().itemFromIndex(index) _1 = self.model().itemFromIndex(index)
_1 = _1.text() if _1 else "" if not _1:
return ""
return _1 return self.getindexdata(index)
def copytable(self) -> str: def copytable(self) -> str:
_data = [] _data = []
@ -250,7 +246,10 @@ class TableViewW(QTableView):
if index.row() != lastrow: if index.row() != lastrow:
_data.append([]) _data.append([])
lastrow = index.row() lastrow = index.row()
_data[-1].append(self.safetext(index, mybewidget=True)) data = self.getdata(index)
if not isinstance(data, str):
data = json.dumps(data, ensure_ascii=False)
_data[-1].append(data)
output = io.StringIO() output = io.StringIO()
csv_writer = csv.writer(output, delimiter="\t") csv_writer = csv.writer(output, delimiter="\t")
@ -269,7 +268,7 @@ class TableViewW(QTableView):
my_list = list(csv_reader) my_list = list(csv_reader)
csv_file.close() csv_file.close()
if len(my_list) == 1 and len(my_list[0]) == 1: if len(my_list) == 1 and len(my_list[0]) == 1:
self.model().itemFromIndex(current).setText(my_list[0][0]) self.setindexdata(current, my_list[0][0])
return return
for j, line in enumerate(my_list): for j, line in enumerate(my_list):
self.insertplainrow(current.row() + 1) self.insertplainrow(current.row() + 1)
@ -279,12 +278,12 @@ class TableViewW(QTableView):
c = current.column() + i c = current.column() + i
if c >= self.model().columnCount(): if c >= self.model().columnCount():
continue continue
self.setindexwidget( self.setindexdata(
self.model().index(current.row() + 1 + j, c), data self.model().index(current.row() + 1 + j, c), data
) )
except: except:
print_exc() print_exc()
self.model().itemFromIndex(current).setText(string) self.setindexdata(current, string)
def getQMessageBox( def getQMessageBox(

View File

@ -80,8 +80,7 @@ class gptcommon(basetrans):
json_data = json.loads(response_data) json_data = json.loads(response_data)
msg = json_data["choices"][0].get("delta", {}).get("content", None) msg = json_data["choices"][0].get("delta", {}).get("content", None)
if not msg: if msg:
continue
message += msg message += msg
yield msg yield msg
rs = json_data["choices"][0].get("finish_reason") rs = json_data["choices"][0].get("finish_reason")

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 5) set(VERSION_MAJOR 5)
set(VERSION_MINOR 38) set(VERSION_MINOR 38)
set(VERSION_PATCH 0) set(VERSION_PATCH 1)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)