mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-19 01:00:18 +00:00
impr: use QSignalMapper
for SongIdSelector
's quick switch actions
This commit is contained in:
parent
94e4d73a95
commit
6dbb7cbfef
@ -1,11 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
from arcaea_offline.database import Database
|
from arcaea_offline.database import Database
|
||||||
from arcaea_offline.models import Chart
|
from arcaea_offline.models import Chart
|
||||||
from PySide6.QtCore import QModelIndex, Qt, Signal, Slot
|
from PySide6.QtCore import QModelIndex, QSignalMapper, Qt, Signal, Slot
|
||||||
from PySide6.QtWidgets import QCompleter, QWidget
|
from PySide6.QtWidgets import QCompleter, QWidget
|
||||||
|
|
||||||
from ui.designer.components.songIdSelector_ui import Ui_SongIdSelector
|
from ui.designer.components.songIdSelector_ui import Ui_SongIdSelector
|
||||||
@ -33,18 +32,22 @@ class SongIdSelector(Ui_SongIdSelector, QWidget):
|
|||||||
self.languageChangeEventFilter = LanguageChangeEventFilter(self)
|
self.languageChangeEventFilter = LanguageChangeEventFilter(self)
|
||||||
self.installEventFilter(self.languageChangeEventFilter)
|
self.installEventFilter(self.languageChangeEventFilter)
|
||||||
|
|
||||||
self.previousPackageButton.clicked.connect(
|
# quick switch bindings
|
||||||
lambda: self.quickSwitchSelection("previous", "package")
|
self.quickSwitchSignalMapper = QSignalMapper(self)
|
||||||
|
self.previousPackageButton.clicked.connect(self.quickSwitchSignalMapper.map)
|
||||||
|
self.quickSwitchSignalMapper.setMapping(
|
||||||
|
self.previousPackageButton, "package||previous"
|
||||||
)
|
)
|
||||||
self.previousSongIdButton.clicked.connect(
|
self.nextPackageButton.clicked.connect(self.quickSwitchSignalMapper.map)
|
||||||
lambda: self.quickSwitchSelection("previous", "songId")
|
self.quickSwitchSignalMapper.setMapping(self.nextPackageButton, "package||next")
|
||||||
)
|
self.previousSongIdButton.clicked.connect(self.quickSwitchSignalMapper.map)
|
||||||
self.nextSongIdButton.clicked.connect(
|
self.quickSwitchSignalMapper.setMapping(
|
||||||
lambda: self.quickSwitchSelection("next", "songId")
|
self.previousSongIdButton, "songId||previous"
|
||||||
)
|
|
||||||
self.nextPackageButton.clicked.connect(
|
|
||||||
lambda: self.quickSwitchSelection("next", "package")
|
|
||||||
)
|
)
|
||||||
|
self.nextSongIdButton.clicked.connect(self.quickSwitchSignalMapper.map)
|
||||||
|
self.quickSwitchSignalMapper.setMapping(self.nextSongIdButton, "songId||next")
|
||||||
|
|
||||||
|
self.quickSwitchSignalMapper.mappedString.connect(self.quickSwitchSlot)
|
||||||
|
|
||||||
self.mode = SongIdSelectorMode.SongId
|
self.mode = SongIdSelectorMode.SongId
|
||||||
|
|
||||||
@ -73,12 +76,11 @@ class SongIdSelector(Ui_SongIdSelector, QWidget):
|
|||||||
def setMode(self, mode: SongIdSelectorMode):
|
def setMode(self, mode: SongIdSelectorMode):
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
|
||||||
def quickSwitchSelection(
|
@Slot(str)
|
||||||
self,
|
def quickSwitchSlot(self, action: str):
|
||||||
direction: Literal["previous", "next"],
|
model, direction = action.split("||")
|
||||||
model: Literal["package", "songId"],
|
|
||||||
):
|
minIndex = -1
|
||||||
minIndex = 0
|
|
||||||
if model == "package":
|
if model == "package":
|
||||||
maxIndex = self.packComboBox.count() - 1
|
maxIndex = self.packComboBox.count() - 1
|
||||||
currentIndex = self.packComboBox.currentIndex() + (
|
currentIndex = self.packComboBox.currentIndex() + (
|
||||||
@ -174,7 +176,7 @@ class SongIdSelector(Ui_SongIdSelector, QWidget):
|
|||||||
self.songIdComboBox.setCurrentIndex(-1)
|
self.songIdComboBox.setCurrentIndex(-1)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_packComboBox_activated(self):
|
def on_packComboBox_currentIndexChanged(self):
|
||||||
self.fillSongIdComboBox()
|
self.fillSongIdComboBox()
|
||||||
|
|
||||||
@Slot(str)
|
@Slot(str)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user