Put progress bars on playing cart buttons.
This commit is contained in:
parent
5b0d604edf
commit
6c92401ad6
@ -10,7 +10,7 @@ from datetime import datetime, timedelta
|
||||
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 +22,7 @@ from PyQt5.QtWidgets import (
|
||||
QMainWindow,
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QProgressBar,
|
||||
)
|
||||
|
||||
from dbconfig import engine, Session
|
||||
@ -57,6 +58,7 @@ class CartButton(QPushButton):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
self.cart_id = cart.id
|
||||
self.duration = cart.duration
|
||||
self.path = cart.path
|
||||
self.player = None
|
||||
self.is_playing = False
|
||||
@ -68,6 +70,13 @@ class CartButton(QPushButton):
|
||||
self.setFont(font)
|
||||
self.setObjectName("cart_" + str(cart.cart_number))
|
||||
|
||||
self.pgb = QProgressBar(self, textVisible=False)
|
||||
self.pgb.setVisible(False)
|
||||
self.pgb.setGeometry(0, 0, self.width(), 10)
|
||||
self.pgb.setMinimum(0)
|
||||
self.pgb.setMaximum(100)
|
||||
self.pgb.setValue(0)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<CartButton(cart_id={self.cart_id} "
|
||||
@ -84,6 +93,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 +158,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 +167,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:
|
||||
@ -171,6 +187,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
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"""
|
||||
@ -196,6 +214,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
cart.duration = tags['duration']
|
||||
|
||||
cart.enabled = dlg.ui.chkEnabled.isChecked()
|
||||
cart.pgb.setVisible(cart.enabled)
|
||||
cart.name = name
|
||||
cart.path = path
|
||||
|
||||
@ -231,7 +250,11 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
if not btn:
|
||||
continue
|
||||
if btn.is_playing:
|
||||
if not btn.player.is_playing():
|
||||
if btn.player.is_playing():
|
||||
# Update progress bar
|
||||
position = btn.player.get_position()
|
||||
btn.pgb.setValue(int(position * 100))
|
||||
else:
|
||||
# Cart has finished playing
|
||||
btn.is_playing = False
|
||||
# Setting to position 0 doesn't seem to work
|
||||
@ -239,6 +262,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
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 +1135,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 +1145,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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user