mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
feat: PlayRatingCalculator
component
This commit is contained in:
86
ui/implements/components/playRatingCalculator.py
Normal file
86
ui/implements/components/playRatingCalculator.py
Normal file
@ -0,0 +1,86 @@
|
||||
from arcaea_offline.calculate import calculate_play_rating
|
||||
from PySide6.QtCore import QCoreApplication
|
||||
from PySide6.QtGui import QGuiApplication
|
||||
from PySide6.QtWidgets import (
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QPushButton,
|
||||
QSizePolicy,
|
||||
QSpacerItem,
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from ui.extends.shared.language import LanguageChangeEventFilter
|
||||
|
||||
from .arcaeaScoreLineEdit import ArcaeaScoreLineEdit
|
||||
|
||||
|
||||
class PlayRatingCalculator(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.languageChangeEventFilter = LanguageChangeEventFilter(self)
|
||||
self.installEventFilter(self.languageChangeEventFilter)
|
||||
|
||||
self.setupUi()
|
||||
|
||||
self.arcaeaScoreLineEdit.textChanged.connect(self.updateResultLabel)
|
||||
self.copyButton.clicked.connect(self.on_copyButton_clicked)
|
||||
|
||||
self.constant: int | None = None
|
||||
|
||||
def setConstant(self, constant: int | None):
|
||||
self.constant = constant
|
||||
self.updateResultLabel()
|
||||
|
||||
@property
|
||||
def result(self):
|
||||
if self.constant is None:
|
||||
return None
|
||||
|
||||
score = self.arcaeaScoreLineEdit.score()
|
||||
if score is None:
|
||||
return None
|
||||
|
||||
return calculate_play_rating(self.constant, score)
|
||||
|
||||
def updateResultLabel(self):
|
||||
result = self.result
|
||||
self.resultLabel.setText(str(result) if result is not None else "...")
|
||||
|
||||
def on_copyButton_clicked(self):
|
||||
result = self.result
|
||||
if result is not None:
|
||||
QGuiApplication.clipboard().setText(str(result))
|
||||
|
||||
def setupUi(self, *args):
|
||||
self.horizontalLayout = QHBoxLayout(self)
|
||||
|
||||
self.arcaeaScoreLineEdit = ArcaeaScoreLineEdit(self)
|
||||
self.horizontalLayout.addWidget(self.arcaeaScoreLineEdit)
|
||||
|
||||
self.label = QLabel(self)
|
||||
self.label.setText(" > ")
|
||||
self.horizontalLayout.addWidget(self.label)
|
||||
|
||||
self.resultLabel = QLabel(self)
|
||||
self.resultLabel.setText("...")
|
||||
self.resultLabel.setSizePolicy(
|
||||
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred
|
||||
)
|
||||
self.horizontalLayout.addWidget(self.resultLabel)
|
||||
|
||||
self.horizontalSpacer = QSpacerItem(
|
||||
20, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred
|
||||
)
|
||||
self.horizontalLayout.addSpacerItem(self.horizontalSpacer)
|
||||
|
||||
self.copyButton = QPushButton(self)
|
||||
self.horizontalLayout.addWidget(self.copyButton)
|
||||
|
||||
self.retranslateUi()
|
||||
|
||||
def retranslateUi(self, *args):
|
||||
self.copyButton.setText(
|
||||
QCoreApplication.translate("PotentialCalculator", "copyButton")
|
||||
)
|
Reference in New Issue
Block a user