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 typing import List, Optional
|
||||||
|
|
||||||
from PyQt5.QtCore import QDate, QEvent, Qt, QSize, QTime, QTimer
|
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 (
|
from PyQt5.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
QDialog,
|
QDialog,
|
||||||
@ -22,6 +22,7 @@ from PyQt5.QtWidgets import (
|
|||||||
QMainWindow,
|
QMainWindow,
|
||||||
QMessageBox,
|
QMessageBox,
|
||||||
QPushButton,
|
QPushButton,
|
||||||
|
QProgressBar,
|
||||||
)
|
)
|
||||||
|
|
||||||
from dbconfig import engine, Session
|
from dbconfig import engine, Session
|
||||||
@ -57,6 +58,7 @@ class CartButton(QPushButton):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.cart_id = cart.id
|
self.cart_id = cart.id
|
||||||
|
self.duration = cart.duration
|
||||||
self.path = cart.path
|
self.path = cart.path
|
||||||
self.player = None
|
self.player = None
|
||||||
self.is_playing = False
|
self.is_playing = False
|
||||||
@ -68,6 +70,13 @@ class CartButton(QPushButton):
|
|||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.setObjectName("cart_" + str(cart.cart_number))
|
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:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
f"<CartButton(cart_id={self.cart_id} "
|
f"<CartButton(cart_id={self.cart_id} "
|
||||||
@ -84,6 +93,11 @@ class CartButton(QPushButton):
|
|||||||
|
|
||||||
return super().event(event)
|
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:
|
class TrackData:
|
||||||
def __init__(self, track):
|
def __init__(self, track):
|
||||||
@ -144,6 +158,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
"""Configure button with cart data"""
|
"""Configure button with cart data"""
|
||||||
|
|
||||||
btn.setEnabled(False)
|
btn.setEnabled(False)
|
||||||
|
btn.pgb.setVisible(False)
|
||||||
if cart.path:
|
if cart.path:
|
||||||
if helpers.file_is_readable(cart.path):
|
if helpers.file_is_readable(cart.path):
|
||||||
colour = Config.COLOUR_CART_READY
|
colour = Config.COLOUR_CART_READY
|
||||||
@ -152,6 +167,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
btn.player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
|
btn.player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
|
||||||
if cart.enabled:
|
if cart.enabled:
|
||||||
btn.setEnabled(True)
|
btn.setEnabled(True)
|
||||||
|
btn.pgb.setVisible(True)
|
||||||
else:
|
else:
|
||||||
colour = Config.COLOUR_CART_ERROR
|
colour = Config.COLOUR_CART_ERROR
|
||||||
else:
|
else:
|
||||||
@ -171,6 +187,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
colour = Config.COLOUR_CART_ERROR
|
colour = Config.COLOUR_CART_ERROR
|
||||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||||
|
btn.pgb.minimum = 0
|
||||||
|
|
||||||
|
|
||||||
def cart_edit(self, btn: CartButton, event: QEvent):
|
def cart_edit(self, btn: CartButton, event: QEvent):
|
||||||
"""Handle context menu for cart button"""
|
"""Handle context menu for cart button"""
|
||||||
@ -196,6 +214,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
cart.duration = tags['duration']
|
cart.duration = tags['duration']
|
||||||
|
|
||||||
cart.enabled = dlg.ui.chkEnabled.isChecked()
|
cart.enabled = dlg.ui.chkEnabled.isChecked()
|
||||||
|
cart.pgb.setVisible(cart.enabled)
|
||||||
cart.name = name
|
cart.name = name
|
||||||
cart.path = path
|
cart.path = path
|
||||||
|
|
||||||
@ -231,7 +250,11 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
if not btn:
|
if not btn:
|
||||||
continue
|
continue
|
||||||
if btn.is_playing:
|
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
|
# Cart has finished playing
|
||||||
btn.is_playing = False
|
btn.is_playing = False
|
||||||
# Setting to position 0 doesn't seem to work
|
# 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)
|
btn.player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
|
||||||
colour = Config.COLOUR_CART_READY
|
colour = Config.COLOUR_CART_READY
|
||||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||||
|
btn.pgb.setValue(0)
|
||||||
|
|
||||||
def clear_selection(self) -> None:
|
def clear_selection(self) -> None:
|
||||||
""" Clear selected row"""
|
""" Clear selected row"""
|
||||||
@ -1111,7 +1135,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
"""
|
"""
|
||||||
Carry out clock tick actions.
|
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
|
All other timers are updated every second. As the timer displays
|
||||||
have a one-second resolution, updating every 500ms can result in
|
have a one-second resolution, updating every 500ms can result in
|
||||||
@ -1120,6 +1145,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
Actions required:
|
Actions required:
|
||||||
- Update TOD clock
|
- Update TOD clock
|
||||||
|
- Call cart_tick
|
||||||
- If track is playing:
|
- If track is playing:
|
||||||
update track clocks time and colours
|
update track clocks time and colours
|
||||||
- Else:
|
- Else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user