From 8b6f64e041d084900ed785193fd943bc6513bf3f Mon Sep 17 00:00:00 2001 From: 283375 Date: Tue, 10 Oct 2023 19:50:27 +0800 Subject: [PATCH] wip: arcaea-offline-ocr==0.1.0 ui changes --- ui/designer/tabs/tabOcr/tabOcr_Device.ui | 327 +++++++++++++------- ui/designer/tabs/tabOcr/tabOcr_Device_ui.py | 238 +++++++++----- ui/implements/tabs/tabOcr/tabOcr_Device.py | 138 ++++++--- ui/resources/lang/en_US.ts | 42 ++- ui/resources/lang/zh_CN.ts | 42 ++- 5 files changed, 526 insertions(+), 261 deletions(-) diff --git a/ui/designer/tabs/tabOcr/tabOcr_Device.ui b/ui/designer/tabs/tabOcr/tabOcr_Device.ui index 4fab6c0..8c76113 100644 --- a/ui/designer/tabs/tabOcr/tabOcr_Device.ui +++ b/ui/designer/tabs/tabOcr/tabOcr_Device.ui @@ -24,130 +24,237 @@ - deviceSelector.title + options.title - + - + - + - deviceSelector.useAutoFactor + options.usePreset - - - SizesV2 + + + false - + + + Qt::Vertical + + - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + options.rois + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + options.masker + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + options.useCustom + + + + + + + options.useCustom + + + + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + - - - - 0 - 0 - + + + dependencies.title - - - 0 - - - 0 - - - 0 - - - 0 - - - - - knnModelSelector.title + + + + + dependencies.knnModel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - 0 + + + + ... + + + + + + + ... + + + + + + + + + + Qt::Vertical + + + + + + + + + + dependencies.phashDatabase + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Vertical - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - tesseractSelector.title - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - phashDatabaseSelector.title - - - - - - - - - - @@ -178,12 +285,24 @@
ui.implements.components.ocrQueue
1 - - DevicesComboBox - QComboBox -
ui.implements.components.devicesComboBox
-
- + + + options_usePresetCheckBox + toggled(bool) + options_presetComboBox + setEnabled(bool) + + + 82 + 111 + + + 82 + 175 + + + + diff --git a/ui/designer/tabs/tabOcr/tabOcr_Device_ui.py b/ui/designer/tabs/tabOcr/tabOcr_Device_ui.py index 40ab0ab..f714894 100644 --- a/ui/designer/tabs/tabOcr/tabOcr_Device_ui.py +++ b/ui/designer/tabs/tabOcr/tabOcr_Device_ui.py @@ -15,11 +15,11 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QGradient, QIcon, QImage, QKeySequence, QLinearGradient, QPainter, QPalette, QPixmap, QRadialGradient, QTransform) -from PySide6.QtWidgets import (QApplication, QCheckBox, QGroupBox, QHBoxLayout, +from PySide6.QtWidgets import (QApplication, QCheckBox, QComboBox, QFrame, + QGridLayout, QGroupBox, QHBoxLayout, QLabel, QPushButton, QSizePolicy, QStackedWidget, QVBoxLayout, QWidget) -from ui.implements.components.devicesComboBox import DevicesComboBox from ui.implements.components.fileSelector import FileSelector from ui.implements.components.ocrQueue import OcrQueue @@ -38,117 +38,191 @@ class Ui_TabOcr_Device(object): self.groupBox = QGroupBox(TabOcr_Device) self.groupBox.setObjectName(u"groupBox") - self.verticalLayout = QVBoxLayout(self.groupBox) - self.verticalLayout.setObjectName(u"verticalLayout") - self.horizontalLayout = QHBoxLayout() + self.horizontalLayout = QHBoxLayout(self.groupBox) self.horizontalLayout.setObjectName(u"horizontalLayout") - self.deviceUseAutoFactorCheckBox = QCheckBox(self.groupBox) - self.deviceUseAutoFactorCheckBox.setObjectName(u"deviceUseAutoFactorCheckBox") + self.verticalLayout = QVBoxLayout() + self.verticalLayout.setObjectName(u"verticalLayout") + self.options_usePresetCheckBox = QCheckBox(self.groupBox) + self.options_usePresetCheckBox.setObjectName(u"options_usePresetCheckBox") - self.horizontalLayout.addWidget(self.deviceUseAutoFactorCheckBox) + self.verticalLayout.addWidget(self.options_usePresetCheckBox) - self.deviceSizesV2CheckBox = QCheckBox(self.groupBox) - self.deviceSizesV2CheckBox.setObjectName(u"deviceSizesV2CheckBox") - self.deviceSizesV2CheckBox.setText(u"SizesV2") + self.options_presetComboBox = QComboBox(self.groupBox) + self.options_presetComboBox.setObjectName(u"options_presetComboBox") + self.options_presetComboBox.setEnabled(False) - self.horizontalLayout.addWidget(self.deviceSizesV2CheckBox) + self.verticalLayout.addWidget(self.options_presetComboBox) - self.verticalLayout.addLayout(self.horizontalLayout) + self.horizontalLayout.addLayout(self.verticalLayout) - self.deviceFileSelector = FileSelector(self.groupBox) - self.deviceFileSelector.setObjectName(u"deviceFileSelector") + self.line_3 = QFrame(self.groupBox) + self.line_3.setObjectName(u"line_3") + self.line_3.setFrameShape(QFrame.VLine) + self.line_3.setFrameShadow(QFrame.Sunken) - self.verticalLayout.addWidget(self.deviceFileSelector) + self.horizontalLayout.addWidget(self.line_3) - self.deviceComboBox = DevicesComboBox(self.groupBox) - self.deviceComboBox.setObjectName(u"deviceComboBox") + self.options_preciseControlWidget = QWidget(self.groupBox) + self.options_preciseControlWidget.setObjectName(u"options_preciseControlWidget") + self.gridLayout_2 = QGridLayout(self.options_preciseControlWidget) + self.gridLayout_2.setObjectName(u"gridLayout_2") + self.gridLayout_2.setContentsMargins(0, 0, 0, 0) + self.label = QLabel(self.options_preciseControlWidget) + self.label.setObjectName(u"label") + self.label.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) - self.verticalLayout.addWidget(self.deviceComboBox) + self.gridLayout_2.addWidget(self.label, 0, 0, 1, 1) + + self.options_roisStackedWidget = QStackedWidget(self.options_preciseControlWidget) + self.options_roisStackedWidget.setObjectName(u"options_roisStackedWidget") + self.page = QWidget() + self.page.setObjectName(u"page") + self.verticalLayout_2 = QVBoxLayout(self.page) + self.verticalLayout_2.setObjectName(u"verticalLayout_2") + self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) + self.options_roisComboBox = QComboBox(self.page) + self.options_roisComboBox.setObjectName(u"options_roisComboBox") + + self.verticalLayout_2.addWidget(self.options_roisComboBox) + + self.options_roisStackedWidget.addWidget(self.page) + self.page_2 = QWidget() + self.page_2.setObjectName(u"page_2") + self.verticalLayout_4 = QVBoxLayout(self.page_2) + self.verticalLayout_4.setObjectName(u"verticalLayout_4") + self.verticalLayout_4.setContentsMargins(0, 0, 0, 0) + self.options_roisCustomSelector = FileSelector(self.page_2) + self.options_roisCustomSelector.setObjectName(u"options_roisCustomSelector") + + self.verticalLayout_4.addWidget(self.options_roisCustomSelector) + + self.options_roisStackedWidget.addWidget(self.page_2) + + self.gridLayout_2.addWidget(self.options_roisStackedWidget, 0, 1, 1, 1) + + self.label_2 = QLabel(self.options_preciseControlWidget) + self.label_2.setObjectName(u"label_2") + self.label_2.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) + + self.gridLayout_2.addWidget(self.label_2, 1, 0, 1, 1) + + self.options_roisUseCustomCheckBox = QCheckBox(self.options_preciseControlWidget) + self.options_roisUseCustomCheckBox.setObjectName(u"options_roisUseCustomCheckBox") + + self.gridLayout_2.addWidget(self.options_roisUseCustomCheckBox, 0, 2, 1, 1) + + self.options_maskerUseCustomCheckBox = QCheckBox(self.options_preciseControlWidget) + self.options_maskerUseCustomCheckBox.setObjectName(u"options_maskerUseCustomCheckBox") + + self.gridLayout_2.addWidget(self.options_maskerUseCustomCheckBox, 1, 2, 1, 1) + + self.options_maskerStackedWidget = QStackedWidget(self.options_preciseControlWidget) + self.options_maskerStackedWidget.setObjectName(u"options_maskerStackedWidget") + self.page_3 = QWidget() + self.page_3.setObjectName(u"page_3") + self.verticalLayout_5 = QVBoxLayout(self.page_3) + self.verticalLayout_5.setObjectName(u"verticalLayout_5") + self.verticalLayout_5.setContentsMargins(0, 0, 0, 0) + self.options_maskerComboBox = QComboBox(self.page_3) + self.options_maskerComboBox.setObjectName(u"options_maskerComboBox") + + self.verticalLayout_5.addWidget(self.options_maskerComboBox) + + self.options_maskerStackedWidget.addWidget(self.page_3) + self.page_4 = QWidget() + self.page_4.setObjectName(u"page_4") + self.verticalLayout_6 = QVBoxLayout(self.page_4) + self.verticalLayout_6.setObjectName(u"verticalLayout_6") + self.verticalLayout_6.setContentsMargins(0, 0, 0, 0) + self.options_maskerCustomSelector = FileSelector(self.page_4) + self.options_maskerCustomSelector.setObjectName(u"options_maskerCustomSelector") + + self.verticalLayout_6.addWidget(self.options_maskerCustomSelector) + + self.options_maskerStackedWidget.addWidget(self.page_4) + + self.gridLayout_2.addWidget(self.options_maskerStackedWidget, 1, 1, 1, 1) + + self.gridLayout_2.setColumnStretch(1, 1) + + self.horizontalLayout.addWidget(self.options_preciseControlWidget) self.verticalLayout_3.addWidget(self.groupBox) - self.horizontalWidget = QWidget(TabOcr_Device) - self.horizontalWidget.setObjectName(u"horizontalWidget") - sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.horizontalWidget.sizePolicy().hasHeightForWidth()) - self.horizontalWidget.setSizePolicy(sizePolicy) - self.horizontalLayout_2 = QHBoxLayout(self.horizontalWidget) - self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") - self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) - self.groupBox_6 = QGroupBox(self.horizontalWidget) - self.groupBox_6.setObjectName(u"groupBox_6") - self.verticalLayout_6 = QVBoxLayout(self.groupBox_6) - self.verticalLayout_6.setObjectName(u"verticalLayout_6") - self.knnModelSelector = FileSelector(self.groupBox_6) - self.knnModelSelector.setObjectName(u"knnModelSelector") + self.groupBox_2 = QGroupBox(TabOcr_Device) + self.groupBox_2.setObjectName(u"groupBox_2") + self.gridLayout = QGridLayout(self.groupBox_2) + self.gridLayout.setObjectName(u"gridLayout") + self.label_3 = QLabel(self.groupBox_2) + self.label_3.setObjectName(u"label_3") + self.label_3.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) - self.verticalLayout_6.addWidget(self.knnModelSelector) + self.gridLayout.addWidget(self.label_3, 0, 0, 1, 1) + self.dependencies_knnModelStatusLabel = QLabel(self.groupBox_2) + self.dependencies_knnModelStatusLabel.setObjectName(u"dependencies_knnModelStatusLabel") + self.dependencies_knnModelStatusLabel.setText(u"...") - self.horizontalLayout_2.addWidget(self.groupBox_6) + self.gridLayout.addWidget(self.dependencies_knnModelStatusLabel, 0, 2, 1, 1) - self.deviceDependenciesStackedWidget = QStackedWidget(self.horizontalWidget) - self.deviceDependenciesStackedWidget.setObjectName(u"deviceDependenciesStackedWidget") - self.deviceV1 = QWidget() - self.deviceV1.setObjectName(u"deviceV1") - self.verticalLayout_2 = QVBoxLayout(self.deviceV1) - self.verticalLayout_2.setObjectName(u"verticalLayout_2") - self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) - self.groupBox_4 = QGroupBox(self.deviceV1) - self.groupBox_4.setObjectName(u"groupBox_4") - self.verticalLayout_5 = QVBoxLayout(self.groupBox_4) - self.verticalLayout_5.setObjectName(u"verticalLayout_5") - self.tesseractFileSelector = FileSelector(self.groupBox_4) - self.tesseractFileSelector.setObjectName(u"tesseractFileSelector") + self.dependencies_phashDatabaseStatusLabel = QLabel(self.groupBox_2) + self.dependencies_phashDatabaseStatusLabel.setObjectName(u"dependencies_phashDatabaseStatusLabel") + self.dependencies_phashDatabaseStatusLabel.setText(u"...") - self.verticalLayout_5.addWidget(self.tesseractFileSelector) + self.gridLayout.addWidget(self.dependencies_phashDatabaseStatusLabel, 1, 2, 1, 1) + self.dependencies_phashDatabaseSelector = FileSelector(self.groupBox_2) + self.dependencies_phashDatabaseSelector.setObjectName(u"dependencies_phashDatabaseSelector") - self.verticalLayout_2.addWidget(self.groupBox_4) + self.gridLayout.addWidget(self.dependencies_phashDatabaseSelector, 1, 4, 1, 1) - self.deviceDependenciesStackedWidget.addWidget(self.deviceV1) - self.deviceV2 = QWidget() - self.deviceV2.setObjectName(u"deviceV2") - self.verticalLayout_4 = QVBoxLayout(self.deviceV2) - self.verticalLayout_4.setObjectName(u"verticalLayout_4") - self.verticalLayout_4.setContentsMargins(0, 0, 0, 0) - self.groupBox_5 = QGroupBox(self.deviceV2) - self.groupBox_5.setObjectName(u"groupBox_5") - self.verticalLayout_7 = QVBoxLayout(self.groupBox_5) - self.verticalLayout_7.setObjectName(u"verticalLayout_7") - self.phashDatabaseSelector = FileSelector(self.groupBox_5) - self.phashDatabaseSelector.setObjectName(u"phashDatabaseSelector") + self.line = QFrame(self.groupBox_2) + self.line.setObjectName(u"line") + self.line.setFrameShape(QFrame.VLine) + self.line.setFrameShadow(QFrame.Sunken) - self.verticalLayout_7.addWidget(self.phashDatabaseSelector) + self.gridLayout.addWidget(self.line, 0, 1, 2, 1) + self.dependencies_knnModelSelector = FileSelector(self.groupBox_2) + self.dependencies_knnModelSelector.setObjectName(u"dependencies_knnModelSelector") - self.verticalLayout_4.addWidget(self.groupBox_5) + self.gridLayout.addWidget(self.dependencies_knnModelSelector, 0, 4, 1, 1) - self.deviceDependenciesStackedWidget.addWidget(self.deviceV2) + self.label_4 = QLabel(self.groupBox_2) + self.label_4.setObjectName(u"label_4") + self.label_4.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) - self.horizontalLayout_2.addWidget(self.deviceDependenciesStackedWidget) + self.gridLayout.addWidget(self.label_4, 1, 0, 1, 1) + self.line_2 = QFrame(self.groupBox_2) + self.line_2.setObjectName(u"line_2") + self.line_2.setFrameShape(QFrame.VLine) + self.line_2.setFrameShadow(QFrame.Sunken) - self.verticalLayout_3.addWidget(self.horizontalWidget) + self.gridLayout.addWidget(self.line_2, 0, 3, 2, 1) + + self.gridLayout.setColumnStretch(4, 1) + + self.verticalLayout_3.addWidget(self.groupBox_2) self.ocrQueue = OcrQueue(TabOcr_Device) self.ocrQueue.setObjectName(u"ocrQueue") - sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) - sizePolicy1.setHorizontalStretch(0) - sizePolicy1.setVerticalStretch(0) - sizePolicy1.setHeightForWidth(self.ocrQueue.sizePolicy().hasHeightForWidth()) - self.ocrQueue.setSizePolicy(sizePolicy1) + sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.ocrQueue.sizePolicy().hasHeightForWidth()) + self.ocrQueue.setSizePolicy(sizePolicy) self.verticalLayout_3.addWidget(self.ocrQueue) self.retranslateUi(TabOcr_Device) + self.options_usePresetCheckBox.toggled.connect(self.options_presetComboBox.setEnabled) - self.deviceDependenciesStackedWidget.setCurrentIndex(0) + self.options_roisStackedWidget.setCurrentIndex(0) + self.options_maskerStackedWidget.setCurrentIndex(0) QMetaObject.connectSlotsByName(TabOcr_Device) @@ -156,11 +230,15 @@ class Ui_TabOcr_Device(object): def retranslateUi(self, TabOcr_Device): self.openWizardButton.setText(QCoreApplication.translate("TabOcr_Device", u"openWizardButton", None)) - self.groupBox.setTitle(QCoreApplication.translate("TabOcr_Device", u"deviceSelector.title", None)) - self.deviceUseAutoFactorCheckBox.setText(QCoreApplication.translate("TabOcr_Device", u"deviceSelector.useAutoFactor", None)) - self.groupBox_6.setTitle(QCoreApplication.translate("TabOcr_Device", u"knnModelSelector.title", None)) - self.groupBox_4.setTitle(QCoreApplication.translate("TabOcr_Device", u"tesseractSelector.title", None)) - self.groupBox_5.setTitle(QCoreApplication.translate("TabOcr_Device", u"phashDatabaseSelector.title", None)) + self.groupBox.setTitle(QCoreApplication.translate("TabOcr_Device", u"options.title", None)) + self.options_usePresetCheckBox.setText(QCoreApplication.translate("TabOcr_Device", u"options.usePreset", None)) + self.label.setText(QCoreApplication.translate("TabOcr_Device", u"options.rois", None)) + self.label_2.setText(QCoreApplication.translate("TabOcr_Device", u"options.masker", None)) + self.options_roisUseCustomCheckBox.setText(QCoreApplication.translate("TabOcr_Device", u"options.useCustom", None)) + self.options_maskerUseCustomCheckBox.setText(QCoreApplication.translate("TabOcr_Device", u"options.useCustom", None)) + self.groupBox_2.setTitle(QCoreApplication.translate("TabOcr_Device", u"dependencies.title", None)) + self.label_3.setText(QCoreApplication.translate("TabOcr_Device", u"dependencies.knnModel", None)) + self.label_4.setText(QCoreApplication.translate("TabOcr_Device", u"dependencies.phashDatabase", None)) pass # retranslateUi diff --git a/ui/implements/tabs/tabOcr/tabOcr_Device.py b/ui/implements/tabs/tabOcr/tabOcr_Device.py index 0cd3580..57b1bf9 100644 --- a/ui/implements/tabs/tabOcr/tabOcr_Device.py +++ b/ui/implements/tabs/tabOcr/tabOcr_Device.py @@ -1,31 +1,21 @@ import logging import cv2 - -# from arcaea_offline_ocr_device_creation_wizard.implements.wizard import Wizard -from arcaea_offline_ocr.device.v1.definition import DeviceV1 -from arcaea_offline_ocr.device.v2.definition import DeviceV2 -from arcaea_offline_ocr.phash_db import ImagePHashDatabase -from arcaea_offline_ocr.sift_db import SIFTDatabase +from arcaea_offline_ocr.phash_db import ImagePhashDatabase from PySide6.QtCore import Qt, Slot from PySide6.QtWidgets import QApplication, QFileDialog, QWidget from ui.designer.tabs.tabOcr.tabOcr_Device_ui import Ui_TabOcr_Device from ui.extends.components.ocrQueue import OcrQueueModel from ui.extends.shared.language import LanguageChangeEventFilter -from ui.extends.shared.settings import ( - DEVICES_JSON_FILE, - KNN_MODEL_FILE, - PHASH_DATABASE_FILE, - TESSERACT_FILE, - Settings, -) +from ui.extends.shared.settings import KNN_MODEL_FILE, PHASH_DATABASE_FILE from ui.extends.tabs.tabOcr.tabOcr_Device import ( ScoreConverter, TabDeviceV2AutoRoisOcrRunnable, TabDeviceV2OcrRunnable, ) + logger = logging.getLogger(__name__) @@ -38,17 +28,36 @@ class TabOcr_Device(Ui_TabOcr_Device, QWidget): self.languageChangeEventFilter = LanguageChangeEventFilter(self) self.installEventFilter(self.languageChangeEventFilter) - self.deviceFileSelector.filesSelected.connect(self.deviceFileSelected) - self.knnModelSelector.filesSelected.connect(self.knnModelFileSelected) - self.phashDatabaseSelector.filesSelected.connect(self.phashDatabaseFileSelected) + # connect options checkBoxes & comboBoxes + self.options_roisUseCustomCheckBox.toggled.connect( + lambda useCustom: self.options_roisStackedWidget.setCurrentIndex( + 1 if useCustom else 0 + ) + ) + self.options_maskerUseCustomCheckBox.toggled.connect( + lambda useCustom: self.options_maskerStackedWidget.setCurrentIndex( + 1 if useCustom else 0 + ) + ) + self.options_usePresetCheckBox.toggled.connect(self.options_setUsePreset) + + self.options_presetComboBox.currentIndexChanged.connect( + self.options_presetSelected + ) + # fill option values + self.options_fillComboBoxes() + + self.dependencies_knnModelSelector.filesSelected.connect(self.knnModelSelected) + self.dependencies_phashDatabaseSelector.filesSelected.connect( + self.phashDatabaseSelected + ) logger.info("Applying settings...") - self.deviceFileSelector.connectSettings(DEVICES_JSON_FILE) - self.knnModelSelector.connectSettings(KNN_MODEL_FILE) - self.tesseractFileSelector.connectSettings(TESSERACT_FILE) - self.phashDatabaseSelector.connectSettings(PHASH_DATABASE_FILE) - settings = Settings() - self.deviceComboBox.selectDevice(settings.deviceUuid()) + self.dependencies_knnModelSelector.connectSettings(KNN_MODEL_FILE) + self.dependencies_phashDatabaseSelector.connectSettings(PHASH_DATABASE_FILE) + + self.options_usePresetCheckBox.setChecked(True) + self.options_usePresetCheckBox.setEnabled(False) self.ocrQueueModel = OcrQueueModel(self) self.ocrQueue.setModel(self.ocrQueueModel) @@ -60,43 +69,70 @@ class TabOcr_Device(Ui_TabOcr_Device, QWidget): # wizard.open() pass - @Slot() - def on_deviceUseAutoFactorCheckBox_stateChanged(self): - checkState = self.deviceUseAutoFactorCheckBox.checkState() - if checkState == Qt.CheckState.Checked: - self.deviceDependenciesStackedWidget.setCurrentIndex(1) - self.deviceComboBox.setCurrentIndex(-1) - self.deviceFileSelector.setEnabled(False) - self.deviceComboBox.setEnabled(False) - else: - self.deviceFileSelector.setEnabled(True) - self.deviceComboBox.setEnabled(True) + @Slot(bool) + def options_setUsePreset(self, usePreset: bool): + self.options_roisUseCustomCheckBox.setChecked(not usePreset) + self.options_maskerUseCustomCheckBox.setChecked(not usePreset) + self.options_preciseControlWidget.setEnabled(not usePreset) + if not usePreset: + self.options_presetComboBox.setCurrentIndex(-1) - @Slot() - def on_deviceComboBox_currentIndexChanged(self): - self.changeDeviceDepStackedWidget() + @Slot(int) + def options_presetSelected(self, index: int): + if index < 0: + self.options_roisComboBox.setCurrentIndex(-1) + self.options_maskerComboBox.setCurrentIndex(-1) - def changeDeviceDepStackedWidget(self): - device = self.deviceComboBox.currentData() - if isinstance(device, (DeviceV1, DeviceV2)): - self.deviceDependenciesStackedWidget.setCurrentIndex(device.version - 1) + autoTypeString = self.options_presetComboBox.currentData() + roisAutoTypeIndex = self.options_roisComboBox.findData(autoTypeString) + maskerAutoTypeIndex = self.options_maskerComboBox.findData(autoTypeString) + self.options_roisComboBox.setCurrentIndex(roisAutoTypeIndex) + self.options_maskerComboBox.setCurrentIndex(maskerAutoTypeIndex) - def deviceFileSelected(self): - if selectedFiles := self.deviceFileSelector.selectedFiles(): - file = selectedFiles[0] - self.deviceComboBox.loadDevicesJson(file) + def options_fillComboBoxes(self): + self.options_roisComboBox.addItem("RoisAutoT1", "AutoT1") + self.options_roisComboBox.addItem("RoisAutoT2", "AutoT2") + self.options_roisComboBox.setCurrentIndex(-1) - def knnModelFileSelected(self): - if selectedFiles := self.knnModelSelector.selectedFiles(): - self.knnModel = cv2.ml.KNearest.load(selectedFiles[0]) + self.options_maskerComboBox.addItem("MaskerAutoT1", "AutoT1") + self.options_maskerComboBox.addItem("MaskerAutoT2", "AutoT2") + self.options_maskerComboBox.setCurrentIndex(-1) - def phashDatabaseFileSelected(self): - if selectedFiles := self.phashDatabaseSelector.selectedFiles(): - self.phashDatabase = ImagePHashDatabase(selectedFiles[0]) + self.options_presetComboBox.addItem("AutoT1 (ver <= 4.7.2)", "AutoT1") + self.options_presetComboBox.addItem("AutoT2 (ver >= 5.0.0)", "AutoT2") + self.options_presetComboBox.setCurrentIndex(1) + + def knnModelSelected(self): + try: + knnModelFile = self.dependencies_knnModelSelector.selectedFiles()[0] + self.knnModel = cv2.ml.KNearest.load(knnModelFile) + self.dependencies_knnModelStatusLabel.setText( + f'OK, varCount {self.knnModel.getVarCount()}' + ) + except Exception: + logger.exception("Error loading knn model:") + self.dependencies_knnModelStatusLabel.setText( + 'Error' + ) + + def phashDatabaseSelected(self): + try: + phashDbFile = self.dependencies_phashDatabaseSelector.selectedFiles()[0] + self.phashDatabase = ImagePhashDatabase(phashDbFile) + self.dependencies_phashDatabaseStatusLabel.setText( + f'OK, ' + f"J{len(self.phashDatabase.jacket_hashes)} " + f"PI{len(self.phashDatabase.partner_icon_hashes)}" + ) + except Exception: + logger.exception("Error loading phash database:") + self.dependencies_phashDatabaseStatusLabel.setText( + 'Error' + ) @Slot() def on_ocr_addImageButton_clicked(self): - files, _filter = QFileDialog.getOpenFileNames( + files, _ = QFileDialog.getOpenFileNames( self, None, "", "Image Files (*.png *.jpg *.jpeg *.bmp *.webp);;*" ) filesNum = len(files) diff --git a/ui/resources/lang/en_US.ts b/ui/resources/lang/en_US.ts index 9ba841d..5698f4b 100644 --- a/ui/resources/lang/en_US.ts +++ b/ui/resources/lang/en_US.ts @@ -787,28 +787,44 @@ validation - deviceSelector.title - Select Device + options.title + Options - deviceSelector.useAutoFactor - Auto calculate factor + options.usePreset + Use preset - - knnModelSelector.title - Select KNearest Model + + options.rois + Rois - - tesseractSelector.title - Select tesseract Path + + options.masker + Masker - - phashDatabaseSelector.title - Select Image PHash Database + + + options.useCustom + Use custom options + + + + dependencies.title + OCR Dependencies + + + + dependencies.knnModel + KNearest model + + + + dependencies.phashDatabase + Image pHash database diff --git a/ui/resources/lang/zh_CN.ts b/ui/resources/lang/zh_CN.ts index 1d6e40f..5b62aa3 100644 --- a/ui/resources/lang/zh_CN.ts +++ b/ui/resources/lang/zh_CN.ts @@ -786,28 +786,44 @@ - deviceSelector.title - 选择设备 + options.title + 选项 - deviceSelector.useAutoFactor - 自动计算 factor + options.usePreset + 使用预设 - - knnModelSelector.title - 选择 KNearest 模型 + + options.rois + 定位器 - - tesseractSelector.title - 选择 tesseract 路径 + + options.masker + 遮罩器 - - phashDatabaseSelector.title - 选择图像 PHash 数据库 + + + options.useCustom + 使用自定义设置 + + + + dependencies.title + OCR 依赖 + + + + dependencies.knnModel + KNearest 模型 + + + + dependencies.phashDatabase + 图像 pHash 数据库