This commit is contained in:
恍兮惚兮 2024-06-22 21:51:29 +08:00
parent 40ec0b5686
commit 251835c2ed
18 changed files with 163 additions and 177 deletions

View File

@ -11,6 +11,7 @@ from gui.usefulwidget import (
getQMessageBox,
dialog_showinfo,
getsimplecombobox,
MySwitch,
getsimpleswitch,
textbrowappendandmovetoend,
FocusSpin,
@ -367,7 +368,7 @@ class hookselect(closeashidewindow):
addnewhooksignal = pyqtSignal(tuple, bool)
getnewsentencesignal = pyqtSignal(str)
sysmessagesignal = pyqtSignal(str)
changeprocessclearsignal = pyqtSignal()
changeprocessclearsignal = pyqtSignal(dict)
removehooksignal = pyqtSignal(tuple)
getfoundhooksignal = pyqtSignal(dict)
update_item_new_line = pyqtSignal(tuple, str)
@ -389,7 +390,7 @@ class hookselect(closeashidewindow):
return
row = self.save.index(hook)
output = output[:200].replace("\n", " ")
colidx = 2 + (gobject.baseobject.textsource.allow_set_text_name)
colidx = 2 + int(self.allow_set_text_name) + int(bool(self.embedablenum))
self.ttCombomodelmodel.item(row, colidx).setText(output)
def removehook(self, key):
@ -398,8 +399,35 @@ class hookselect(closeashidewindow):
self.ttCombomodelmodel.removeRow(self.save.index(key))
self.selectionbutton.pop(self.save.index(key))
self.save.remove(key)
self.solveifembedablenumdecreaseto0(key)
def changeprocessclear(self):
def solveifembedablenumdecreaseto0(self, key):
embedable = self.saveifembedable.pop(key)
if not embedable:
return
self.embedablenum -= 1
if self.embedablenum > 0:
return
self.currentheader.pop(1 + int(self.allow_set_text_name))
self.ttCombomodelmodel.removeColumn(1 + int(self.allow_set_text_name))
self.ttCombomodelmodel.setHorizontalHeaderLabels(_TRL(self.currentheader))
def solveifembedablenumincreaseto1(self, key, isembedable):
self.saveifembedable[key] = isembedable
if not isembedable:
return
self.embedablenum += 1
if self.embedablenum != 1:
return
self.currentheader.insert(1 + int(self.allow_set_text_name), "内嵌")
self.ttCombomodelmodel.insertColumn(1 + int(self.allow_set_text_name), [])
self.ttCombomodelmodel.setHorizontalHeaderLabels(_TRL(self.currentheader))
self.tttable.horizontalHeader().setSectionResizeMode(
1 + int(self.allow_set_text_name), QHeaderView.ResizeMode.ResizeToContents
)
def changeprocessclear(self, config):
# self.ttCombo.clear()
self.ttCombomodelmodel.clear()
self.save = []
@ -409,45 +437,35 @@ class hookselect(closeashidewindow):
self.typecombo = []
self.allres = OrderedDict()
self.hidesearchhookbuttons()
self.currentheader = ["显示", "HOOK", "文本"]
self.allow_set_text_name = config["allow_set_text_name"]
self.saveifembedable = {}
if self.allow_set_text_name:
self.currentheader.insert(1, "类型")
self.embedablenum = 0
def addnewhook(self, key, select):
hc, hn, tp = key
isembedable = hc[0] == "E"
if len(self.save) == 0:
if gobject.baseobject.textsource.allow_set_text_name:
self.ttCombomodelmodel.setHorizontalHeaderLabels(
_TRL(["显示", "类型", "HOOK", "文本"])
)
self.ttCombomodelmodel.setHorizontalHeaderLabels(_TRL(self.currentheader))
self.tttable.horizontalHeader().setSectionResizeMode(
0, QHeaderView.ResizeMode.ResizeToContents
)
self.tttable.horizontalHeader().setSectionResizeMode(
len(self.currentheader) - 1, QHeaderView.ResizeMode.Interactive
)
self.tttable.horizontalHeader().setSectionResizeMode(
len(self.currentheader) - 2, QHeaderView.ResizeMode.Interactive
)
if self.allow_set_text_name:
self.tttable.horizontalHeader().setSectionResizeMode(
2, QHeaderView.ResizeMode.Interactive
)
self.tttable.horizontalHeader().setSectionResizeMode(
3, QHeaderView.ResizeMode.Interactive
)
self.tttable.horizontalHeader().setSectionResizeMode(
0, QHeaderView.ResizeMode.ResizeToContents
)
self.tttable.horizontalHeader().setSectionResizeMode(
1, QHeaderView.ResizeMode.ResizeToContents
)
else:
self.ttCombomodelmodel.setHorizontalHeaderLabels(
_TRL(["选择", "HOOK", "文本"])
)
self.tttable.horizontalHeader().setSectionResizeMode(
1, QHeaderView.ResizeMode.Interactive
)
self.tttable.horizontalHeader().setSectionResizeMode(
2, QHeaderView.ResizeMode.Interactive
)
self.tttable.horizontalHeader().setSectionResizeMode(
0, QHeaderView.ResizeMode.ResizeToContents
)
if hc[0] == "E":
self.solveifembedablenumincreaseto1(key, isembedable)
if isembedable:
self.selectionbutton.insert(
0,
getsimpleswitch(
@ -464,111 +482,91 @@ class hookselect(closeashidewindow):
{1: False}, 1, callback=functools.partial(self.accept, key)
)
)
if gobject.baseobject.textsource.allow_set_text_name:
self.typecombo.insert(
rown,
getsimplecombobox(
_TRL(["文本", "人名"]),
gobject.baseobject.textsource.hooktypecollecter,
key,
callback=functools.partial(
savehook_new_data[gobject.baseobject.textsource.pname][
"hooktypeasname"
].__setitem__,
json.dumps(gobject.baseobject.textsource.serialkey(key)),
),
),
)
self.ttCombomodelmodel.insertRow(
rown,
[
QStandardItem(),
QStandardItem(),
QStandardItem("%s %s %x:%x" % (hn, hc, tp.ctx, tp.ctx2)),
QStandardItem(),
],
)
self.tttable.setIndexWidget(
self.ttCombomodelmodel.index(rown, 1), self.typecombo[rown]
)
else:
self.ttCombomodelmodel.insertRow(
rown,
[
QStandardItem(),
QStandardItem("%s %s %x:%x" % (hn, hc, tp.ctx, tp.ctx2)),
QStandardItem(),
],
)
items = [
QStandardItem(),
QStandardItem("%s %s %x:%x" % (hn, hc, tp.ctx, tp.ctx2)),
QStandardItem(),
]
if self.allow_set_text_name:
items.insert(1, QStandardItem())
if self.embedablenum:
items.insert(1 + int(self.allow_set_text_name), QStandardItem())
self.ttCombomodelmodel.insertRow(rown, items)
if select:
self.selectionbutton[rown].click()
self.tttable.setIndexWidget(
self.ttCombomodelmodel.index(rown, 0), self.selectionbutton[rown]
)
if hc[0] == "E":
embedw, hlay = getformlayoutw(cls=QHBoxLayout)
label = QLabel()
hlay.addWidget(label)
embedw.setStyleSheet("background-color: rgba(255, 255, 255, 0)")
checkbtn = QPushButton()
checkbtn.setSizePolicy(
QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Preferred
)
if isembedable:
checkbtn = MySwitch(sign=self._check_tp_using(key))
def _t(tp):
_isusing = gobject.baseobject.textsource.checkisusingembed(
tp.addr, tp.ctx, tp.ctx2
)
if _isusing:
_text = "取消内嵌翻译"
checkbtn.clicked.connect(functools.partial(self._embedbtnfn, key))
if hn[:8] == "UserHook":
needinserthookcode = savehook_new_data[
gobject.baseobject.textsource.pname
]["needinserthookcode"]
needinserthookcode = list(set(needinserthookcode + [hc]))
savehook_new_data[gobject.baseobject.textsource.pname].update(
{"needinserthookcode": needinserthookcode}
)
else:
pass
else:
_text = "使用内嵌翻译"
checkbtn.setText("" + _TR(_text) + "")
return _isusing
_t(tp)
def _c(hc, tp, _):
gobject.baseobject.textsource.useembed(
tp.addr, tp.ctx, tp.ctx2, not _t(tp)
)
_use = _t(tp)
if _use:
savehook_new_data[gobject.baseobject.textsource.pname][
"embedablehook"
].append([hc, tp.addr, tp.ctx, tp.ctx2])
else:
save = []
for _ in savehook_new_data[gobject.baseobject.textsource.pname][
"embedablehook"
]:
hc, ad, c1, c2 = _
if (hc, 0, c1, c2) == (hc, 0, tp.ctx, tp.ctx2):
save.append(_)
for _ in save:
savehook_new_data[gobject.baseobject.textsource.pname][
"embedablehook"
].remove(_)
checkbtn.clicked.connect(functools.partial(_c, hc, tp))
hlay.addWidget(checkbtn)
colidx = 2 + (gobject.baseobject.textsource.allow_set_text_name)
self.tttable.setIndexWidget(
self.ttCombomodelmodel.index(rown, colidx), embedw
self.ttCombomodelmodel.index(rown, 1 + int(self.allow_set_text_name)),
checkbtn,
)
if self.allow_set_text_name:
typecombo = getsimplecombobox(
_TRL(["文本", "人名"]),
gobject.baseobject.textsource.hooktypecollecter,
key,
callback=functools.partial(
savehook_new_data[gobject.baseobject.textsource.pname][
"hooktypeasname"
].__setitem__,
json.dumps(gobject.baseobject.textsource.serialkey(key)),
),
)
self.typecombo.insert(rown, typecombo)
self.tttable.setIndexWidget(
self.ttCombomodelmodel.index(rown, 1),
typecombo,
)
self.tttable.setRowHeight(
rown, max(self.tttable.rowHeight(rown), typecombo.height())
)
def _check_tp_using(self, key):
hc, hn, tp = key
_isusing = gobject.baseobject.textsource.checkisusingembed(
tp.addr, tp.ctx, tp.ctx2
)
if _isusing:
if hn[:8] == "UserHook":
needinserthookcode = savehook_new_data[
gobject.baseobject.textsource.pname
]["needinserthookcode"]
needinserthookcode = list(set(needinserthookcode + [hc]))
savehook_new_data[gobject.baseobject.textsource.pname].update(
{"needinserthookcode": needinserthookcode}
)
else:
pass
return _isusing
def _embedbtnfn(self, key, _):
hc, hn, tp = key
gobject.baseobject.textsource.useembed(tp.addr, tp.ctx, tp.ctx2, _)
_use = self._check_tp_using(key)
if _use:
savehook_new_data[gobject.baseobject.textsource.pname][
"embedablehook"
].append([hc, tp.addr, tp.ctx, tp.ctx2])
else:
save = []
for _ in savehook_new_data[gobject.baseobject.textsource.pname][
"embedablehook"
]:
hc, ad, c1, c2 = _
if (hc, 0, c1, c2) == (hc, 0, tp.ctx, tp.ctx2):
save.append(_)
for _ in save:
savehook_new_data[gobject.baseobject.textsource.pname][
"embedablehook"
].remove(_)
def setupUi(self):
self.widget = QWidget()
@ -684,8 +682,6 @@ class hookselect(closeashidewindow):
self.tabwidget.addTab(self.textOutput, _TR("文本"))
self.tabwidget.addTab(self.sysOutput, _TR("系统"))
self.changeprocessclear()
def showmenu(self, p: QPoint):
r = self.tttable.currentIndex().row()
if r < 0:

View File

@ -193,6 +193,11 @@ class closeashidewindow(saveposwindow):
class MySwitch(QWidget):
clicked = pyqtSignal(bool)
def event(self, a0: QEvent) -> bool:
if a0.type() == QEvent.Type.MouseButtonDblClick:
return True
return super().event(a0)
def click(self):
self.setChecked(not self.checked)
self.clicked.emit(self.checked)

View File

@ -131,7 +131,7 @@ class texthook(basetext):
self.needinserthookcode = needinserthookcode
self.removedaddress = []
gobject.baseobject.hookselectdialog.changeprocessclearsignal.emit()
gobject.baseobject.hookselectdialog.changeprocessclearsignal.emit(self.config)
if (
len(autostarthookcode) == 0
and len(savehook_new_data[self.pname]["embedablehook"]) == 0

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "المعهد العالمي التعرف على الحروف",
"有道图片翻译": "ترجمة الصور",
"图片翻译 API": "ترجمة الصور API",
"取消内嵌翻译": "إلغاء جزءا لا يتجزأ من الترجمة",
"使用内嵌翻译": "جزءا لا يتجزأ من الترجمة",
"内嵌翻译": "جزءا لا يتجزأ من الترجمة",
"隐藏不存在的游戏": "إخفاء لعبة غير موجودة",
"宽度": "عرض",
@ -810,5 +808,6 @@
"固定值": "قيمة ثابتة",
"可选取的": "قابل للاختيار",
"投影距离": "المسافة المتوقعة",
"反转颜色": "عكس اللون"
"反转颜色": "عكس اللون",
"内嵌": "جزءا لا يتجزأ من"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "通用文字識別API",
"有道图片翻译": "有道圖片翻譯",
"图片翻译 API": "圖片翻譯API",
"取消内嵌翻译": "取消內嵌翻譯",
"使用内嵌翻译": "使用內嵌翻譯",
"内嵌翻译": "內嵌翻譯",
"隐藏不存在的游戏": "隱藏不存在的遊戲",
"宽度": "寬度",
@ -810,5 +808,6 @@
"固定值": "固定值",
"可选取的": "可選取的",
"投影距离": "投影距離",
"反转颜色": "反轉顏色"
"反转颜色": "反轉顏色",
"内嵌": "內嵌"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "Universal Text Recognition API",
"有道图片翻译": "Translation of Youdao Pictures",
"图片翻译 API": "Image Translation API",
"取消内嵌翻译": "Cancel embedded translation",
"使用内嵌翻译": "Using embedded translation",
"内嵌翻译": "Embedded translation",
"隐藏不存在的游戏": "Hide games that do not exist",
"宽度": "width",
@ -810,5 +808,6 @@
"固定值": "Fixed value",
"可选取的": "Selectable",
"投影距离": "Projection distance",
"反转颜色": "invert colors"
"反转颜色": "invert colors",
"内嵌": "Embedded"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "API universal de reconocimiento de texto",
"有道图片翻译": "Traducción de imágenes de youdao",
"图片翻译 API": "API de traducción de imágenes",
"取消内嵌翻译": "Cancelar la traducción incorporada",
"使用内嵌翻译": "Usar traducción incorporada",
"内嵌翻译": "Traducción incorporada",
"隐藏不存在的游戏": "Ocultar juegos que no existen",
"宽度": "Ancho",
@ -810,5 +808,6 @@
"固定值": "Valor fijo",
"可选取的": "Seleccionable",
"投影距离": "Distancia de proyección",
"反转颜色": "Invertir color"
"反转颜色": "Invertir color",
"内嵌": "Incrustación"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "API de reconnaissance de texte universelle",
"有道图片翻译": "Traduction d'images",
"图片翻译 API": "API de traduction d'images",
"取消内嵌翻译": "Annuler la traduction intégrée",
"使用内嵌翻译": "Utiliser la traduction intégrée",
"内嵌翻译": "Traduction intégrée",
"隐藏不存在的游戏": "Cacher les jeux qui n'existent pas",
"宽度": "Largeur",
@ -810,5 +808,6 @@
"固定值": "Valeur fixe",
"可选取的": "Sélectionnable",
"投影距离": "Distance de projection",
"反转颜色": "Inverser les couleurs"
"反转颜色": "Inverser les couleurs",
"内嵌": "Intégré"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "API universale per il riconoscimento del testo",
"有道图片翻译": "Traduzione di Youdao Pictures",
"图片翻译 API": "API di traduzione immagine",
"取消内嵌翻译": "Annulla traduzione incorporata",
"使用内嵌翻译": "Uso della traduzione integrata",
"内嵌翻译": "Traduzione integrata",
"隐藏不存在的游戏": "Nascondi giochi che non esistono",
"宽度": "larghezza",
@ -810,5 +808,6 @@
"固定值": "Valore fisso",
"可选取的": "Selezionabile",
"投影距离": "Distanza di proiezione",
"反转颜色": "inverti colori"
"反转颜色": "inverti colori",
"内嵌": "Incorporato"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "共通文字認識API",
"有道图片翻译": "有道画像翻訳",
"图片翻译 API": "画像翻訳API",
"取消内嵌翻译": "インライン翻訳のキャンセル",
"使用内嵌翻译": "インライン翻訳の使用",
"内嵌翻译": "インライン翻訳",
"隐藏不存在的游戏": "起こらないゲームを隠す",
"宽度": "幅",
@ -810,5 +808,6 @@
"固定值": "固定値",
"可选取的": "選択可能",
"投影距离": "とうえいきょり",
"反转颜色": "色を反転"
"反转颜色": "色を反転",
"内嵌": "インライン"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "일반 문자 인식 API",
"有道图片翻译": "그래픽 번역",
"图片翻译 API": "사진 번역 API",
"取消内嵌翻译": "인라인 번역 취소",
"使用内嵌翻译": "인라인 번역 사용",
"内嵌翻译": "인라인 번역",
"隐藏不存在的游戏": "일어나지 않는 게임 숨기기",
"宽度": "너비",
@ -810,5 +808,6 @@
"固定值": "고정값",
"可选取的": "선택 가능",
"投影距离": "투영 거리",
"反转颜色": "색상 반전"
"反转颜色": "색상 반전",
"内嵌": "내장"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "Uniwersalne rozpoznawanie tekstu API",
"有道图片翻译": "Tłumaczenie zdjęć Youdao",
"图片翻译 API": "API tłumaczenia obrazów",
"取消内嵌翻译": "Anuluj wbudowane tłumaczenie",
"使用内嵌翻译": "Używanie wbudowanego tłumaczenia",
"内嵌翻译": "Tłumaczenie wbudowane",
"隐藏不存在的游戏": "Ukryj gry, które nie istnieją",
"宽度": "szerokość",
@ -810,5 +808,6 @@
"固定值": "Wartość stała",
"可选取的": "Wybór",
"投影距离": "Odległość projekcji",
"反转颜色": "odwróć kolory"
"反转颜色": "odwróć kolory",
"内嵌": "Wbudowane"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "Универсальное распознавание текста API",
"有道图片翻译": "Перевод фотографий.",
"图片翻译 API": "Перевод изображений API",
"取消内嵌翻译": "Отменить встроенный перевод",
"使用内嵌翻译": "Использовать встроенный перевод",
"内嵌翻译": "Встроенный перевод",
"隐藏不存在的游戏": "Скрыть несуществующую игру",
"宽度": "Ширина",
@ -810,5 +808,6 @@
"固定值": "Постоянная величина",
"可选取的": "Выбор",
"投影距离": "Расстояние проекции",
"反转颜色": "Инвертировать цвет"
"反转颜色": "Инвертировать цвет",
"内嵌": "Встраивание"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "API การจดจำคำทั่วไป",
"有道图片翻译": "การแปลภาพวิถี",
"图片翻译 API": "แปลภาพ API",
"取消内嵌翻译": "ยกเลิกการแปลแบบอินไลน์",
"使用内嵌翻译": "ใช้การแปลแบบอินไลน์",
"内嵌翻译": "แปลแบบอินไลน์",
"隐藏不存在的游戏": "ซ่อนเกมที่ไม่มีอยู่จริง",
"宽度": "ความกว้าง",
@ -810,5 +808,6 @@
"固定值": "ค่าคงที่",
"可选取的": "เลือกได้",
"投影距离": "ระยะการฉาย",
"反转颜色": "การย้อนกลับสี"
"反转颜色": "การย้อนกลับสี",
"内嵌": "อินไลน์"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "Universal Text Recognition API",
"有道图片翻译": "Youdao Resimlerinin çevirimi",
"图片翻译 API": "Resim Çeviri API",
"取消内嵌翻译": "Yapılan çeviri iptal et",
"使用内嵌翻译": "İçeri çeviri kullanılıyor",
"内嵌翻译": "İçeri yatırılmış çeviri",
"隐藏不存在的游戏": "Olmadığı oyunları gizleyin",
"宽度": "genişlik",
@ -810,5 +808,6 @@
"固定值": "Tam değer",
"可选取的": "Seçilebilir",
"投影距离": "Projeksyon mesafesi",
"反转颜色": "Ters renkler"
"反转颜色": "Ters renkler",
"内嵌": "İçeri"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "Універсальний програмний інтерфейс розпізнавання тексту",
"有道图片翻译": "Переклад зображень Youdao",
"图片翻译 API": "API перекладу зображення",
"取消内嵌翻译": "Скасувати вбудований переклад",
"使用内嵌翻译": "Використання вбудованого перекладу",
"内嵌翻译": "Вбудований переклад",
"隐藏不存在的游戏": "Сховати ігри, які не існують",
"宽度": "ширина",
@ -810,5 +808,6 @@
"固定值": "Визначене значення",
"可选取的": "Вибраний",
"投影距离": "Відстань проекту",
"反转颜色": "звернути кольори"
"反转颜色": "звернути кольори",
"内嵌": "Вбудовано"
}

View File

@ -544,8 +544,6 @@
"通用文字识别 API": "API nhận dạng văn bản chung",
"有道图片翻译": "Có hình dịch",
"图片翻译 API": "Hình ảnh dịch API",
"取消内嵌翻译": "Hủy dịch nội tuyến",
"使用内嵌翻译": "Sử dụng Inline Translation",
"内嵌翻译": "Dịch nội tuyến",
"隐藏不存在的游戏": "Ẩn các trò chơi không tồn tại",
"宽度": "Chiều rộng",
@ -810,5 +808,6 @@
"固定值": "Giá trị cố định",
"可选取的": "Chọn",
"投影距离": "Khoảng cách chiếu",
"反转颜色": "Đảo ngược màu"
"反转颜色": "Đảo ngược màu",
"内嵌": "Nội tuyến"
}

View File

@ -543,8 +543,6 @@
"通用文字识别 API": "",
"有道图片翻译": "",
"图片翻译 API": "",
"取消内嵌翻译": "",
"使用内嵌翻译": "",
"内嵌翻译": "",
"隐藏不存在的游戏": "",
"宽度": "",
@ -810,5 +808,6 @@
"字体倍率": "",
"固定值": "",
"投影距离": "",
"反转颜色": ""
"反转颜色": "",
"内嵌": ""
}