mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 04:16:26 +00:00
wip: refactor
This commit is contained in:
@ -1,24 +1,21 @@
|
||||
import pytesseract
|
||||
from arcaea_offline_ocr_device_creation_wizard.implements.wizard import Wizard
|
||||
|
||||
# from arcaea_offline_ocr_device_creation_wizard.implements.wizard import Wizard
|
||||
from PySide6.QtCore import QModelIndex, Qt, Slot
|
||||
from PySide6.QtGui import QColor, QPalette
|
||||
from PySide6.QtWidgets import QFileDialog, QWidget
|
||||
from PySide6.QtGui import QColor
|
||||
from PySide6.QtWidgets import QFileDialog, QHeaderView, QWidget
|
||||
|
||||
from ui.designer.tabs.tabOcr_ui import Ui_TabOcr
|
||||
from ui.extends.components.ocrQueue import OcrQueueModel
|
||||
from ui.extends.settings import Settings
|
||||
from ui.extends.tabs.tabOcr import (
|
||||
ImageDelegate,
|
||||
OcrQueueModel,
|
||||
OcrQueueTableProxyModel,
|
||||
TableChartDelegate,
|
||||
TableScoreDelegate,
|
||||
)
|
||||
from ui.extends.tabs.tabOcr import TabDeviceV2OcrRunnable, ScoreInsertConverter
|
||||
|
||||
|
||||
class TabOcr(Ui_TabOcr, QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.openWizardButton.setEnabled(False)
|
||||
|
||||
self.deviceFileSelector.filesSelected.connect(self.deviceFileSelected)
|
||||
self.tesseractFileSelector.filesSelected.connect(
|
||||
@ -31,36 +28,14 @@ class TabOcr(Ui_TabOcr, QWidget):
|
||||
self.deviceComboBox.selectDevice(settings.deviceUuid())
|
||||
|
||||
self.ocrQueueModel = OcrQueueModel(self)
|
||||
self.ocrQueueModel.dataChanged.connect(self.resizeViewWhenScoreChanged)
|
||||
self.ocrQueueModel.started.connect(self.ocrStarted)
|
||||
self.ocrQueueModel.finished.connect(self.ocrFinished)
|
||||
self.ocrQueueProxyModel = OcrQueueTableProxyModel(self)
|
||||
self.ocrQueueProxyModel.setSourceModel(self.ocrQueueModel)
|
||||
|
||||
self.tableView.setModel(self.ocrQueueProxyModel)
|
||||
self.tableView.setItemDelegateForColumn(1, ImageDelegate(self.tableView))
|
||||
self.tableView.setItemDelegateForColumn(2, TableChartDelegate(self.tableView))
|
||||
self.tableView.setItemDelegateForColumn(3, TableScoreDelegate(self.tableView))
|
||||
|
||||
tableViewPalette = QPalette(self.tableView.palette())
|
||||
highlightColor = QColor(tableViewPalette.color(QPalette.ColorRole.Highlight))
|
||||
highlightColor.setAlpha(25)
|
||||
tableViewPalette.setColor(QPalette.ColorRole.Highlight, highlightColor)
|
||||
self.tableView.setPalette(tableViewPalette)
|
||||
|
||||
@Slot(QModelIndex, QModelIndex, list)
|
||||
def resizeViewWhenScoreChanged(
|
||||
self, topleft: QModelIndex, bottomRight: QModelIndex, roles: list[int]
|
||||
):
|
||||
if OcrQueueModel.ScoreInsertRole in roles:
|
||||
rows = [*range(topleft.row(), bottomRight.row() + 1)]
|
||||
[self.tableView.resizeRowToContents(row) for row in rows]
|
||||
self.tableView.resizeColumnsToContents()
|
||||
self.ocrQueue.setModel(self.ocrQueueModel)
|
||||
self.ocrQueueProxyModel = self.ocrQueue.tableProxyModel()
|
||||
|
||||
@Slot()
|
||||
def on_openWizardButton_clicked(self):
|
||||
wizard = Wizard(self)
|
||||
wizard.open()
|
||||
# wizard = Wizard(self)
|
||||
# wizard.open()
|
||||
pass
|
||||
|
||||
def deviceFileSelected(self):
|
||||
selectedFiles = self.deviceFileSelector.selectedFiles()
|
||||
@ -73,15 +48,6 @@ class TabOcr(Ui_TabOcr, QWidget):
|
||||
if selectedFiles:
|
||||
pytesseract.pytesseract.tesseract_cmd = selectedFiles[0]
|
||||
|
||||
def setOcrButtonsEnabled(self, __bool: bool):
|
||||
self.ocr_addImageButton.setEnabled(__bool)
|
||||
self.ocr_removeSelectedButton.setEnabled(__bool)
|
||||
self.ocr_removeAllButton.setEnabled(__bool)
|
||||
self.ocr_startButton.setEnabled(__bool)
|
||||
self.ocr_acceptSelectedButton.setEnabled(__bool)
|
||||
self.ocr_acceptAllButton.setEnabled(__bool)
|
||||
self.ocr_ignoreValidateCheckBox.setEnabled(__bool)
|
||||
|
||||
@Slot()
|
||||
def on_ocr_addImageButton_clicked(self):
|
||||
files, _filter = QFileDialog.getOpenFileNames(
|
||||
@ -89,45 +55,24 @@ class TabOcr(Ui_TabOcr, QWidget):
|
||||
)
|
||||
for file in files:
|
||||
self.ocrQueueModel.addItem(file)
|
||||
self.tableView.resizeRowsToContents()
|
||||
self.tableView.resizeColumnsToContents()
|
||||
self.ocrQueue.resizeTableView()
|
||||
|
||||
@Slot()
|
||||
def on_ocr_startButton_clicked(self):
|
||||
self.ocrQueueModel.startQueue(self.deviceComboBox.currentData())
|
||||
|
||||
def ocrStarted(self):
|
||||
self.setOcrButtonsEnabled(False)
|
||||
|
||||
def ocrFinished(self):
|
||||
self.setOcrButtonsEnabled(True)
|
||||
|
||||
@Slot()
|
||||
def on_ocr_removeSelectedButton_clicked(self):
|
||||
rows = [
|
||||
modelIndex.row()
|
||||
for modelIndex in self.tableView.selectionModel().selectedRows(0)
|
||||
]
|
||||
self.ocrQueueModel.removeItems(rows)
|
||||
for row in range(self.ocrQueueModel.rowCount()):
|
||||
index = self.ocrQueueModel.index(row, 0)
|
||||
imagePath = index.data(OcrQueueModel.ImagePathRole)
|
||||
runnable = TabDeviceV2OcrRunnable(
|
||||
imagePath, self.deviceComboBox.currentData(), self.knn, self.siftDb
|
||||
)
|
||||
self.ocrQueueModel.setData(index, runnable, OcrQueueModel.OcrRunnableRole)
|
||||
self.ocrQueueModel.setData(
|
||||
index,
|
||||
ScoreInsertConverter.deviceV2,
|
||||
OcrQueueModel.ProcessOcrResultFuncRole,
|
||||
)
|
||||
self.ocrQueueModel.startQueue()
|
||||
|
||||
@Slot()
|
||||
def on_ocr_removeAllButton_clicked(self):
|
||||
self.ocrQueueModel.clear()
|
||||
|
||||
@Slot()
|
||||
def on_ocr_acceptSelectedButton_clicked(self):
|
||||
ignoreValidate = (
|
||||
self.ocr_ignoreValidateCheckBox.checkState() == Qt.CheckState.Checked
|
||||
)
|
||||
rows = [
|
||||
modelIndex.row()
|
||||
for modelIndex in self.tableView.selectionModel().selectedRows(0)
|
||||
]
|
||||
self.ocrQueueModel.acceptItems(rows, ignoreValidate)
|
||||
|
||||
@Slot()
|
||||
def on_ocr_acceptAllButton_clicked(self):
|
||||
ignoreValidate = (
|
||||
self.ocr_ignoreValidateCheckBox.checkState() == Qt.CheckState.Checked
|
||||
)
|
||||
self.ocrQueueModel.acceptAllItems(ignoreValidate)
|
||||
|
Reference in New Issue
Block a user