Compare commits
5 Commits
5b0d604edf
...
2f13099bda
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f13099bda | ||
|
|
9ccff3db20 | ||
|
|
ef9b1e7ce5 | ||
|
|
5e770b3975 | ||
|
|
6c92401ad6 |
@ -16,6 +16,7 @@ class Config(object):
|
||||
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_HEADER = "#d4edda"
|
||||
|
||||
@ -7,10 +7,11 @@ import sys
|
||||
import threading
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from time import sleep
|
||||
from typing import List, Optional
|
||||
|
||||
from PyQt5.QtCore import QDate, QEvent, Qt, QSize, QTime, QTimer
|
||||
from PyQt5.QtGui import QColor, QPalette, QFont
|
||||
from PyQt5.QtGui import QColor, QFont, QPalette, QResizeEvent
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
QDialog,
|
||||
@ -22,6 +23,7 @@ from PyQt5.QtWidgets import (
|
||||
QMainWindow,
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QProgressBar,
|
||||
)
|
||||
|
||||
from dbconfig import engine, Session
|
||||
@ -57,6 +59,10 @@ class CartButton(QPushButton):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
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
|
||||
@ -68,6 +74,17 @@ class CartButton(QPushButton):
|
||||
self.setFont(font)
|
||||
self.setObjectName("cart_" + str(cart.cart_number))
|
||||
|
||||
self.pgb = QProgressBar(self, textVisible=False)
|
||||
self.pgb.setVisible(False)
|
||||
palette = self.pgb.palette()
|
||||
palette.setColor(QPalette.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)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<CartButton(cart_id={self.cart_id} "
|
||||
@ -84,6 +101,11 @@ class CartButton(QPushButton):
|
||||
|
||||
return super().event(event)
|
||||
|
||||
def resizeEvent(self, event: QResizeEvent) -> None:
|
||||
"""Resize progess bar when button size changes"""
|
||||
|
||||
self.pgb.setGeometry(0, 0, self.width(), 10)
|
||||
|
||||
|
||||
class TrackData:
|
||||
def __init__(self, track):
|
||||
@ -144,6 +166,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""Configure button with cart data"""
|
||||
|
||||
btn.setEnabled(False)
|
||||
btn.pgb.setVisible(False)
|
||||
if cart.path:
|
||||
if helpers.file_is_readable(cart.path):
|
||||
colour = Config.COLOUR_CART_READY
|
||||
@ -152,6 +175,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
btn.player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
|
||||
if cart.enabled:
|
||||
btn.setEnabled(True)
|
||||
btn.pgb.setVisible(True)
|
||||
else:
|
||||
colour = Config.COLOUR_CART_ERROR
|
||||
else:
|
||||
@ -164,13 +188,20 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""Handle cart click"""
|
||||
|
||||
btn = self.sender()
|
||||
|
||||
if helpers.file_is_readable(btn.path):
|
||||
# Don't allow clicks while we're playing
|
||||
btn.setEnabled(False)
|
||||
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.minimum = 0
|
||||
|
||||
def cart_edit(self, btn: CartButton, event: QEvent):
|
||||
"""Handle context menu for cart button"""
|
||||
@ -223,6 +254,16 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# Configure button
|
||||
self.cart_configure(cart, btn)
|
||||
|
||||
def cart_progressbar(self, btn: CartButton) -> None:
|
||||
"""Manage progress bar"""
|
||||
|
||||
ms = 0
|
||||
btn.pgb.setMaximum(btn.duration)
|
||||
while ms <= btn.duration:
|
||||
btn.pgb.setValue(ms)
|
||||
ms += 100
|
||||
sleep(0.1)
|
||||
|
||||
def cart_tick(self) -> None:
|
||||
"""Cart clock actions"""
|
||||
|
||||
@ -234,11 +275,13 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
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)
|
||||
btn.player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
|
||||
colour = Config.COLOUR_CART_READY
|
||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||
btn.pgb.setValue(0)
|
||||
|
||||
def clear_selection(self) -> None:
|
||||
""" Clear selected row"""
|
||||
@ -1111,7 +1154,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""
|
||||
Carry out clock tick actions.
|
||||
|
||||
The Time of Day clock is updated every tick (500ms).
|
||||
The Time of Day clock and any cart progress bars are updated
|
||||
every tick (500ms).
|
||||
|
||||
All other timers are updated every second. As the timer displays
|
||||
have a one-second resolution, updating every 500ms can result in
|
||||
@ -1120,6 +1164,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
Actions required:
|
||||
- Update TOD clock
|
||||
- Call cart_tick
|
||||
- If track is playing:
|
||||
update track clocks time and colours
|
||||
- Else:
|
||||
|
||||
@ -823,7 +823,6 @@ class PlaylistTab(QTableWidget):
|
||||
def scroll_current_to_top(self) -> None:
|
||||
"""Scroll currently-playing row to top"""
|
||||
|
||||
log.debug("KAE: playlists.scroll_current_to_top()")
|
||||
current_row = self._get_current_track_row()
|
||||
log.debug(f"KAE: playlists.scroll_current_to_top(), {current_row=}")
|
||||
self._scroll_to_top(current_row)
|
||||
@ -831,7 +830,6 @@ class PlaylistTab(QTableWidget):
|
||||
def scroll_next_to_top(self) -> None:
|
||||
"""Scroll nextly-playing row to top"""
|
||||
|
||||
log.debug("KAE: playlists.scroll_next_to_top()")
|
||||
next_row = self._get_next_track_row()
|
||||
log.debug(f"KAE: playlists.scroll_next_to_top(), {next_row=}")
|
||||
self._scroll_to_top(next_row)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user