wip: arcaea-offline==0.2.0

- fix imports
This commit is contained in:
2023-08-28 22:45:50 +08:00
parent a9941e9c87
commit 2e6ca98f7d
17 changed files with 227 additions and 155 deletions

View File

@ -0,0 +1,11 @@
from typing import Type
from PySide6.QtCore import QUrl
from sqlalchemy import Engine
from sqlalchemy import create_engine as sa_create_engine
from sqlalchemy.pool import NullPool, Pool
def create_engine(_url: str | QUrl, pool: Type[Pool] = NullPool) -> Engine:
url = _url.toString() if isinstance(_url, QUrl) else _url
return sa_create_engine(url, poolclass=pool)

View File

@ -1,9 +1,7 @@
from typing import Union
from arcaea_offline.models import Chart
from arcaea_offline.utils import rating_class_to_short_text, rating_class_to_text
from PySide6.QtCore import QDateTime, QModelIndex, Qt, Signal
from PySide6.QtGui import QBrush, QColor
from arcaea_offline.utils.rating import rating_class_to_short_text, rating_class_to_text
from PySide6.QtCore import QModelIndex, Qt, Signal
from PySide6.QtGui import QColor
from PySide6.QtWidgets import (
QFrame,
QHBoxLayout,

View File

@ -1,16 +1,12 @@
from typing import Union
from arcaea_offline.calculate import calculate_score_range
from arcaea_offline.models import Chart, Score, ScoreInsert
from arcaea_offline.utils import (
rating_class_to_text,
score_to_grade_text,
zip_score_grade,
)
from arcaea_offline.models import Chart, Score
from arcaea_offline.utils.rating import rating_class_to_text
from arcaea_offline.utils.score import score_to_grade_text, zip_score_grade
from PySide6.QtCore import QAbstractItemModel, QDateTime, QModelIndex, Qt, Signal
from PySide6.QtGui import QColor, QFont, QLinearGradient
from PySide6.QtWidgets import (
QAbstractItemDelegate,
QFrame,
QHBoxLayout,
QLabel,
@ -53,7 +49,7 @@ class ScoreEditorDelegateWrapper(ScoreEditor):
self.formLayout.insertRow(0, self.delegateHeader)
def setText(self, score: Score | ScoreInsert, _extra: str = None):
def setText(self, score: Score, _extra: str = None):
text = "Editing "
text += _extra or ""
text += f"score {score.score}"
@ -91,22 +87,14 @@ class ScoreDelegate(TextSegmentDelegate):
def getScore(self, index: QModelIndex) -> Score | None:
return None
def getScoreInsert(self, index: QModelIndex) -> ScoreInsert | None:
return None
def _getScore(self, index: QModelIndex):
score = self.getScore(index)
scoreInsert = self.getScoreInsert(index)
return scoreInsert if score is None else score
def getChart(self, index: QModelIndex) -> Chart | None:
return None
def getScoreValidateOk(self, index: QModelIndex) -> bool | None:
score = self._getScore(index)
score = self.getScore(index)
chart = self.getChart(index)
if isinstance(score, (Score, ScoreInsert)) and isinstance(chart, Chart):
if isinstance(score, Score) and isinstance(chart, Chart):
scoreRange = calculate_score_range(chart, score.pure, score.far)
return scoreRange[0] <= score.score <= scoreRange[1]
@ -114,9 +102,9 @@ class ScoreDelegate(TextSegmentDelegate):
return zip_score_grade(score, self.GradeGradientsWrappers)
def getTextSegments(self, index, option):
score = self._getScore(index)
score = self.getScore(index)
chart = self.getChart(index)
if not (isinstance(score, (Score, ScoreInsert)) and isinstance(chart, Chart)):
if not (isinstance(score, Score) and isinstance(chart, Chart)):
return [
[
{
@ -176,10 +164,10 @@ class ScoreDelegate(TextSegmentDelegate):
def paint(self, painter, option, index):
# draw scoreMismatch warning background
score = self._getScore(index)
score = self.getScore(index)
chart = self.getChart(index)
if (
isinstance(score, (Score, ScoreInsert))
isinstance(score, Score)
and isinstance(chart, Chart)
and self.paintWarningBackground(index)
):
@ -206,16 +194,16 @@ class ScoreDelegate(TextSegmentDelegate):
self.closeEditor.emit(editor)
def createEditor(self, parent, option, index) -> ScoreEditorDelegateWrapper:
score = self._getScore(index)
score = self.getScore(index)
chart = self.getChart(index)
if isinstance(score, (Score, ScoreInsert)) and isinstance(chart, Chart):
if isinstance(score, Score) and isinstance(chart, Chart):
editor = ScoreEditorDelegateWrapper(parent)
editor.setWindowFlag(Qt.WindowType.Sheet, True)
editor.setWindowFlag(Qt.WindowType.FramelessWindowHint, True)
editor.setWindowTitle(
f"{chart.name_en}({chart.song_id}) | {rating_class_to_text(chart.rating_class)} | {chart.package_id}"
)
editor.setText(self._getScore(index))
editor.setText(self.getScore(index))
editor.setValidateBeforeAccept(False)
editor.move(parent.mapToGlobal(parent.pos()))
editor.accepted.connect(self._commitEditor)
@ -231,9 +219,9 @@ class ScoreDelegate(TextSegmentDelegate):
keepWidgetInScreen(editor)
def setEditorData(self, editor: ScoreEditorDelegateWrapper, index) -> None:
score = self._getScore(index)
score = self.getScore(index)
chart = self.getChart(index)
if isinstance(score, (Score, ScoreInsert)) and isinstance(chart, Chart):
if isinstance(score, Score) and isinstance(chart, Chart):
editor.setChart(chart)
editor.setValue(score)

View File

@ -1,5 +1,5 @@
from arcaea_offline.calculate import calculate_score
from arcaea_offline.models import Chart, Score, ScoreInsert
# from arcaea_offline.calculate import calculate_score
from arcaea_offline.models import Chart, Score
from PySide6.QtCore import QCoreApplication, QModelIndex, QSortFilterProxyModel, Qt
from .base import DbTableModel

View File

@ -1,7 +1,7 @@
from PySide6.QtCore import QDir, QSettings
from PySide6.QtCore import QDir, QSettings, QUrl
__all__ = [
"DATABASE_PATH",
"DATABASE_URL",
"DEVICES_JSON_FILE",
"DEVICE_UUID",
"TESSERACT_FILE",
@ -10,7 +10,7 @@ __all__ = [
"Settings",
]
DATABASE_PATH = "General/DatabasePath"
DATABASE_URL = "General/DatabaseUrl"
DEVICES_JSON_FILE = "Ocr/DevicesJsonFile"
DEVICE_UUID = "Ocr/DeviceUuid"
@ -27,6 +27,13 @@ class Settings(QSettings):
parent,
)
def databaseUrl(self) -> str | None:
return self.value(DATABASE_URL, None, str)
def setDatabaseUrl(self, value: str):
self.setValue(DATABASE_URL, value)
self.sync()
def devicesJsonFile(self) -> str | None:
return self.value(DEVICES_JSON_FILE, None, str)