mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
trigger
This commit is contained in:
parent
5af4a27012
commit
efb196f61b
@ -1,6 +1,6 @@
|
||||
from qtsymbols import *
|
||||
import functools, os
|
||||
from myutils.config import globalconfig, ocrsetting, ocrerrorfix
|
||||
from myutils.config import globalconfig, ocrsetting, ocrerrorfix, static_data
|
||||
from myutils.utils import splitocrtypes, dynamiclink
|
||||
from gui.inputdialog import autoinitdialog, postconfigdialog, autoinitdialog_items
|
||||
from gui.usefulwidget import (
|
||||
@ -13,11 +13,16 @@ from gui.usefulwidget import (
|
||||
clearlayout,
|
||||
getboxlayout,
|
||||
selectcolor,
|
||||
TableViewW,
|
||||
listediter,
|
||||
LStandardItemModel,
|
||||
LFocusCombo,
|
||||
threebuttons,
|
||||
)
|
||||
import gobject
|
||||
from gui.dynalang import LFormLayout
|
||||
from gui.dynalang import LFormLayout, LDialog, LAction
|
||||
from myutils.ocrutil import ocr_end, ocr_init
|
||||
from myutils.wrapper import threader
|
||||
from myutils.wrapper import threader, Singleton_close
|
||||
|
||||
|
||||
def __label1(self):
|
||||
@ -38,6 +43,88 @@ def __directinitend(engine, _ok):
|
||||
ocr_end()
|
||||
|
||||
|
||||
@Singleton_close
|
||||
class triggereditor(LDialog):
|
||||
def showmenu(self, p: QPoint):
|
||||
curr = self.hctable.currentIndex()
|
||||
r = curr.row()
|
||||
if r < 0:
|
||||
return
|
||||
menu = QMenu(self.hctable)
|
||||
remove = LAction("删除")
|
||||
menu.addAction(remove)
|
||||
action = menu.exec(self.hctable.cursor().pos())
|
||||
|
||||
if action == remove:
|
||||
self.hctable.removeselectedrows()
|
||||
|
||||
def moverank(self, dy):
|
||||
src, tgt = self.hctable.moverank(dy)
|
||||
self.internalrealname.insert(tgt, self.internalrealname.pop(src))
|
||||
|
||||
def __init__(self, parent) -> None:
|
||||
super().__init__(parent)
|
||||
self.list = globalconfig["ocr_trigger_events"]
|
||||
|
||||
self.setWindowTitle("触发事件")
|
||||
model = LStandardItemModel()
|
||||
model.setHorizontalHeaderLabels(["按键", "事件"])
|
||||
self.hcmodel = model
|
||||
table = TableViewW()
|
||||
table.horizontalHeader().setSectionResizeMode(
|
||||
QHeaderView.ResizeMode.ResizeToContents
|
||||
)
|
||||
table.horizontalHeader().setStretchLastSection(True)
|
||||
table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
||||
table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection))
|
||||
table.setWordWrap(False)
|
||||
table.setModel(model)
|
||||
|
||||
table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
table.customContextMenuRequested.connect(self.showmenu)
|
||||
self.hctable = table
|
||||
self.internalrealname = []
|
||||
formLayout = QVBoxLayout()
|
||||
self.setLayout(formLayout)
|
||||
formLayout.addWidget(self.hctable)
|
||||
self.vkeys = list(static_data["vkcode_map"].keys())
|
||||
for row, k in enumerate(self.list): # 2
|
||||
self.hcmodel.insertRow(row, [QStandardItem(), QStandardItem()])
|
||||
combo = LFocusCombo()
|
||||
combo.addItems(self.vkeys)
|
||||
combo.setCurrentIndex(self.vkeys.index(k["vkey"]))
|
||||
self.hctable.setIndexWidget(self.hcmodel.index(row, 0), combo)
|
||||
combo = LFocusCombo()
|
||||
combo.addItems(["按下", "松开"])
|
||||
combo.setCurrentIndex(k["event"])
|
||||
self.hctable.setIndexWidget(self.hcmodel.index(row, 1), combo)
|
||||
self.buttons = threebuttons(texts=["添加行", "删除行"])
|
||||
self.buttons.btn1clicked.connect(self.click1)
|
||||
self.buttons.btn2clicked.connect(self.hctable.removeselectedrows)
|
||||
|
||||
formLayout.addWidget(self.buttons)
|
||||
self.resize(600, self.sizeHint().height())
|
||||
self.show()
|
||||
|
||||
def closeEvent(self, a0: QCloseEvent) -> None:
|
||||
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()
|
||||
self.list.append({"vkey": self.vkeys[i0], "event": i1})
|
||||
|
||||
def click1(self):
|
||||
self.hcmodel.insertRow(0, [QStandardItem(), QStandardItem()])
|
||||
combo = LFocusCombo()
|
||||
combo.addItems(self.vkeys)
|
||||
self.hctable.setIndexWidget(self.hcmodel.index(0, 0), combo)
|
||||
combo = LFocusCombo()
|
||||
combo.addItems(["按下", "松开"])
|
||||
self.hctable.setIndexWidget(self.hcmodel.index(0, 1), combo)
|
||||
|
||||
|
||||
def initgridsources(self, names):
|
||||
line = []
|
||||
i = 0
|
||||
@ -107,6 +194,17 @@ def _ocrparam_create(self, idx):
|
||||
),
|
||||
)
|
||||
if idx in [3]:
|
||||
self._ocrparaml.addRow(
|
||||
"触发事件",
|
||||
getboxlayout(
|
||||
[
|
||||
D_getIconButton(
|
||||
functools.partial(triggereditor, self),
|
||||
"fa.gear",
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
self._ocrparaml.addRow(
|
||||
"延迟(s)",
|
||||
getboxlayout(
|
||||
|
@ -1,5 +1,5 @@
|
||||
import time, os, threading
|
||||
from myutils.config import globalconfig
|
||||
from myutils.config import globalconfig, static_data
|
||||
import winsharedutils, windows
|
||||
from gui.rangeselect import rangeadjust
|
||||
from myutils.wrapper import threader
|
||||
@ -95,7 +95,7 @@ class ocrtext(basetext):
|
||||
|
||||
@threader
|
||||
def gettextthread(self):
|
||||
laststate = (0, 0, 0, 0, 0)
|
||||
laststate = tuple((0 for _ in range(len(globalconfig["ocr_trigger_events"]))))
|
||||
while not self.ending:
|
||||
if not self.isautorunning:
|
||||
time.sleep(0.1)
|
||||
@ -103,20 +103,23 @@ class ocrtext(basetext):
|
||||
|
||||
if globalconfig["ocr_auto_method"] == 3:
|
||||
triggered = False
|
||||
this = (
|
||||
windows.GetAsyncKeyState(windows.VK_LBUTTON),
|
||||
windows.GetAsyncKeyState(windows.VK_RETURN),
|
||||
windows.GetAsyncKeyState(windows.VK_CONTROL),
|
||||
windows.GetAsyncKeyState(windows.VK_SHIFT),
|
||||
windows.GetAsyncKeyState(windows.VK_MENU),
|
||||
this = tuple(
|
||||
(
|
||||
windows.GetAsyncKeyState(
|
||||
static_data["vkcode_map"][line["vkey"]]
|
||||
)
|
||||
for line in globalconfig["ocr_trigger_events"]
|
||||
)
|
||||
)
|
||||
for _, line in enumerate(globalconfig["ocr_trigger_events"]):
|
||||
event = line["event"]
|
||||
press = this[_]
|
||||
if ((event == 0) and (laststate[_] == 0) and press) or (
|
||||
(event == 1) and laststate[_] and (press == 0)
|
||||
):
|
||||
triggered = True
|
||||
break
|
||||
|
||||
if any(((this[_] and (laststate[_] == 0)) for _ in (0, 1))):
|
||||
# 按下
|
||||
triggered = True
|
||||
elif any(((this[_] == 0 and laststate[_]) for _ in (2, 3, 4))):
|
||||
# 松开
|
||||
triggered = True
|
||||
laststate = this
|
||||
if triggered:
|
||||
if gobject.baseobject.hwnd:
|
||||
@ -149,7 +152,9 @@ class ocrtext(basetext):
|
||||
self.dispatchtext(t)
|
||||
time.sleep(0.01)
|
||||
else:
|
||||
laststate = (0, 0, 0, 0, 0)
|
||||
laststate = tuple(
|
||||
(0 for _ in range(len(globalconfig["ocr_trigger_events"])))
|
||||
)
|
||||
t = self.getallres(True)
|
||||
if t:
|
||||
self.dispatchtext(t)
|
||||
|
@ -2018,6 +2018,28 @@
|
||||
"ocr_auto_method": 0,
|
||||
"ocr_interval": 5,
|
||||
"ocr_trigger_delay": 0,
|
||||
"ocr_trigger_events": [
|
||||
{
|
||||
"vkey": "LBUTTON",
|
||||
"event": 0
|
||||
},
|
||||
{
|
||||
"vkey": "ENTER",
|
||||
"event": 0
|
||||
},
|
||||
{
|
||||
"vkey": "CTRL",
|
||||
"event": 1
|
||||
},
|
||||
{
|
||||
"vkey": "ALT",
|
||||
"event": 1
|
||||
},
|
||||
{
|
||||
"vkey": "SHIFT",
|
||||
"event": 1
|
||||
}
|
||||
],
|
||||
"mustocr_interval": 5,
|
||||
"ocrmininterval": 1,
|
||||
"selectable": false,
|
||||
|
@ -1166,6 +1166,8 @@
|
||||
"ALT": 1
|
||||
},
|
||||
"vkcode_map": {
|
||||
"LBUTTON": 1,
|
||||
"RBUTTON": 2,
|
||||
"F1": 112,
|
||||
"F2": 113,
|
||||
"F3": 114,
|
||||
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "تلقائيا ملزمة نافذة بعد تحديد نطاق التعرف الضوئي على الحروف",
|
||||
"延迟(s)": "تأخير ( ق )",
|
||||
"鼠标键盘触发+等待稳定": "الماوس لوحة المفاتيح الزناد + انتظار الاستقرار",
|
||||
"匈牙利语": "اللغة الهنغارية"
|
||||
"匈牙利语": "اللغة الهنغارية",
|
||||
"触发事件": "الحدث الزناد",
|
||||
"按键": "مفتاح",
|
||||
"事件": "الأحداث",
|
||||
"按下": "ضغط",
|
||||
"松开": "خففت"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "選取OCR範圍後自動綁定視窗",
|
||||
"延迟(s)": "延遲(s)",
|
||||
"鼠标键盘触发+等待稳定": "滑鼠鍵盤觸發+等待穩定",
|
||||
"匈牙利语": "匈牙利語"
|
||||
"匈牙利语": "匈牙利語",
|
||||
"触发事件": "觸發事件",
|
||||
"按键": "按鍵",
|
||||
"事件": "事件",
|
||||
"按下": "按下",
|
||||
"松开": "鬆開"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Automaticky vázat okno po výběru rozsahu OCR",
|
||||
"延迟(s)": "Zpoždění (s)",
|
||||
"鼠标键盘触发+等待稳定": "Spouštěč myši a klávesnice+čekání na stabilizaci",
|
||||
"匈牙利语": "Maďarština"
|
||||
"匈牙利语": "Maďarština",
|
||||
"触发事件": "Spouštěcí událost",
|
||||
"按键": "Klíč",
|
||||
"事件": "událost",
|
||||
"按下": "Stiskněte dolů",
|
||||
"松开": "uvolnění"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Fenster nach Auswahl des OCR-Bereichs automatisch binden",
|
||||
"延迟(s)": "Verzögerung (s)",
|
||||
"鼠标键盘触发+等待稳定": "Maus und Tastatur Trigger+warten auf Stabilisierung",
|
||||
"匈牙利语": "Ungarische Sprache"
|
||||
"匈牙利语": "Ungarische Sprache",
|
||||
"触发事件": "Auslöseereignis",
|
||||
"按键": "Schlüssel",
|
||||
"事件": "Ereignis",
|
||||
"按下": "Drücken Sie nach unten",
|
||||
"松开": "Freigabe"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Automatically bind window after selecting OCR range",
|
||||
"延迟(s)": "Delay (s)",
|
||||
"鼠标键盘触发+等待稳定": "Mouse and keyboard trigger+waiting for stabilization",
|
||||
"匈牙利语": "Hungarian language"
|
||||
"匈牙利语": "Hungarian language",
|
||||
"触发事件": "Trigger event",
|
||||
"按键": "Key",
|
||||
"事件": "event",
|
||||
"按下": "Press down",
|
||||
"松开": "release"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Vincular automáticamente la ventana después de seleccionar el rango OCR",
|
||||
"延迟(s)": "Retraso (s)",
|
||||
"鼠标键盘触发+等待稳定": "Activación del ratón y el teclado + espera para estabilizarse",
|
||||
"匈牙利语": "Húngaro"
|
||||
"匈牙利语": "Húngaro",
|
||||
"触发事件": "Evento desencadenante",
|
||||
"按键": "Teclas",
|
||||
"事件": "Incidencias",
|
||||
"按下": "Presionar",
|
||||
"松开": "Soltar"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Fenêtre de liaison automatique après sélection de la plage ocr",
|
||||
"延迟(s)": "Retard (s)",
|
||||
"鼠标键盘触发+等待稳定": "Déclenchement du clavier de la souris + attente de stabilisation",
|
||||
"匈牙利语": "Hongrois"
|
||||
"匈牙利语": "Hongrois",
|
||||
"触发事件": "Événements déclenchés",
|
||||
"按键": "Appuyez sur la clé",
|
||||
"事件": "Événements",
|
||||
"按下": "Appuyez sur",
|
||||
"松开": "Desserrer"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Associa automaticamente la finestra dopo aver selezionato l'intervallo OCR",
|
||||
"延迟(s)": "Ritardo (s)",
|
||||
"鼠标键盘触发+等待稳定": "Mouse e tastiera trigger + attesa di stabilizzazione",
|
||||
"匈牙利语": "Lingua ungherese"
|
||||
"匈牙利语": "Lingua ungherese",
|
||||
"触发事件": "Evento di attivazione",
|
||||
"按键": "Chiave",
|
||||
"事件": "evento",
|
||||
"按下": "Premere verso il basso",
|
||||
"松开": "rilascio"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "OCR範囲を選択するとウィンドウが自動的にバインドされます",
|
||||
"延迟(s)": "遅延(s)",
|
||||
"鼠标键盘触发+等待稳定": "マウスのキーボードトリガ+待機安定",
|
||||
"匈牙利语": "ハンガリー語"
|
||||
"匈牙利语": "ハンガリー語",
|
||||
"触发事件": "イベントのトリガー",
|
||||
"按键": "キーを押す",
|
||||
"事件": "イベント#イベント#",
|
||||
"按下": "押す",
|
||||
"松开": "ゆるめる"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "OCR 범위 선택 후 창 자동 바인딩",
|
||||
"延迟(s)": "지연 (s)",
|
||||
"鼠标键盘触发+等待稳定": "마우스 키보드 트리거 + 안정 대기 중",
|
||||
"匈牙利语": "헝가리어"
|
||||
"匈牙利语": "헝가리어",
|
||||
"触发事件": "이벤트 트리거",
|
||||
"按键": "키",
|
||||
"事件": "이벤트",
|
||||
"按下": "누르기",
|
||||
"松开": "풀어"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Venster automatisch binden na het selecteren van OCR-bereik",
|
||||
"延迟(s)": "Vertraging (s)",
|
||||
"鼠标键盘触发+等待稳定": "Muis en toetsenbord trigger+wachten op stabilisatie",
|
||||
"匈牙利语": "Hongaarse taal"
|
||||
"匈牙利语": "Hongaarse taal",
|
||||
"触发事件": "Trigger gebeurtenis",
|
||||
"按键": "Sleutel",
|
||||
"事件": "gebeurtenis",
|
||||
"按下": "Druk omlaag",
|
||||
"松开": "release"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Automatycznie wiąże okno po wybraniu zakresu OCR",
|
||||
"延迟(s)": "Opóźnienie (s)",
|
||||
"鼠标键盘触发+等待稳定": "Wyzwalacz myszy i klawiatury+oczekiwanie na stabilizację",
|
||||
"匈牙利语": "Język węgierski"
|
||||
"匈牙利语": "Język węgierski",
|
||||
"触发事件": "Wyzwalanie zdarzenia",
|
||||
"按键": "Klucz",
|
||||
"事件": "zdarzenie",
|
||||
"按下": "Naciśnij w dół",
|
||||
"松开": "uwolnienie"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Vincular automaticamente a janela após selecionar o intervalo de OCR",
|
||||
"延迟(s)": "Atraso (s)",
|
||||
"鼠标键盘触发+等待稳定": "Mouse e teclado gatilho + aguardando estabilização",
|
||||
"匈牙利语": "Língua húngara"
|
||||
"匈牙利语": "Língua húngara",
|
||||
"触发事件": "Evento de disparo",
|
||||
"按键": "Chave",
|
||||
"事件": "evento",
|
||||
"按下": "Pressione para baixo",
|
||||
"松开": "libertação"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Выберите диапазон OCR и автоматически свяжите окно",
|
||||
"延迟(s)": "Задержка (s)",
|
||||
"鼠标键盘触发+等待稳定": "Запуск клавиатуры мыши + Ожидание стабилизации",
|
||||
"匈牙利语": "Венгерский язык"
|
||||
"匈牙利语": "Венгерский язык",
|
||||
"触发事件": "Событие запуска",
|
||||
"按键": "Клавиши",
|
||||
"事件": "События",
|
||||
"按下": "Нажмите",
|
||||
"松开": "Отпусти."
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Bind automatiskt fönster efter markerat OCR-område",
|
||||
"延迟(s)": "Försening (s)",
|
||||
"鼠标键盘触发+等待稳定": "Mus och tangentbord trigger + väntar på stabilisering",
|
||||
"匈牙利语": "Ungerska språket"
|
||||
"匈牙利语": "Ungerska språket",
|
||||
"触发事件": "Trigger- händelse",
|
||||
"按键": "Nyckel",
|
||||
"事件": "händelse",
|
||||
"按下": "Tryck ner",
|
||||
"松开": "frigörande"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "ผูกหน้าต่างโดยอัตโนมัติหลังจากเลือกช่วง OCR",
|
||||
"延迟(s)": "ความล่าช้า (s)",
|
||||
"鼠标键盘触发+等待稳定": "เมาส์คีย์บอร์ดทริกเกอร์ + รอความมั่นคง",
|
||||
"匈牙利语": "ฮังการี"
|
||||
"匈牙利语": "ฮังการี",
|
||||
"触发事件": "เหตุการณ์ทริกเกอร์",
|
||||
"按键": "ปุ่มกด",
|
||||
"事件": "กิจกรรม",
|
||||
"按下": "กด",
|
||||
"松开": "ปล่อย"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "OCR menzili seçmeden sonra pencereyi otomatik bağlayın",
|
||||
"延迟(s)": "Geç",
|
||||
"鼠标键盘触发+等待稳定": "Fare ve klavye tetikleyici+stabilizasyonu bekliyor",
|
||||
"匈牙利语": "Macar dili"
|
||||
"匈牙利语": "Macar dili",
|
||||
"触发事件": "Dönüştürme olayını",
|
||||
"按键": "Anahtar",
|
||||
"事件": "Olay",
|
||||
"按下": "Aşağı basın",
|
||||
"松开": "serbest"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Автоматично зв’ язати вікно після вибору діапазону OCR",
|
||||
"延迟(s)": "Затримка (с)",
|
||||
"鼠标键盘触发+等待稳定": "Пуск миші і клавіатури+чекає на стабілізацію",
|
||||
"匈牙利语": "Угорська мова"
|
||||
"匈牙利语": "Угорська мова",
|
||||
"触发事件": "Подія пересування",
|
||||
"按键": "Ключ",
|
||||
"事件": "подія",
|
||||
"按下": "Натисніть вниз",
|
||||
"松开": "випускати"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "Tự động ràng buộc cửa sổ sau khi chọn phạm vi OCR",
|
||||
"延迟(s)": "Độ trễ (s)",
|
||||
"鼠标键盘触发+等待稳定": "Kích hoạt bàn phím chuột+chờ ổn định",
|
||||
"匈牙利语": "Việt Nam"
|
||||
"匈牙利语": "Việt Nam",
|
||||
"触发事件": "Sự kiện kích hoạt",
|
||||
"按键": "Phím",
|
||||
"事件": "Sự kiện",
|
||||
"按下": "Nhấn",
|
||||
"松开": "Thả lỏng"
|
||||
}
|
@ -837,5 +837,10 @@
|
||||
"选取OCR范围后自动绑定窗口": "",
|
||||
"延迟(s)": "",
|
||||
"鼠标键盘触发+等待稳定": "",
|
||||
"匈牙利语": ""
|
||||
"匈牙利语": "",
|
||||
"触发事件": "",
|
||||
"按键": "",
|
||||
"事件": "",
|
||||
"按下": "",
|
||||
"松开": ""
|
||||
}
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
||||
|
||||
set(VERSION_MAJOR 5)
|
||||
set(VERSION_MINOR 30)
|
||||
set(VERSION_PATCH 0)
|
||||
set(VERSION_PATCH 1)
|
||||
|
||||
add_library(pch pch.cpp)
|
||||
target_precompile_headers(pch PUBLIC pch.h)
|
||||
|
Loading…
x
Reference in New Issue
Block a user