Remove all carts code
This commit is contained in:
parent
5278b124ca
commit
c5ca1469dc
@ -9,17 +9,9 @@ class Config(object):
|
||||
AUDIO_SEGMENT_CHUNK_SIZE = 10
|
||||
BITRATE_LOW_THRESHOLD = 192
|
||||
BITRATE_OK_THRESHOLD = 300
|
||||
CART_DIRECTORY = "/home/kae/radio/CartTracks"
|
||||
CARTS_COUNT = 10
|
||||
CARTS_HIDE = True
|
||||
COLOUR_BITRATE_LOW = "#ffcdd2"
|
||||
COLOUR_BITRATE_MEDIUM = "#ffeb6f"
|
||||
COLOUR_BITRATE_OK = "#dcedc8"
|
||||
COLOUR_CART_ERROR = "#dc3545"
|
||||
COLOUR_CART_PLAYING = "#248f24"
|
||||
COLOUR_CART_PROGRESSBAR = "#000000"
|
||||
COLOUR_CART_READY = "#ffc107"
|
||||
COLOUR_CART_UNCONFIGURED = "#f2f2f2"
|
||||
COLOUR_CURRENT_PLAYLIST = "#7eca8f"
|
||||
COLOUR_CURRENT_TAB = "#248f24"
|
||||
COLOUR_ENDING_TIMER = "#dc3545"
|
||||
|
||||
@ -23,23 +23,6 @@ from sqlalchemy.orm import (
|
||||
|
||||
|
||||
# Database classes
|
||||
class CartsTable(Model):
|
||||
__tablename__ = "carts"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
cart_number: Mapped[int] = mapped_column(unique=True)
|
||||
name: Mapped[str] = mapped_column(String(256), index=True)
|
||||
duration: Mapped[Optional[int]] = mapped_column(index=True)
|
||||
path: Mapped[Optional[str]] = mapped_column(String(2048), index=False)
|
||||
enabled: Mapped[Optional[bool]] = mapped_column(default=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<Carts(id={self.id}, cart={self.cart_number}, "
|
||||
f"name={self.name}, path={self.path}>"
|
||||
)
|
||||
|
||||
|
||||
class NoteColoursTable(Model):
|
||||
__tablename__ = "notecolours"
|
||||
|
||||
|
||||
@ -37,28 +37,6 @@ db = Alchemical(ALCHEMICAL_DATABASE_URI, engine_options=Config.ENGINE_OPTIONS)
|
||||
|
||||
|
||||
# Database classes
|
||||
class Carts(dbtables.CartsTable):
|
||||
def __init__(
|
||||
self,
|
||||
session: Session,
|
||||
cart_number: int,
|
||||
name: str,
|
||||
duration: Optional[int] = None,
|
||||
path: Optional[str] = None,
|
||||
enabled: bool = True,
|
||||
) -> None:
|
||||
"""Create new cart"""
|
||||
|
||||
self.cart_number = cart_number
|
||||
self.name = name
|
||||
self.duration = duration
|
||||
self.path = path
|
||||
self.enabled = enabled
|
||||
|
||||
session.add(self)
|
||||
session.commit()
|
||||
|
||||
|
||||
class NoteColours(dbtables.NoteColoursTable):
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@ -60,7 +60,7 @@ from classes import (
|
||||
from config import Config
|
||||
from dialogs import TrackSelectDialog, ReplaceFilesDialog
|
||||
from log import log
|
||||
from models import db, Carts, Playdates, PlaylistRows, Playlists, Settings, Tracks
|
||||
from models import db, Playdates, PlaylistRows, Playlists, Settings, Tracks
|
||||
from playlistmodel import PlaylistModel, PlaylistProxyModel
|
||||
from playlists import PlaylistTab
|
||||
from trackmanager import (
|
||||
@ -69,7 +69,6 @@ from trackmanager import (
|
||||
track_sequence,
|
||||
)
|
||||
from ui import icons_rc # noqa F401
|
||||
from ui.dlg_cart_ui import Ui_DialogCartEdit # type: ignore
|
||||
from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist # type: ignore
|
||||
from ui.downloadcsv_ui import Ui_DateSelect # type: ignore
|
||||
from ui.main_window_ui import Ui_MainWindow # type: ignore
|
||||
@ -77,73 +76,6 @@ from utilities import check_db, update_bitrates
|
||||
import helpers
|
||||
|
||||
|
||||
class CartButton(QPushButton):
|
||||
"""Button for playing carts"""
|
||||
|
||||
progress = pyqtSignal(int)
|
||||
|
||||
def __init__(self, musicmuster: "Window", cart: Carts, *args, **kwargs):
|
||||
"""Create a cart pushbutton and set it disabled"""
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
self.musicmuster = musicmuster
|
||||
self.cart_id = cart.id
|
||||
if cart.path and cart.enabled and not cart.duration:
|
||||
tags = helpers.get_tags(cart.path)
|
||||
cart.duration = tags["duration"]
|
||||
self.duration = cart.duration
|
||||
self.path = cart.path
|
||||
self.player = None
|
||||
self.is_playing = False
|
||||
|
||||
self.setEnabled(True)
|
||||
self.setMinimumSize(QSize(147, 61))
|
||||
font = QFont()
|
||||
font.setPointSize(14)
|
||||
self.setFont(font)
|
||||
self.setObjectName("cart_" + str(cart.cart_number))
|
||||
|
||||
self.pgb = QProgressBar(self)
|
||||
self.pgb.setTextVisible(False)
|
||||
self.pgb.setVisible(False)
|
||||
palette = self.pgb.palette()
|
||||
palette.setColor(
|
||||
QPalette.ColorRole.Highlight, QColor(Config.COLOUR_CART_PROGRESSBAR)
|
||||
)
|
||||
self.pgb.setPalette(palette)
|
||||
self.pgb.setGeometry(0, 0, self.width(), 10)
|
||||
self.pgb.setMinimum(0)
|
||||
self.pgb.setMaximum(1)
|
||||
self.pgb.setValue(0)
|
||||
|
||||
self.progress.connect(self.pgb.setValue)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<CartButton(cart_id={self.cart_id} "
|
||||
f"path={self.path}, is_playing={self.is_playing}>"
|
||||
)
|
||||
|
||||
def event(self, event: Optional[QEvent]) -> bool:
|
||||
"""Allow right click even when button is disabled"""
|
||||
|
||||
if not event:
|
||||
return False
|
||||
|
||||
if event.type() == QEvent.Type.MouseButtonRelease:
|
||||
mouse_event = cast(QMouseEvent, event)
|
||||
if mouse_event.button() == Qt.MouseButton.RightButton:
|
||||
self.musicmuster.cart_edit(self, event)
|
||||
return True
|
||||
|
||||
return super().event(event)
|
||||
|
||||
def resizeEvent(self, event: Optional[QResizeEvent]) -> None:
|
||||
"""Resize progess bar when button size changes"""
|
||||
|
||||
self.pgb.setGeometry(0, 0, self.width(), 10)
|
||||
|
||||
|
||||
class ImportTrack(QObject):
|
||||
import_finished = pyqtSignal()
|
||||
|
||||
@ -254,11 +186,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.audacity_client: Optional[pipeclient.PipeClient] = None
|
||||
self.initialise_audacity()
|
||||
|
||||
if Config.CARTS_HIDE:
|
||||
self.cartsWidget.hide()
|
||||
self.frame_6.hide()
|
||||
else:
|
||||
self.carts_init()
|
||||
self.disable_selection_timing = False
|
||||
self.clock_counter = 0
|
||||
self.timer10.start(10)
|
||||
@ -291,137 +218,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
QMessageBox.StandardButton.Ok,
|
||||
)
|
||||
|
||||
def cart_configure(self, cart: Carts, btn: CartButton) -> None:
|
||||
"""Configure button with cart data"""
|
||||
|
||||
btn.setEnabled(False)
|
||||
btn.pgb.setVisible(False)
|
||||
if cart.path:
|
||||
if not helpers.file_is_unreadable(cart.path):
|
||||
colour = Config.COLOUR_CART_READY
|
||||
btn.path = cart.path
|
||||
btn.player = self.music.VLC.media_player_new(cart.path)
|
||||
if btn.player:
|
||||
btn.player.audio_set_volume(Config.VLC_VOLUME_DEFAULT)
|
||||
if cart.enabled:
|
||||
btn.setEnabled(True)
|
||||
btn.pgb.setVisible(True)
|
||||
else:
|
||||
colour = Config.COLOUR_CART_ERROR
|
||||
else:
|
||||
colour = Config.COLOUR_CART_UNCONFIGURED
|
||||
|
||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||
if cart.name is not None:
|
||||
btn.setText(cart.name)
|
||||
|
||||
def cart_click(self) -> None:
|
||||
"""Handle cart click"""
|
||||
|
||||
btn = self.sender()
|
||||
if not isinstance(btn, CartButton):
|
||||
return
|
||||
|
||||
if not helpers.file_is_unreadable(btn.path):
|
||||
# Don't allow clicks while we're playing
|
||||
btn.setEnabled(False)
|
||||
if not btn.player:
|
||||
log.debug(f"musicmuster.cart_click(): no player assigned ({btn=})")
|
||||
return
|
||||
|
||||
btn.player.play()
|
||||
btn.is_playing = True
|
||||
colour = Config.COLOUR_CART_PLAYING
|
||||
thread = threading.Thread(target=self.cart_progressbar, args=(btn,))
|
||||
thread.start()
|
||||
else:
|
||||
colour = Config.COLOUR_CART_ERROR
|
||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||
btn.pgb.setMinimum(0)
|
||||
|
||||
def cart_edit(self, btn: CartButton, event: QEvent):
|
||||
"""Handle context menu for cart button"""
|
||||
|
||||
with db.Session() as session:
|
||||
cart = session.query(Carts).get(btn.cart_id)
|
||||
if cart is None:
|
||||
log.error("cart_edit: cart not found")
|
||||
return
|
||||
|
||||
dlg = CartDialog(musicmuster=self, session=session, cart=cart)
|
||||
if dlg.exec():
|
||||
name = dlg.ui.lineEditName.text()
|
||||
if not name:
|
||||
QMessageBox.warning(self, "Error", "Name required")
|
||||
return
|
||||
path = dlg.path
|
||||
if not path:
|
||||
QMessageBox.warning(self, "Error", "Filename required")
|
||||
return
|
||||
if cart.path and not helpers.file_is_unreadable(cart.path):
|
||||
tags = helpers.get_tags(cart.path)
|
||||
cart.duration = tags["duration"]
|
||||
|
||||
cart.enabled = dlg.ui.chkEnabled.isChecked()
|
||||
cart.name = name
|
||||
cart.path = path
|
||||
|
||||
session.add(cart)
|
||||
session.commit()
|
||||
|
||||
self.cart_configure(cart, btn)
|
||||
|
||||
def carts_init(self) -> None:
|
||||
"""Initialse carts data structures"""
|
||||
|
||||
with db.Session() as session:
|
||||
# Number carts from 1 for humanity
|
||||
for cart_number in range(1, Config.CARTS_COUNT + 1):
|
||||
cart = session.query(Carts).get(cart_number)
|
||||
if cart is None:
|
||||
cart = Carts(session, cart_number, name=f"Cart #{cart_number}")
|
||||
|
||||
btn = CartButton(self, cart)
|
||||
btn.clicked.connect(self.cart_click)
|
||||
# Insert button on left of cart space starting at
|
||||
# location zero
|
||||
self.horizontalLayout_Carts.insertWidget(cart.id - 1, btn)
|
||||
# Configure button
|
||||
self.cart_configure(cart, btn)
|
||||
|
||||
def cart_progressbar(self, btn: CartButton) -> None:
|
||||
"""Manage progress bar"""
|
||||
|
||||
if not btn.duration:
|
||||
return
|
||||
|
||||
ms = 0
|
||||
btn.pgb.setMaximum(btn.duration)
|
||||
while ms <= btn.duration:
|
||||
btn.progress.emit(ms)
|
||||
ms += 100
|
||||
sleep(0.1)
|
||||
|
||||
def cart_tick(self) -> None:
|
||||
"""Cart clock actions"""
|
||||
|
||||
for i in range(self.horizontalLayout_Carts.count()):
|
||||
btn = self.horizontalLayout_Carts.itemAt(i).widget()
|
||||
if not btn:
|
||||
continue
|
||||
if btn.is_playing:
|
||||
if not btn.player.is_playing():
|
||||
# Cart has finished playing
|
||||
btn.is_playing = False
|
||||
btn.setEnabled(True)
|
||||
# Setting to position 0 doesn't seem to work
|
||||
btn.player = self.music.VLC.media_player_new(btn.path)
|
||||
MainTrackManager,
|
||||
btn.player.audio_set_volume(Config.VLC_VOLUME_DEFAULT)
|
||||
colour = Config.COLOUR_CART_READY
|
||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||
btn.pgb.setValue(0)
|
||||
|
||||
def clear_next(self) -> None:
|
||||
"""
|
||||
Clear next track
|
||||
@ -1703,8 +1499,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""
|
||||
|
||||
self.lblTOD.setText(dt.datetime.now().strftime(Config.TOD_TIME_FORMAT))
|
||||
# Update carts
|
||||
# self.cart_tick()
|
||||
|
||||
def tick_100ms(self) -> None:
|
||||
"""
|
||||
@ -1844,44 +1638,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.hdrNextTrack.setText("")
|
||||
|
||||
|
||||
class CartDialog(QDialog):
|
||||
"""Edit cart details"""
|
||||
|
||||
def __init__(
|
||||
self, musicmuster: Window, session: Session, cart: Carts, *args, **kwargs
|
||||
) -> None:
|
||||
"""
|
||||
Manage carts
|
||||
"""
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
self.musicmuster = musicmuster
|
||||
self.session = session
|
||||
|
||||
self.ui = Ui_DialogCartEdit()
|
||||
self.ui.setupUi(self)
|
||||
self.path = cart.path
|
||||
self.ui.lblPath.setText(self.path)
|
||||
self.ui.lineEditName.setText(cart.name)
|
||||
self.ui.chkEnabled.setChecked(cart.enabled)
|
||||
|
||||
self.setWindowTitle("Edit Cart " + str(cart.id))
|
||||
|
||||
self.ui.btnFile.clicked.connect(self.choose_file)
|
||||
|
||||
def choose_file(self) -> None:
|
||||
"""File select"""
|
||||
|
||||
dlg = QFileDialog()
|
||||
dlg.setFileMode(QFileDialog.FileMode.ExistingFile)
|
||||
dlg.setViewMode(QFileDialog.ViewMode.Detail)
|
||||
dlg.setDirectory(Config.CART_DIRECTORY)
|
||||
dlg.setNameFilter("Music files (*.flac *.mp3)")
|
||||
if dlg.exec():
|
||||
self.path = dlg.selectedFiles()[0]
|
||||
self.ui.lblPath.setText(self.path)
|
||||
|
||||
|
||||
class DownloadCSV(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user