mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
init
This commit is contained in:
6
ui/implements/components/__init__.py
Normal file
6
ui/implements/components/__init__.py
Normal 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
|
254
ui/implements/components/chartSelector.py
Normal file
254
ui/implements/components/chartSelector.py
Normal 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)
|
9
ui/implements/components/dbTableViewer.py
Normal file
9
ui/implements/components/dbTableViewer.py
Normal 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)
|
32
ui/implements/components/devicesComboBox.py
Normal file
32
ui/implements/components/devicesComboBox.py
Normal 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)
|
50
ui/implements/components/elidedLabel.py
Normal file
50
ui/implements/components/elidedLabel.py
Normal 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)
|
91
ui/implements/components/fileSelector.py
Normal file
91
ui/implements/components/fileSelector.py
Normal 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()
|
15
ui/implements/components/focusSelectAllLineEdit.py
Normal file
15
ui/implements/components/focusSelectAllLineEdit.py
Normal 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()
|
100
ui/implements/components/ratingClassRadioButton.py
Normal file
100
ui/implements/components/ratingClassRadioButton.py
Normal 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()
|
197
ui/implements/components/scoreEditor.py
Normal file
197
ui/implements/components/scoreEditor.py
Normal 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)
|
Reference in New Issue
Block a user