This commit is contained in:
2023-07-07 01:41:19 +08:00
commit 95da43261e
83 changed files with 7529 additions and 0 deletions

View File

@ -0,0 +1,6 @@
from .chartSelector import ChartSelector
from .devicesComboBox import DevicesComboBox
from .elidedLabel import ElidedLabel
from .fileSelector import FileSelector
from .ratingClassRadioButton import RatingClassRadioButton
from .scoreEditor import ScoreEditor

View File

@ -0,0 +1,254 @@
from typing import Literal
from arcaea_offline.database import Database
from arcaea_offline.models import Chart, Package
from arcaea_offline.utils import rating_class_to_text
from PySide6.QtCore import QModelIndex, Qt, Signal, Slot
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QCompleter, QWidget
from ui.designer.components.chartSelector_ui import Ui_ChartSelector
from ui.extends.components.chartSelector import FuzzySearchCompleterModel
from ui.extends.shared.delegates.descriptionDelegate import DescriptionDelegate
from ui.implements.components.ratingClassRadioButton import RatingClassRadioButton
class ChartSelector(Ui_ChartSelector, QWidget):
valueChanged = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self.db = Database()
self.db.register_update_hook(self.fillPackageComboBox)
self.setupUi(self)
self.pstButton.setColors(QColor("#399bb2"), QColor("#f0f8fa"))
self.prsButton.setColors(QColor("#809955"), QColor("#f7f9f4"))
self.ftrButton.setColors(QColor("#702d60"), QColor("#f7ebf4"))
self.bydButton.setColors(QColor("#710f25"), QColor("#f9ced8"))
self.__RATING_CLASS_BUTTONS = [
self.pstButton,
self.prsButton,
self.ftrButton,
self.bydButton,
]
self.pstButton.clicked.connect(self.selectRatingClass)
self.prsButton.clicked.connect(self.selectRatingClass)
self.ftrButton.clicked.connect(self.selectRatingClass)
self.bydButton.clicked.connect(self.selectRatingClass)
self.deselectAllRatingClassButtons()
self.updateRatingClassButtonsEnabled([])
self.previousPackageButton.clicked.connect(
lambda: self.quickSwitchSelection("previous", "package")
)
self.previousSongIdButton.clicked.connect(
lambda: self.quickSwitchSelection("previous", "songId")
)
self.nextSongIdButton.clicked.connect(
lambda: self.quickSwitchSelection("next", "songId")
)
self.nextPackageButton.clicked.connect(
lambda: self.quickSwitchSelection("next", "package")
)
self.valueChanged.connect(self.updateResultLabel)
self.fillPackageComboBox()
self.packageComboBox.setCurrentIndex(-1)
self.songIdComboBox.setCurrentIndex(-1)
self.fuzzySearchCompleterModel = FuzzySearchCompleterModel()
self.fuzzySearchCompleter = QCompleter(self.fuzzySearchCompleterModel)
self.fuzzySearchCompleter.popup().setItemDelegate(
DescriptionDelegate(self.fuzzySearchCompleter.popup())
)
self.fuzzySearchCompleter.activated[QModelIndex].connect(
self.fuzzySearchCompleterSetSelection
)
self.fuzzySearchLineEdit.setCompleter(self.fuzzySearchCompleter)
self.packageComboBox.setItemDelegate(DescriptionDelegate(self.packageComboBox))
self.songIdComboBox.setItemDelegate(DescriptionDelegate(self.songIdComboBox))
self.pstButton.toggled.connect(self.valueChanged)
self.prsButton.toggled.connect(self.valueChanged)
self.ftrButton.toggled.connect(self.valueChanged)
self.bydButton.toggled.connect(self.valueChanged)
self.packageComboBox.currentIndexChanged.connect(self.valueChanged)
self.songIdComboBox.currentIndexChanged.connect(self.valueChanged)
def quickSwitchSelection(
self,
direction: Literal["previous", "next"],
model: Literal["package", "songId"],
):
minIndex = 0
if model == "package":
maxIndex = self.packageComboBox.count() - 1
currentIndex = self.packageComboBox.currentIndex() + (
1 if direction == "next" else -1
)
currentIndex = max(min(maxIndex, currentIndex), minIndex)
self.packageComboBox.setCurrentIndex(currentIndex)
elif model == "songId":
maxIndex = self.songIdComboBox.count() - 1
currentIndex = self.songIdComboBox.currentIndex() + (
1 if direction == "next" else -1
)
currentIndex = max(min(maxIndex, currentIndex), minIndex)
self.songIdComboBox.setCurrentIndex(currentIndex)
else:
return
def value(self):
packageId = self.packageComboBox.currentData()
songId = self.songIdComboBox.currentData()
ratingClass = self.selectedRatingClass()
if packageId and songId and isinstance(ratingClass, int):
return Chart.from_db_row(self.db.get_chart(songId, ratingClass))
return None
@Slot()
def updateResultLabel(self):
chart = self.value()
if isinstance(chart, Chart):
package = Package.from_db_row(
self.db.get_package_by_package_id(chart.package_id)
)
texts = [
[package.name, chart.name_en, rating_class_to_text(chart.rating_class)],
[package.id, chart.song_id, str(chart.rating_class)],
]
texts = [" | ".join(t) for t in texts]
text = f'{texts[0]}<br><font color="gray">{texts[1]}</font>'
self.resultLabel.setText(text)
else:
self.resultLabel.setText("...")
def fillPackageComboBox(self):
self.packageComboBox.clear()
packages = [Package.from_db_row(dbRow) for dbRow in self.db.get_packages()]
for package in packages:
self.packageComboBox.addItem(f"{package.name} ({package.id})", package.id)
row = self.packageComboBox.count() - 1
self.packageComboBox.setItemData(
row, package.name, DescriptionDelegate.MainTextRole
)
self.packageComboBox.setItemData(
row, package.id, DescriptionDelegate.DescriptionTextRole
)
self.packageComboBox.setCurrentIndex(-1)
def fillSongIdComboBox(self):
self.songIdComboBox.clear()
packageId = self.packageComboBox.currentData()
if packageId:
charts = [
Chart.from_db_row(dbRow)
for dbRow in self.db.get_charts_by_package_id(packageId)
]
inserted_song_ids = []
for chart in charts:
if chart.song_id not in inserted_song_ids:
self.songIdComboBox.addItem(
f"{chart.name_en} ({chart.song_id})", chart.song_id
)
inserted_song_ids.append(chart.song_id)
row = self.songIdComboBox.count() - 1
self.songIdComboBox.setItemData(
row, chart.name_en, DescriptionDelegate.MainTextRole
)
self.songIdComboBox.setItemData(
row, chart.song_id, DescriptionDelegate.DescriptionTextRole
)
self.songIdComboBox.setCurrentIndex(-1)
@Slot()
def on_packageComboBox_activated(self):
self.fillSongIdComboBox()
@Slot(int)
def on_songIdComboBox_currentIndexChanged(self, index: int):
rating_classes = []
if index > -1:
charts = [
Chart.from_db_row(dbRow)
for dbRow in self.db.get_charts_by_song_id(
self.songIdComboBox.currentData()
)
]
rating_classes = [chart.rating_class for chart in charts]
self.updateRatingClassButtonsEnabled(rating_classes)
@Slot()
def on_resetButton_clicked(self):
self.packageComboBox.setCurrentIndex(-1)
self.songIdComboBox.setCurrentIndex(-1)
@Slot(str)
def on_fuzzySearchLineEdit_textChanged(self, text: str):
if text:
self.fuzzySearchCompleterModel.fillDbFuzzySearchResults(self.db, text)
else:
self.fuzzySearchCompleterModel.clear()
def selectChart(self, chart: Chart):
packageIdIndex = self.packageComboBox.findData(chart.package_id)
if packageIdIndex > -1:
self.packageComboBox.setCurrentIndex(packageIdIndex)
else:
# QMessageBox
return
self.fillSongIdComboBox()
songIdIndex = self.songIdComboBox.findData(chart.song_id)
if songIdIndex > -1:
self.songIdComboBox.setCurrentIndex(songIdIndex)
else:
# QMessageBox
return
self.selectRatingClass(chart.rating_class)
@Slot(QModelIndex)
def fuzzySearchCompleterSetSelection(self, index: QModelIndex):
chart = index.data(Qt.ItemDataRole.UserRole + 10) # type: Chart
self.selectChart(chart)
self.fuzzySearchLineEdit.clear()
self.fuzzySearchLineEdit.clearFocus()
def ratingClassButtons(self):
return self.__RATING_CLASS_BUTTONS
def selectedRatingClass(self):
for i, button in enumerate(self.__RATING_CLASS_BUTTONS):
if button.isChecked():
return i
def updateRatingClassButtonsEnabled(self, rating_classes: list[int]):
for i, button in enumerate(self.__RATING_CLASS_BUTTONS):
if i in rating_classes:
button.setEnabled(True)
else:
button.setChecked(False)
button.setEnabled(False)
def deselectAllRatingClassButtons(self):
[button.setChecked(False) for button in self.__RATING_CLASS_BUTTONS]
@Slot()
def selectRatingClass(self, rating_class: int | None = None):
if type(rating_class) == int and rating_class in range(4):
self.deselectAllRatingClassButtons()
button = self.__RATING_CLASS_BUTTONS[rating_class]
if button.isEnabled():
button.setChecked(True)
else:
button = self.sender()
if isinstance(button, RatingClassRadioButton) and button.isEnabled():
self.deselectAllRatingClassButtons()
button.setChecked(True)

View File

@ -0,0 +1,9 @@
from PySide6.QtWidgets import QWidget
from ui.designer.components.dbTableViewer_ui import Ui_DbTableViewer
class DbTableViewer(Ui_DbTableViewer, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)

View File

@ -0,0 +1,32 @@
from arcaea_offline_ocr.device import Device
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[Device]):
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)

View File

@ -0,0 +1,50 @@
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QLabel
class ElidedLabel(QLabel):
"""
Adapted from https://wiki.qt.io/Elided_Label
"""
def __init__(self, parent=None):
super().__init__(parent)
self.__elideMode: Qt.TextElideMode = Qt.TextElideMode.ElideNone
self.__cachedElidedText = ""
self.__cachedText = ""
def elideMode(self):
return self.__elideMode
def setElideMode(self, mode):
self.__elideMode = mode
self.__cachedText = ""
self.update()
def resizeEvent(self, event):
super().resizeEvent(event)
self.__cachedText = ""
def paintEvent(self, event) -> None:
if self.__elideMode == Qt.TextElideMode.ElideNone:
return super().paintEvent(event)
self.updateCachedTexts()
super().setText(self.__cachedElidedText)
super().paintEvent(event)
super().setText(self.__cachedText)
def updateCachedTexts(self):
text = self.text()
if self.__cachedText == text:
return
self.__cachedText = text
fontMetrics = self.fontMetrics()
self.__cachedElidedText = fontMetrics.elidedText(
self.text(), self.__elideMode, self.width(), Qt.TextFlag.TextShowMnemonic
)
# make sure to show at least the first character
if self.__cachedText:
firstChar = f"{self.__cachedText[0]}..."
self.setMinimumWidth(fontMetrics.horizontalAdvance(firstChar) + 1)

View File

@ -0,0 +1,91 @@
from PySide6.QtCore import QDir, QFileInfo, QMetaObject, Qt, Signal, Slot
from PySide6.QtWidgets import QFileDialog, QWidget
from ui.designer.components.fileSelector_ui import Ui_FileSelector
class FileSelector(Ui_FileSelector, QWidget):
accepted = Signal()
filesSelected = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.reset()
self.elidedLabel.setElideMode(Qt.TextElideMode.ElideMiddle)
self.accepted.connect(self.filesSelected)
self.accepted.connect(self.updateLabel)
self.filesSelected.connect(self.updateLabel)
self.__mode = self.getOpenFileNames
def getOpenFileNames(self):
selectedFiles, filter = QFileDialog.getOpenFileNames(
self,
self.__caption,
self.__startDirectory,
self.__filter,
"",
options=self.__options,
)
if selectedFiles:
self.__selectedFiles = selectedFiles
self.accepted.emit()
def getExistingDirectory(self):
selectedDir = QFileDialog.getExistingDirectory(
self,
self.__caption,
self.__startDirectory,
QFileDialog.Option.ShowDirsOnly | self.__options,
)
if selectedDir:
self.__selectedFiles = [selectedDir]
self.accepted.emit()
def selectFile(self, filename: str):
fileInfo = QFileInfo(filename)
if not fileInfo.exists():
return
self.__selectedFiles = [fileInfo.absoluteFilePath()]
self.__startDirectory = fileInfo.dir().absolutePath()
self.filesSelected.emit()
def selectedFiles(self):
return self.__selectedFiles
def setNameFilters(self, filters: list[str]):
self.__filter = ";;".join(filters) if filters else ""
def setOptions(self, options: QFileDialog.Option):
self.__options = options
def setMode(self, mode):
if mode in [self.getOpenFileNames, self.getExistingDirectory]:
self.__mode = mode
else:
raise ValueError("Invalid mode")
def reset(self):
self.__selectedFiles = []
self.__caption = None
self.__startDirectory = QDir.currentPath()
self.__filter = ""
self.__options = QFileDialog.Option(0)
self.updateLabel()
def updateLabel(self):
selectedFiles = self.selectedFiles()
if not selectedFiles:
self.elidedLabel.setText("...")
else:
self.elidedLabel.setText("<br>".join(selectedFiles))
@Slot()
def on_selectButton_clicked(self):
self.__mode()

View File

@ -0,0 +1,15 @@
from PySide6.QtWidgets import QLineEdit
class FocusSelectAllLineEdit(QLineEdit):
def mousePressEvent(self, event):
super().mousePressEvent(event)
self.selectAll()
def focusInEvent(self, event):
super().focusInEvent(event)
self.selectAll()
def focusOutEvent(self, event):
super().focusOutEvent(event)
self.deselect()

View File

@ -0,0 +1,100 @@
from PySide6.QtCore import Slot
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QGraphicsColorizeEffect, QRadioButton
from ui.extends.color import mix_color
STYLESHEET = """
QRadioButton {{
padding: 10px;
background-color: qlineargradient(spread:pad, x1:0.7, y1:0.5, x2:1, y2:0.525, stop:0 {dark_color}, stop:1 {mid_color});
color: {text_color};
}}
QRadioButton::indicator {{
border: 2px solid palette(Window);
width: 7px;
height: 7px;
border-radius: 0px;
}}
QRadioButton::indicator:unchecked {{
background-color: palette(Window);
}}
QPushButton::indicator:checked {{
background-color: {mid_color};
}}
"""
class RatingClassRadioButton(QRadioButton):
def __init__(self, parent):
super().__init__(parent)
self.toggled.connect(self.updateCheckedEffect)
self.grayscaleEffect = QGraphicsColorizeEffect(self)
self.grayscaleEffect.setColor("#000000")
def setColors(self, dark_color: QColor, text_color: QColor):
self._dark_color = dark_color
self._text_color = text_color
self._mid_color = mix_color(dark_color, text_color, 0.616)
self.updateEffects()
def isColorsSet(self) -> bool:
return (
hasattr(self, "_dark_color")
and hasattr(self, "_text_color")
and hasattr(self, "_mid_color")
and isinstance(self._dark_color, QColor)
and isinstance(self._text_color, QColor)
and isinstance(self._mid_color, QColor)
)
def setNormalStyleSheet(self):
self.setStyleSheet(
STYLESHEET.format(
dark_color=self._dark_color.name(QColor.NameFormat.HexArgb),
mid_color=self._mid_color.name(QColor.NameFormat.HexArgb),
text_color=self._text_color.name(QColor.NameFormat.HexArgb),
)
)
def setDisabledStyleSheet(self):
self.setStyleSheet(
STYLESHEET.format(
dark_color="#282828",
mid_color="#282828",
text_color="#9e9e9e",
).replace("palette(Window)", "#333333")
)
@Slot()
def updateEnabledEffect(self):
if self.isColorsSet():
if self.isEnabled():
self.setNormalStyleSheet()
else:
self.setDisabledStyleSheet()
@Slot()
def updateCheckedEffect(self):
if self.isColorsSet():
if self.isEnabled():
self.grayscaleEffect.setStrength(0.0 if self.isChecked() else 1.0)
self.setGraphicsEffect(self.grayscaleEffect)
@Slot()
def updateEffects(self):
self.updateCheckedEffect()
self.updateEnabledEffect()
def setChecked(self, arg__1: bool):
super().setChecked(arg__1)
self.updateEffects()
def setEnabled(self, arg__1: bool):
super().setEnabled(arg__1)
self.updateEffects()

View File

@ -0,0 +1,197 @@
from enum import IntEnum
from typing import Optional
from arcaea_offline.calculate import calculate_score_range
from arcaea_offline.models import Chart, Score, ScoreInsert
from PySide6.QtCore import QCoreApplication, QDateTime, Signal, Slot
from PySide6.QtWidgets import QMessageBox, QWidget
from ui.designer.components.scoreEditor_ui import Ui_ScoreEditor
class ScoreValidateResult(IntEnum):
Ok = 0
ScoreMismatch = 1
ScoreEmpty = 2
ChartInvalid = 50
class ScoreEditor(Ui_ScoreEditor, QWidget):
valueChanged = Signal()
accepted = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.__validateBeforeAccept = True
self.__chart = None
self.scoreLineEdit.textChanged.connect(self.valueChanged)
self.pureSpinBox.valueChanged.connect(self.valueChanged)
self.farSpinBox.valueChanged.connect(self.valueChanged)
self.lostSpinBox.valueChanged.connect(self.valueChanged)
self.dateTimeEdit.dateTimeChanged.connect(self.valueChanged)
self.maxRecallSpinBox.valueChanged.connect(self.valueChanged)
self.clearTypeComboBox.currentIndexChanged.connect(self.valueChanged)
self.valueChanged.connect(self.validateScore)
self.valueChanged.connect(self.updateValidateLabel)
self.clearTypeComboBox.addItem("HARD LOST", -1)
self.clearTypeComboBox.addItem("TRACK LOST", 0)
self.clearTypeComboBox.addItem("TRACK COMPLETE", 1)
self.clearTypeComboBox.setCurrentIndex(-1)
def setValidateBeforeAccept(self, __bool: bool):
self.__validateBeforeAccept = __bool
def triggerValidateMessageBox(self):
validate = self.validateScore()
if validate == ScoreValidateResult.Ok:
return True
if validate == ScoreValidateResult.ChartInvalid:
QMessageBox.critical(
self,
# fmt: off
QCoreApplication.translate("ScoreEditor", "chartInvalidDialog.title"),
QCoreApplication.translate("ScoreEditor", "chartInvalidDialog.title"),
# fmt: on
)
return False
if validate == ScoreValidateResult.ScoreMismatch:
result = QMessageBox.warning(
self,
# fmt: off
QCoreApplication.translate("ScoreEditor", "scoreMismatchDialog.title"),
QCoreApplication.translate("ScoreEditor", "scoreMismatchDialog.content"),
# fmt: on
QMessageBox.StandardButton.Yes,
QMessageBox.StandardButton.No,
)
return result == QMessageBox.StandardButton.Yes
elif validate == ScoreValidateResult.ScoreEmpty:
result = QMessageBox.warning(
self,
# fmt: off
QCoreApplication.translate("ScoreEditor", "emptyScoreDialog.title"),
QCoreApplication.translate("ScoreEditor", "emptyScoreDialog.content"),
# fmt: on
QMessageBox.StandardButton.Yes,
QMessageBox.StandardButton.No,
)
return result == QMessageBox.StandardButton.Yes
else:
return False
@Slot()
def on_commitButton_clicked(self):
userAccept = (
self.triggerValidateMessageBox() if self.__validateBeforeAccept else True
)
if userAccept:
self.accepted.emit()
def score(self):
score_text = self.scoreLineEdit.text().replace("'", "")
return int(score_text) if score_text else 0
def setMinimums(self):
self.pureSpinBox.setMinimum(0)
self.farSpinBox.setMinimum(0)
self.lostSpinBox.setMinimum(0)
self.maxRecallSpinBox.setMinimum(-1)
def setLimits(self, chart: Chart):
self.setMinimums()
self.pureSpinBox.setMaximum(chart.note)
self.farSpinBox.setMaximum(chart.note)
self.lostSpinBox.setMaximum(chart.note)
self.maxRecallSpinBox.setMaximum(chart.note)
def resetLimits(self):
self.setMinimums()
self.pureSpinBox.setMaximum(0)
self.farSpinBox.setMaximum(0)
self.lostSpinBox.setMaximum(0)
self.maxRecallSpinBox.setMaximum(0)
def setChart(self, chart: Optional[Chart]):
if isinstance(chart, Chart):
self.__chart = chart
self.setLimits(chart)
else:
self.__chart = None
self.resetLimits()
self.updateValidateLabel()
def validateScore(self) -> ScoreValidateResult:
if not isinstance(self.__chart, Chart):
return ScoreValidateResult.ChartInvalid
score = self.value()
score_range = calculate_score_range(self.__chart, score.pure, score.far)
score_in_range = score_range[0] <= score.score <= score_range[1]
note_in_range = score.pure + score.far + score.lost <= self.__chart.note
if not score_in_range or not note_in_range:
return ScoreValidateResult.ScoreMismatch
if score.score == 0:
return ScoreValidateResult.ScoreEmpty
return ScoreValidateResult.Ok
def updateValidateLabel(self):
validate = self.validateScore()
if validate == ScoreValidateResult.Ok:
text = QCoreApplication.translate("ScoreEditor", "validate.ok")
elif validate == ScoreValidateResult.ChartInvalid:
text = QCoreApplication.translate("ScoreEditor", "validate.chartInvalid")
elif validate == ScoreValidateResult.ScoreMismatch:
text = QCoreApplication.translate("ScoreEditor", "validate.scoreMismatch")
elif validate == ScoreValidateResult.ScoreEmpty:
text = QCoreApplication.translate("ScoreEditor", "validate.scoreEmpty")
else:
text = QCoreApplication.translate("ScoreEditor", "validate.unknownState")
self.validateLabel.setText(text)
def value(self):
if isinstance(self.__chart, Chart):
return ScoreInsert(
song_id=self.__chart.song_id,
rating_class=self.__chart.rating_class,
score=self.score(),
pure=self.pureSpinBox.value(),
far=self.farSpinBox.value(),
lost=self.lostSpinBox.value(),
time=self.dateTimeEdit.dateTime().toSecsSinceEpoch(),
max_recall=self.maxRecallSpinBox.value()
if self.maxRecallSpinBox.value() > -1
else None,
clear_type=None,
)
def setValue(self, score: Score | ScoreInsert):
if isinstance(score, (Score, ScoreInsert)):
scoreText = str(score.score)
scoreText = scoreText.rjust(8, "0")
self.scoreLineEdit.setText(scoreText)
self.pureSpinBox.setValue(score.pure)
self.farSpinBox.setValue(score.far)
self.lostSpinBox.setValue(score.lost)
self.dateTimeEdit.setDateTime(QDateTime.fromSecsSinceEpoch(score.time))
if score.max_recall is not None:
self.maxRecallSpinBox.setValue(score.max_recall)
if score.clear_type is not None:
self.clearTypeComboBox.setCurrentIndex(score.clear_type)
def reset(self):
self.setChart(None)
self.scoreLineEdit.setText("''")
self.pureSpinBox.setValue(0)
self.farSpinBox.setValue(0)
self.lostSpinBox.setValue(0)
self.maxRecallSpinBox.setValue(-1)
self.clearTypeComboBox.setCurrentIndex(-1)

View File

@ -0,0 +1,38 @@
from traceback import format_exception
from PySide6.QtWidgets import QMainWindow
from ui.designer.mainwindow_ui import Ui_MainWindow
from ui.implements.tabs.tabOcr import TabOcr
# try:
# import arcaea_offline_ocr
# from ui.implements.tabs.tabOcr import TabOcr
# OCR_ENABLED_FLAG = True
# except Exception as e:
# from ui.implements.tabs.tabOcrDisabled import TabOcrDisabled
# OCR_ENABLED_FLAG = False
# OCR_ERROR_TEXT = "\n".join(format_exception(e))
class MainWindow(Ui_MainWindow, QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
currentIndex = self.tabWidget.currentIndex()
ocrTabIndex = self.tabWidget.indexOf(self.tab_ocr)
self.tabWidget.removeTab(ocrTabIndex)
self.tab_ocr.deleteLater()
# if OCR_ENABLED_FLAG:
# self.tab_ocr = TabOcr(self.tabWidget)
# else:
# self.tab_ocr = TabOcrDisabled(self.tabWidget)
# self.tab_ocr.contentLabel.setText(OCR_ERROR_TEXT)
self.tab_ocr = TabOcr(self.tabWidget)
self.tabWidget.insertTab(ocrTabIndex, self.tab_ocr, "")
self.tabWidget.setCurrentIndex(currentIndex)
self.retranslateUi(self)

View File

@ -0,0 +1,73 @@
from arcaea_offline.database import Database
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QWidget
from ui.designer.settings.settingsDefault_ui import Ui_SettingsDefault
from ui.extends.ocr import load_devices_json
from ui.extends.settings import *
class SettingsDefault(Ui_SettingsDefault, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.settings = Settings(self)
self.devicesJsonFileSelector.filesSelected.connect(self.fillDevicesComboBox)
self.devicesJsonFileResetButton.clicked.connect(self.resetDevicesJsonFile)
self.deviceUuidResetButton.clicked.connect(self.resetDeviceUuid)
devicesJsonPath = self.settings.devicesJsonFile()
self.devicesJsonFileSelector.selectFile(devicesJsonPath)
tesseractPath = self.settings.tesseractPath()
self.tesseractFileSelector.selectFile(tesseractPath)
self.devicesJsonFileSelector.accepted.connect(
self.on_devicesJsonFileSelector_accepted
)
self.tesseractFileSelector.accepted.connect(
self.on_tesseractFileSelector_accepted
)
def setDevicesJsonFile(self):
try:
filename = self.devicesJsonFileSelector.selectedFiles()[0]
devices = load_devices_json(filename)
assert isinstance(devices, list)
self.settings.setDevicesJsonFile(filename)
except Exception as e:
print(e)
# QMessageBox
return
def resetDevicesJsonFile(self):
self.devicesJsonFileSelector.reset()
self.settings.resetDevicesJsonFile()
def on_devicesJsonFileSelector_accepted(self):
self.setDevicesJsonFile()
def fillDevicesComboBox(self):
devicesJsonPath = self.devicesJsonFileSelector.selectedFiles()[0]
self.devicesComboBox.loadDevicesJson(devicesJsonPath)
storedDeviceUuid = self.settings.deviceUuid()
self.devicesComboBox.selectDevice(storedDeviceUuid)
@Slot()
def on_devicesComboBox_activated(self):
device = self.devicesComboBox.currentData()
if device:
self.settings.setDeviceUuid(device.uuid)
def resetDeviceUuid(self):
self.devicesComboBox.setCurrentIndex(-1)
self.settings.resetDeviceUuid()
def setTesseractFile(self):
file = self.tesseractFileSelector.selectedFiles()[0]
self.settings.setTesseractPath(file)
def on_tesseractFileSelector_accepted(self):
self.setTesseractFile()

View File

@ -0,0 +1,23 @@
from PySide6.QtCore import Qt, Slot
from PySide6.QtGui import QPixmap
from PySide6.QtWidgets import QMessageBox, QWidget
from ui.designer.tabs.tabAbout_ui import Ui_TabAbout
class TabAbout(Ui_TabAbout, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
logoPixmap = QPixmap(":/images/logo.png").scaled(
300,
300,
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation,
)
self.logoLabel.setPixmap(logoPixmap)
@Slot()
def on_aboutQtButton_clicked(self):
QMessageBox.aboutQt(self)

View File

@ -0,0 +1,30 @@
import logging
import traceback
from arcaea_offline.database import Database
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QFileDialog, QMessageBox, QWidget
from ui.designer.tabs.tabDb.tabDb_Manage_ui import Ui_TabDb_Manage
logger = logging.getLogger(__name__)
class TabDb_Manage(Ui_TabDb_Manage, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
@Slot()
def on_syncArcSongDbButton_clicked(self):
dbFile, filter = QFileDialog.getOpenFileName(
self, None, "", "DB File (*.db);;*"
)
try:
Database().update_arcsong_db(dbFile)
QMessageBox.information(self, "OK", "OK")
except Exception as e:
logging.exception("Sync arcsong.db error")
QMessageBox.critical(
self, "Sync Error", "\n".join(traceback.format_exception(e))
)

View File

@ -0,0 +1,114 @@
from arcaea_offline.models import ScoreInsert
from PySide6.QtCore import QModelIndex, Qt, Slot
from PySide6.QtGui import QColor, QPalette
from PySide6.QtWidgets import QMessageBox
from ui.extends.shared.delegates.chartDelegate import ChartDelegate
from ui.extends.shared.delegates.scoreDelegate import ScoreDelegate
from ui.extends.shared.models.tables.score import (
DbScoreTableModel,
DbScoreTableSortFilterProxyModel,
)
from ui.implements.components.dbTableViewer import DbTableViewer
class TableChartDelegate(ChartDelegate):
def getChart(self, index):
return index.data(DbScoreTableModel.ChartRole)
class TableScoreDelegate(ScoreDelegate):
def getChart(self, index):
return index.data(DbScoreTableModel.ChartRole)
def getScoreInsert(self, index: QModelIndex) -> ScoreInsert | None:
return super().getScoreInsert(index)
def getScore(self, index):
return index.data(DbScoreTableModel.ScoreRole)
def setModelData(self, editor, model, index):
if super().confirmSetModelData(editor):
model.setData(index, editor.value(), DbScoreTableModel.ScoreRole)
class DbScoreTableViewer(DbTableViewer):
def __init__(self, parent=None):
super().__init__(parent)
self.tableModel = DbScoreTableModel(self)
self.tableProxyModel = DbScoreTableSortFilterProxyModel(self)
self.tableProxyModel.setSourceModel(self.tableModel)
self.tableView.setModel(self.tableProxyModel)
self.tableView.setItemDelegateForColumn(1, TableChartDelegate(self.tableView))
self.tableView.setItemDelegateForColumn(2, 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)
self.tableModel.dataChanged.connect(self.resizeTableView)
self.fillSortComboBox()
def fillSortComboBox(self):
self.sort_comboBox.addItem("ID", [0, 1])
self.sort_comboBox.addItem(
"Score", [2, DbScoreTableSortFilterProxyModel.Sort_C2_ScoreRole]
)
self.sort_comboBox.addItem(
"Time", [2, DbScoreTableSortFilterProxyModel.Sort_C2_TimeRole]
)
self.sort_comboBox.addItem("Potential", [3, 1])
self.sort_comboBox.setCurrentIndex(0)
self.on_sort_comboBox_activated()
@Slot()
def resizeTableView(self):
self.tableView.resizeRowsToContents()
self.tableView.resizeColumnsToContents()
@Slot()
def on_sort_comboBox_activated(self):
self.sortProxyModel()
@Slot()
def on_sort_descendingCheckBox_toggled(self):
self.sortProxyModel()
@Slot()
def sortProxyModel(self):
if self.sort_comboBox.currentIndex() > -1:
column, role = self.sort_comboBox.currentData()
self.tableProxyModel.setSortRole(role)
self.tableProxyModel.sort(
column,
Qt.SortOrder.DescendingOrder
if self.sort_descendingCheckBox.isChecked()
else Qt.SortOrder.AscendingOrder,
)
@Slot()
def on_action_removeSelectedButton_clicked(self):
rows = [
srcIndex.row()
for srcIndex in [
self.tableProxyModel.mapToSource(proxyIndex)
for proxyIndex in self.tableView.selectionModel().selectedRows()
]
]
result = QMessageBox.warning(
self,
"Warning",
f"Removing {len(rows)} row(s). Are you sure?",
QMessageBox.StandardButton.Yes,
QMessageBox.StandardButton.No,
)
if result == QMessageBox.StandardButton.Yes:
self.tableModel.removeRowList(rows)
@Slot()
def on_refreshButton_clicked(self):
self.tableModel.syncDb()
self.resizeTableView()

View File

@ -0,0 +1,16 @@
from PySide6.QtCore import QCoreApplication
from PySide6.QtWidgets import QWidget
from ui.designer.tabs.tabDbEntry_ui import Ui_TabDbEntry
from ui.implements.tabs.tabDb.tabDb_ScoreTableViewer import DbScoreTableViewer
class TabDbEntry(Ui_TabDbEntry, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.tabWidget.addTab(
DbScoreTableViewer(self),
QCoreApplication.translate("TabDbEntry", "tab.scoreTableViewer"),
)

View File

@ -0,0 +1,33 @@
import traceback
from arcaea_offline.database import Database
from PySide6.QtCore import QCoreApplication, QModelIndex
from PySide6.QtWidgets import QMessageBox, QWidget
from ui.designer.tabs.tabInputScore_ui import Ui_TabInputScore
class TabInputScore(Ui_TabInputScore, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.chartSelector.valueChanged.connect(self.updateScoreEditorChart)
self.scoreEditor.accepted.connect(self.commit)
def updateScoreEditorChart(self):
chart = self.chartSelector.value()
self.scoreEditor.setChart(chart)
def commit(self):
try:
Database().insert_score(self.scoreEditor.value())
self.scoreEditor.reset()
except Exception as e:
QMessageBox.critical(
self,
# fmt: off
QCoreApplication.translate("General", "tracebackFormatExceptionOnly.title"),
QCoreApplication.translate("General", "tracebackFormatExceptionOnly.content").format(traceback.format_exception_only(e))
# fmt: on
)

View File

@ -0,0 +1,133 @@
import pytesseract
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 ui.designer.tabs.tabOcr_ui import Ui_TabOcr
from ui.extends.settings import Settings
from ui.extends.tabs.tabOcr import (
ImageDelegate,
OcrQueueModel,
OcrQueueTableProxyModel,
TableChartDelegate,
TableScoreDelegate,
)
class TabOcr(Ui_TabOcr, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.deviceFileSelector.filesSelected.connect(self.deviceFileSelected)
self.tesseractFileSelector.filesSelected.connect(
self.tesseractFileSelectorFilesSelected
)
settings = Settings()
self.deviceFileSelector.selectFile(settings.devicesJsonFile())
self.tesseractFileSelector.selectFile(settings.tesseractPath())
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()
@Slot()
def on_openWizardButton_clicked(self):
wizard = Wizard(self)
wizard.open()
def deviceFileSelected(self):
selectedFiles = self.deviceFileSelector.selectedFiles()
if selectedFiles:
file = selectedFiles[0]
self.deviceComboBox.loadDevicesJson(file)
def tesseractFileSelectorFilesSelected(self):
selectedFiles = self.tesseractFileSelector.selectedFiles()
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(
self, None, "", "Image Files (*.png *.jpg *.jpeg *.bmp *.webp);;*"
)
for file in files:
self.ocrQueueModel.addItem(file)
self.tableView.resizeRowsToContents()
self.tableView.resizeColumnsToContents()
@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)
@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)

View File

@ -0,0 +1,9 @@
from PySide6.QtWidgets import QWidget
from ui.designer.tabs.tabOcrDisabled_ui import Ui_TabOcrDisabled
class TabOcrDisabled(Ui_TabOcrDisabled, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)

View File

@ -0,0 +1,18 @@
from arcaea_offline.database import Database
from PySide6.QtWidgets import QWidget
from ui.designer.tabs.tabOverview_ui import Ui_TabOverview
class TabOverview(Ui_TabOverview, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.db = Database()
self.db.register_update_hook(self.updateOverview)
self.updateOverview()
def updateOverview(self):
b30 = self.db.get_b30() or 0.00
self.b30Label.setText(str(f"{b30:.3f}"))

View File

@ -0,0 +1,23 @@
from PySide6.QtCore import QModelIndex, Slot
from PySide6.QtWidgets import QListWidgetItem, QWidget
from ui.designer.tabs.tabSettings_ui import Ui_TabSettings
class SettingsEntryItem(QListWidgetItem):
pass
class TabSettings(Ui_TabSettings, QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.listWidget.addItem("Default")
self.listWidget.activated.connect(self.switchPage)
self.listWidget.setCurrentRow(self.stackedWidget.currentIndex())
@Slot(QModelIndex)
def switchPage(self, index: QModelIndex):
self.stackedWidget.setCurrentIndex(index.row())