mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-16 07:40:18 +00:00
wip: arcaea-offline-ocr==0.1.0
settings
This commit is contained in:
parent
5c5c1a227d
commit
ad5e5ec694
@ -5,12 +5,11 @@ from PySide6.QtCore import QFileInfo, QSettings, Signal
|
||||
from .singleton import QObjectSingleton
|
||||
|
||||
__all__ = [
|
||||
"LANGUAGE",
|
||||
"DATABASE_URL",
|
||||
"DEVICES_JSON_FILE",
|
||||
"DEVICE_UUID",
|
||||
"TESSERACT_FILE",
|
||||
"KNN_MODEL_FILE",
|
||||
"SIFT_DATABASE_FILE",
|
||||
"B30_KNN_MODEL_FILE",
|
||||
"PHASH_DATABASE_FILE",
|
||||
"ANDREAL_FOLDER",
|
||||
"ANDREAL_EXECUTABLE",
|
||||
"Settings",
|
||||
@ -21,12 +20,8 @@ __all__ = [
|
||||
LANGUAGE = "Language"
|
||||
DATABASE_URL = "DatabaseUrl"
|
||||
|
||||
DEVICES_JSON_FILE = "Ocr/DevicesJsonFile"
|
||||
DEVICE_UUID = "Ocr/DeviceUuid"
|
||||
TESSERACT_FILE = "Ocr/TesseractFile"
|
||||
KNN_MODEL_FILE = "Ocr/KnnModelFile"
|
||||
B30_KNN_MODEL_FILE = "Ocr/B30KnnModelFile"
|
||||
SIFT_DATABASE_FILE = "Ocr/SiftDatabaseFile"
|
||||
PHASH_DATABASE_FILE = "Ocr/PHashDatabaseFile"
|
||||
|
||||
ANDREAL_FOLDER = "Andreal/AndrealFolder"
|
||||
@ -70,33 +65,6 @@ class Settings(QSettings, metaclass=QObjectSingleton):
|
||||
def setDatabaseUrl(self, value: str):
|
||||
self._setStrItem(DATABASE_URL, value)
|
||||
|
||||
def devicesJsonFile(self):
|
||||
return self._strItem(DEVICES_JSON_FILE)
|
||||
|
||||
def setDevicesJsonFile(self, value: str):
|
||||
self._setStrItem(DEVICES_JSON_FILE, value)
|
||||
|
||||
def resetDevicesJsonFile(self):
|
||||
self._resetStrItem(DEVICES_JSON_FILE)
|
||||
|
||||
def deviceUuid(self):
|
||||
return self._strItem(DEVICE_UUID)
|
||||
|
||||
def setDeviceUuid(self, value: str):
|
||||
self._setStrItem(DEVICE_UUID, value)
|
||||
|
||||
def resetDeviceUuid(self):
|
||||
self._resetStrItem(DEVICE_UUID)
|
||||
|
||||
def tesseractPath(self):
|
||||
return self._strItem(TESSERACT_FILE)
|
||||
|
||||
def setTesseractPath(self, value: str):
|
||||
self._setStrItem(TESSERACT_FILE, value)
|
||||
|
||||
def resetTesseractPath(self):
|
||||
self._resetStrItem(TESSERACT_FILE)
|
||||
|
||||
def knnModelFile(self):
|
||||
return self._strItem(KNN_MODEL_FILE)
|
||||
|
||||
@ -115,15 +83,6 @@ class Settings(QSettings, metaclass=QObjectSingleton):
|
||||
def resetB30KnnModelFile(self):
|
||||
self._resetStrItem(B30_KNN_MODEL_FILE)
|
||||
|
||||
def siftDatabaseFile(self):
|
||||
return self._strItem(SIFT_DATABASE_FILE)
|
||||
|
||||
def setSiftDatabaseFile(self, value: str):
|
||||
self._setStrItem(SIFT_DATABASE_FILE, value)
|
||||
|
||||
def resetSiftDatabaseFile(self):
|
||||
self._resetStrItem(SIFT_DATABASE_FILE)
|
||||
|
||||
def phashDatabaseFile(self):
|
||||
return self._strItem(PHASH_DATABASE_FILE)
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
from arcaea_offline_ocr.device.v1.definition import DeviceV1
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QComboBox
|
||||
|
||||
from ui.extends.ocr import load_devices_json
|
||||
from ui.extends.shared.delegates.descriptionDelegate import DescriptionDelegate
|
||||
|
||||
|
||||
class DevicesComboBox(QComboBox):
|
||||
DeviceUuidRole = Qt.ItemDataRole.UserRole + 10
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setItemDelegate(DescriptionDelegate(self))
|
||||
|
||||
def setDevices(self, devices: list[DeviceV1]):
|
||||
self.clear()
|
||||
for device in devices:
|
||||
self.addItem(f"{device.name} ({device.uuid})", device)
|
||||
row = self.count() - 1
|
||||
self.setItemData(row, device.uuid, self.DeviceUuidRole)
|
||||
self.setItemData(row, device.name, DescriptionDelegate.MainTextRole)
|
||||
self.setItemData(row, device.uuid, DescriptionDelegate.DescriptionTextRole)
|
||||
self.setCurrentIndex(-1)
|
||||
|
||||
def loadDevicesJson(self, path: str):
|
||||
devices = load_devices_json(path)
|
||||
self.setDevices(devices)
|
||||
|
||||
def selectDevice(self, deviceUuid: str):
|
||||
index = self.findData(deviceUuid, self.DeviceUuidRole)
|
||||
self.setCurrentIndex(index)
|
@ -1,7 +1,6 @@
|
||||
from PySide6.QtCore import QCoreApplication
|
||||
from PySide6.QtWidgets import QLabel, QPushButton
|
||||
|
||||
from ui.implements.components.devicesComboBox import DevicesComboBox
|
||||
from ui.implements.components.fileSelector import FileSelector
|
||||
from ui.implements.settings.settingsBaseWidget import SettingsBaseWidget
|
||||
|
||||
@ -12,28 +11,6 @@ class SettingsOcr(SettingsBaseWidget):
|
||||
|
||||
self.setupUi(self)
|
||||
|
||||
if self.settings.devicesJsonFile():
|
||||
self.devicesJsonValueWidget.selectFile(self.settings.devicesJsonFile())
|
||||
self.devicesJsonValueWidget.filesSelected.connect(self.setDevicesJson)
|
||||
self.devicesJsonResetButton.clicked.connect(self.resetDevicesJson)
|
||||
self.insertItem(
|
||||
"devicesJson",
|
||||
self.devicesJsonLabel,
|
||||
self.devicesJsonValueWidget,
|
||||
self.devicesJsonResetButton,
|
||||
)
|
||||
|
||||
if self.settings.deviceUuid():
|
||||
self.deviceUuidValueWidget.selectDevice(self.settings.deviceUuid())
|
||||
self.deviceUuidValueWidget.activated.connect(self.setDeviceUuid)
|
||||
self.deviceUuidResetButton.clicked.connect(self.resetDeviceUuid)
|
||||
self.insertItem(
|
||||
"deviceUuid",
|
||||
self.deviceUuidLabel,
|
||||
self.deviceUuidValueWidget,
|
||||
self.deviceUuidResetButton,
|
||||
)
|
||||
|
||||
if self.settings.knnModelFile():
|
||||
self.knnModelFileValueWidget.selectFile(self.settings.knnModelFile())
|
||||
self.knnModelFileValueWidget.filesSelected.connect(self.setKnnModelFile)
|
||||
@ -56,19 +33,6 @@ class SettingsOcr(SettingsBaseWidget):
|
||||
self.b30KnnModelFileResetButton,
|
||||
)
|
||||
|
||||
if self.settings.siftDatabaseFile():
|
||||
self.siftDatabaseFileValueWidget.selectFile(
|
||||
self.settings.siftDatabaseFile()
|
||||
)
|
||||
self.siftDatabaseFileValueWidget.filesSelected.connect(self.setSiftDatabaseFile)
|
||||
self.siftDatabaseFileResetButton.clicked.connect(self.resetSiftDatabaseFile)
|
||||
self.insertItem(
|
||||
"siftDatabaseFile",
|
||||
self.siftDatabaseFileLabel,
|
||||
self.siftDatabaseFileValueWidget,
|
||||
self.siftDatabaseFileResetButton,
|
||||
)
|
||||
|
||||
if self.settings.phashDatabaseFile():
|
||||
self.phashDatabaseFileValueWidget.selectFile(
|
||||
self.settings.phashDatabaseFile()
|
||||
@ -84,34 +48,6 @@ class SettingsOcr(SettingsBaseWidget):
|
||||
self.phashDatabaseFileResetButton,
|
||||
)
|
||||
|
||||
def setDevicesJson(self):
|
||||
selectedFile = self.devicesJsonValueWidget.selectedFiles()
|
||||
if selectedFile and selectedFile[0]:
|
||||
file = selectedFile[0]
|
||||
self.settings.setDevicesJsonFile(file)
|
||||
self.fillDeviceUuidComboBox()
|
||||
|
||||
def fillDeviceUuidComboBox(self):
|
||||
devicesJsonPath = self.devicesJsonValueWidget.selectedFiles()[0]
|
||||
self.deviceUuidValueWidget.loadDevicesJson(devicesJsonPath)
|
||||
|
||||
storedDeviceUuid = self.settings.deviceUuid()
|
||||
self.deviceUuidValueWidget.selectDevice(storedDeviceUuid)
|
||||
|
||||
def resetDevicesJson(self):
|
||||
self.deviceUuidValueWidget.clear()
|
||||
self.devicesJsonValueWidget.reset()
|
||||
self.settings.resetDeviceUuid()
|
||||
self.settings.resetDevicesJsonFile()
|
||||
|
||||
def setDeviceUuid(self):
|
||||
if device := self.deviceUuidValueWidget.currentData():
|
||||
self.settings.setDeviceUuid(device.uuid)
|
||||
|
||||
def resetDeviceUuid(self):
|
||||
self.deviceUuidValueWidget.setCurrentIndex(-1)
|
||||
self.settings.resetDeviceUuid()
|
||||
|
||||
def setKnnModelFile(self):
|
||||
selectedFile = self.knnModelFileValueWidget.selectedFiles()
|
||||
if selectedFile and selectedFile[0]:
|
||||
@ -132,16 +68,6 @@ class SettingsOcr(SettingsBaseWidget):
|
||||
self.b30KnnModelFileValueWidget.reset()
|
||||
self.settings.resetB30KnnModelFile()
|
||||
|
||||
def setSiftDatabaseFile(self):
|
||||
selectedFile = self.siftDatabaseFileValueWidget.selectedFiles()
|
||||
if selectedFile and selectedFile[0]:
|
||||
file = selectedFile[0]
|
||||
self.settings.setSiftDatabaseFile(file)
|
||||
|
||||
def resetSiftDatabaseFile(self):
|
||||
self.siftDatabaseFileValueWidget.reset()
|
||||
self.settings.resetSiftDatabaseFile()
|
||||
|
||||
def setPHashDatabaseFile(self):
|
||||
selectedFile = self.phashDatabaseFileValueWidget.selectedFiles()
|
||||
if selectedFile and selectedFile[0]:
|
||||
@ -153,14 +79,6 @@ class SettingsOcr(SettingsBaseWidget):
|
||||
self.settings.resetPHashDatabaseFile()
|
||||
|
||||
def setupUi(self, *args):
|
||||
self.devicesJsonLabel = QLabel(self)
|
||||
self.devicesJsonValueWidget = FileSelector(self)
|
||||
self.devicesJsonResetButton = QPushButton(self)
|
||||
|
||||
self.deviceUuidLabel = QLabel(self)
|
||||
self.deviceUuidValueWidget = DevicesComboBox(self)
|
||||
self.deviceUuidResetButton = QPushButton(self)
|
||||
|
||||
self.knnModelFileLabel = QLabel(self)
|
||||
self.knnModelFileValueWidget = FileSelector(self)
|
||||
self.knnModelFileResetButton = QPushButton(self)
|
||||
@ -169,10 +87,6 @@ class SettingsOcr(SettingsBaseWidget):
|
||||
self.b30KnnModelFileValueWidget = FileSelector(self)
|
||||
self.b30KnnModelFileResetButton = QPushButton(self)
|
||||
|
||||
self.siftDatabaseFileLabel = QLabel(self)
|
||||
self.siftDatabaseFileValueWidget = FileSelector(self)
|
||||
self.siftDatabaseFileResetButton = QPushButton(self)
|
||||
|
||||
self.phashDatabaseFileLabel = QLabel(self)
|
||||
self.phashDatabaseFileValueWidget = FileSelector(self)
|
||||
self.phashDatabaseFileResetButton = QPushButton(self)
|
||||
@ -186,21 +100,12 @@ class SettingsOcr(SettingsBaseWidget):
|
||||
# fmt: off
|
||||
self.setTitle(QCoreApplication.translate("Settings", "ocr.title"))
|
||||
|
||||
self.devicesJsonLabel.setText(QCoreApplication.translate("Settings", "ocr.devicesJson.label"))
|
||||
self.devicesJsonResetButton.setText(QCoreApplication.translate("Settings", "resetButton"))
|
||||
|
||||
self.deviceUuidLabel.setText(QCoreApplication.translate("Settings", "ocr.deviceUuid.label"))
|
||||
self.deviceUuidResetButton.setText(QCoreApplication.translate("Settings", "resetButton"))
|
||||
|
||||
self.knnModelFileLabel.setText(QCoreApplication.translate("Settings", "ocr.knnModelFile.label"))
|
||||
self.knnModelFileResetButton.setText(QCoreApplication.translate("Settings", "resetButton"))
|
||||
|
||||
self.b30KnnModelFileLabel.setText(QCoreApplication.translate("Settings", "ocr.b30KnnModelFile.label"))
|
||||
self.b30KnnModelFileResetButton.setText(QCoreApplication.translate("Settings", "resetButton"))
|
||||
|
||||
self.siftDatabaseFileLabel.setText(QCoreApplication.translate("Settings", "ocr.siftDatabaseFile.label"))
|
||||
self.siftDatabaseFileResetButton.setText(QCoreApplication.translate("Settings", "resetButton"))
|
||||
|
||||
self.phashDatabaseFileLabel.setText(QCoreApplication.translate("Settings", "ocr.phashDatabaseFile.label"))
|
||||
self.phashDatabaseFileResetButton.setText(QCoreApplication.translate("Settings", "resetButton"))
|
||||
# fmt: on
|
||||
|
Loading…
x
Reference in New Issue
Block a user