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

View File

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

View File

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

View File

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

View File

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