Move MusicMusterSignals into helpers
This commit is contained in:
parent
fedcfc3eea
commit
15ecae54cf
@ -1,21 +0,0 @@
|
||||
from PyQt6.QtCore import pyqtSignal, QObject
|
||||
|
||||
from helpers import singleton
|
||||
|
||||
|
||||
@singleton
|
||||
class MusicMusterSignals(QObject):
|
||||
"""
|
||||
Class for all MusicMuster signals. See:
|
||||
- https://zetcode.com/gui/pyqt5/eventssignals/
|
||||
- https://stackoverflow.com/questions/62654525/
|
||||
emit-a-signal-from-another-class-to-main-class
|
||||
and Singleton class at
|
||||
https://refactoring.guru/design-patterns/singleton/python/example#example-0
|
||||
"""
|
||||
|
||||
add_track_to_header_signal = pyqtSignal(int, int, int)
|
||||
add_track_to_playlist_signal = pyqtSignal(int, int, int, str)
|
||||
enable_escape_signal = pyqtSignal(bool)
|
||||
set_next_track_signal = pyqtSignal(int, int)
|
||||
span_cells_signal = pyqtSignal(int, int, int, int)
|
||||
@ -2,9 +2,12 @@ from PyQt6.QtCore import QEvent, Qt
|
||||
from PyQt6.QtWidgets import QDialog, QListWidgetItem
|
||||
from typing import Optional
|
||||
|
||||
import helpers
|
||||
from helpers import (
|
||||
get_relative_date,
|
||||
ms_to_mmss,
|
||||
MusicMusterSignals,
|
||||
)
|
||||
|
||||
from datastructures import MusicMusterSignals
|
||||
from dbconfig import scoped_session
|
||||
from models import Settings, Tracks
|
||||
from ui.dlg_TrackSelect_ui import Ui_Dialog # type: ignore
|
||||
@ -105,8 +108,8 @@ class TrackSelectDialog(QDialog):
|
||||
t = QListWidgetItem()
|
||||
track_text = (
|
||||
f"{track.title} - {track.artist} "
|
||||
f"[{helpers.ms_to_mmss(track.duration)}] "
|
||||
f"({helpers.get_relative_date(last_played)})"
|
||||
f"[{ms_to_mmss(track.duration)}] "
|
||||
f"({get_relative_date(last_played)})"
|
||||
)
|
||||
t.setText(track_text)
|
||||
t.setData(Qt.ItemDataRole.UserRole, track)
|
||||
@ -161,7 +164,7 @@ class TrackSelectDialog(QDialog):
|
||||
last_played = last_playdate.lastplayed
|
||||
else:
|
||||
last_played = None
|
||||
path_text = f"{track.path} ({helpers.get_relative_date(last_played)})"
|
||||
path_text = f"{track.path} ({get_relative_date(last_played)})"
|
||||
|
||||
self.ui.dbPath.setText(path_text)
|
||||
|
||||
|
||||
@ -14,11 +14,45 @@ from mutagen.flac import FLAC # type: ignore
|
||||
from mutagen.mp3 import MP3 # type: ignore
|
||||
from pydub import AudioSegment, effects
|
||||
from pydub.utils import mediainfo
|
||||
from PyQt6.QtCore import pyqtSignal, QObject
|
||||
from PyQt6.QtWidgets import QMainWindow, QMessageBox # type: ignore
|
||||
from tinytag import TinyTag # type: ignore
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
|
||||
def singleton(cls):
|
||||
"""
|
||||
Make a class a Singleton class (see
|
||||
https://realpython.com/primer-on-python-decorators/#creating-singletons)
|
||||
"""
|
||||
|
||||
@functools.wraps(cls)
|
||||
def wrapper_singleton(*args, **kwargs):
|
||||
if not wrapper_singleton.instance:
|
||||
wrapper_singleton.instance = cls(*args, **kwargs)
|
||||
return wrapper_singleton.instance
|
||||
|
||||
wrapper_singleton.instance = None
|
||||
return wrapper_singleton
|
||||
|
||||
|
||||
@singleton
|
||||
class MusicMusterSignals(QObject):
|
||||
"""
|
||||
Class for all MusicMuster signals. See:
|
||||
- https://zetcode.com/gui/pyqt5/eventssignals/
|
||||
- https://stackoverflow.com/questions/62654525/
|
||||
emit-a-signal-from-another-class-to-main-class
|
||||
and Singleton class at
|
||||
https://refactoring.guru/design-patterns/singleton/python/example#example-0
|
||||
"""
|
||||
|
||||
add_track_to_header_signal = pyqtSignal(int, int, int)
|
||||
add_track_to_playlist_signal = pyqtSignal(int, int, int, str)
|
||||
enable_escape_signal = pyqtSignal(bool)
|
||||
set_next_track_signal = pyqtSignal(int, int)
|
||||
span_cells_signal = pyqtSignal(int, int, int, int)
|
||||
|
||||
def ask_yes_no(title: str, question: str, default_yes: bool = False) -> bool:
|
||||
"""Ask question; return True for yes, False for no"""
|
||||
|
||||
@ -380,22 +414,6 @@ def show_warning(parent: QMainWindow, title: str, msg: str) -> None:
|
||||
QMessageBox.warning(parent, title, msg, buttons=QMessageBox.StandardButton.Cancel)
|
||||
|
||||
|
||||
def singleton(cls):
|
||||
"""
|
||||
Make a class a Singleton class (see
|
||||
https://realpython.com/primer-on-python-decorators/#creating-singletons)
|
||||
"""
|
||||
|
||||
@functools.wraps(cls)
|
||||
def wrapper_singleton(*args, **kwargs):
|
||||
if not wrapper_singleton.instance:
|
||||
wrapper_singleton.instance = cls(*args, **kwargs)
|
||||
return wrapper_singleton.instance
|
||||
|
||||
wrapper_singleton.instance = None
|
||||
return wrapper_singleton
|
||||
|
||||
|
||||
def trailing_silence(
|
||||
audio_segment: AudioSegment,
|
||||
silence_threshold: int = -50,
|
||||
|
||||
@ -69,7 +69,6 @@ import music
|
||||
from dialogs import TrackSelectDialog
|
||||
from models import Base, Carts, Playdates, PlaylistRows, Playlists, Settings, Tracks
|
||||
from config import Config
|
||||
from datastructures import MusicMusterSignals
|
||||
from playlists import PlaylistTab
|
||||
from ui.dlg_cart_ui import Ui_DialogCartEdit # type: ignore
|
||||
from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist # type: ignore
|
||||
@ -363,7 +362,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.timer10.start(10)
|
||||
self.timer500.start(500)
|
||||
self.timer1000.start(1000)
|
||||
self.signals = MusicMusterSignals()
|
||||
self.signals = helpers.MusicMusterSignals()
|
||||
self.connect_signals_slots()
|
||||
|
||||
def about(self) -> None:
|
||||
|
||||
@ -16,10 +16,10 @@ from PyQt6.QtGui import (
|
||||
)
|
||||
|
||||
from config import Config
|
||||
from datastructures import MusicMusterSignals
|
||||
from dbconfig import scoped_session, Session
|
||||
from helpers import (
|
||||
file_is_unreadable,
|
||||
MusicMusterSignals,
|
||||
)
|
||||
from log import log
|
||||
from models import PlaylistRows, Tracks
|
||||
|
||||
@ -35,7 +35,6 @@ from PyQt6.QtWidgets import (
|
||||
QStyleOption,
|
||||
)
|
||||
|
||||
from datastructures import MusicMusterSignals
|
||||
from dbconfig import Session, scoped_session
|
||||
from dialogs import TrackSelectDialog
|
||||
from config import Config
|
||||
@ -44,6 +43,7 @@ from helpers import (
|
||||
file_is_unreadable,
|
||||
get_relative_date,
|
||||
ms_to_mmss,
|
||||
MusicMusterSignals,
|
||||
open_in_audacity,
|
||||
send_mail,
|
||||
set_track_metadata,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user