mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
wip: arcaea-offline-ocr==0.1.0
settings
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user