Specify colour of cart progress bars
This commit is contained in:
parent
ef9b1e7ce5
commit
9ccff3db20
@ -16,6 +16,7 @@ class Config(object):
|
|||||||
COLOUR_BITRATE_OK = "#dcedc8"
|
COLOUR_BITRATE_OK = "#dcedc8"
|
||||||
COLOUR_CART_ERROR = "#dc3545"
|
COLOUR_CART_ERROR = "#dc3545"
|
||||||
COLOUR_CART_PLAYING = "#248f24"
|
COLOUR_CART_PLAYING = "#248f24"
|
||||||
|
COLOUR_CART_PROGRESSBAR = "#000000"
|
||||||
COLOUR_CART_READY = "#ffc107"
|
COLOUR_CART_READY = "#ffc107"
|
||||||
COLOUR_CART_UNCONFIGURED = "#f2f2f2"
|
COLOUR_CART_UNCONFIGURED = "#f2f2f2"
|
||||||
COLOUR_CURRENT_HEADER = "#d4edda"
|
COLOUR_CURRENT_HEADER = "#d4edda"
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from time import sleep
|
||||||
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
|
||||||
@ -58,6 +59,9 @@ 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
|
||||||
|
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.duration = cart.duration
|
||||||
self.path = cart.path
|
self.path = cart.path
|
||||||
self.player = None
|
self.player = None
|
||||||
@ -72,9 +76,13 @@ class CartButton(QPushButton):
|
|||||||
|
|
||||||
self.pgb = QProgressBar(self, textVisible=False)
|
self.pgb = QProgressBar(self, textVisible=False)
|
||||||
self.pgb.setVisible(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.setGeometry(0, 0, self.width(), 10)
|
||||||
self.pgb.setMinimum(0)
|
self.pgb.setMinimum(0)
|
||||||
self.pgb.setMaximum(100)
|
self.pgb.setMaximum(1)
|
||||||
self.pgb.setValue(0)
|
self.pgb.setValue(0)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@ -184,6 +192,9 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
btn.player.play()
|
btn.player.play()
|
||||||
btn.is_playing = True
|
btn.is_playing = True
|
||||||
colour = Config.COLOUR_CART_PLAYING
|
colour = Config.COLOUR_CART_PLAYING
|
||||||
|
thread = threading.Thread(target=self.cart_progressbar,
|
||||||
|
args=(btn,))
|
||||||
|
thread.start()
|
||||||
else:
|
else:
|
||||||
colour = Config.COLOUR_CART_ERROR
|
colour = Config.COLOUR_CART_ERROR
|
||||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||||
@ -240,6 +251,16 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# Configure button
|
# Configure button
|
||||||
self.cart_configure(cart, btn)
|
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:
|
def cart_tick(self) -> None:
|
||||||
"""Cart clock actions"""
|
"""Cart clock actions"""
|
||||||
|
|
||||||
@ -248,11 +269,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
if not btn:
|
if not btn:
|
||||||
continue
|
continue
|
||||||
if btn.is_playing:
|
if btn.is_playing:
|
||||||
if btn.player.is_playing():
|
if not 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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user