Use signal to update cart progress bar

This commit is contained in:
Keith Edmunds 2022-10-26 20:09:04 +01:00
parent 52776fcf8d
commit 0f5edcc86c

View File

@ -10,7 +10,7 @@ from datetime import datetime, timedelta
from time import sleep 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 pyqtSignal, QDate, QEvent, Qt, QSize, QTime, QTimer
from PyQt5.QtGui import QColor, QFont, QPalette, QResizeEvent from PyQt5.QtGui import QColor, QFont, QPalette, QResizeEvent
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QApplication,
@ -53,6 +53,8 @@ from utilities import check_db, update_bitrates
class CartButton(QPushButton): class CartButton(QPushButton):
"""Button for playing carts""" """Button for playing carts"""
progress = pyqtSignal(int)
def __init__(self, parent: QMainWindow, cart: Carts): def __init__(self, parent: QMainWindow, cart: Carts):
"""Create a cart pushbutton and set it disabled""" """Create a cart pushbutton and set it disabled"""
@ -85,6 +87,8 @@ class CartButton(QPushButton):
self.pgb.setMaximum(1) self.pgb.setMaximum(1)
self.pgb.setValue(0) self.pgb.setValue(0)
self.progress.connect(self.pgb.setValue)
def __repr__(self) -> str: def __repr__(self) -> str:
return ( return (
f"<CartButton(cart_id={self.cart_id} " f"<CartButton(cart_id={self.cart_id} "
@ -195,9 +199,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, thread = threading.Thread(target=self.cart_progressbar,
# args=(btn,)) args=(btn,))
# thread.start() 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")
@ -260,7 +264,7 @@ class Window(QMainWindow, Ui_MainWindow):
ms = 0 ms = 0
btn.pgb.setMaximum(btn.duration) btn.pgb.setMaximum(btn.duration)
while ms <= btn.duration: while ms <= btn.duration:
btn.pgb.setValue(ms) btn.progress.emit(ms)
ms += 100 ms += 100
sleep(0.1) sleep(0.1)