Use signal to update cart progress bar
This commit is contained in:
parent
52776fcf8d
commit
0f5edcc86c
@ -10,7 +10,7 @@ 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.QtCore import pyqtSignal, QDate, QEvent, Qt, QSize, QTime, QTimer
|
||||
from PyQt5.QtGui import QColor, QFont, QPalette, QResizeEvent
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
@ -53,6 +53,8 @@ from utilities import check_db, update_bitrates
|
||||
class CartButton(QPushButton):
|
||||
"""Button for playing carts"""
|
||||
|
||||
progress = pyqtSignal(int)
|
||||
|
||||
def __init__(self, parent: QMainWindow, cart: Carts):
|
||||
"""Create a cart pushbutton and set it disabled"""
|
||||
|
||||
@ -85,6 +87,8 @@ class CartButton(QPushButton):
|
||||
self.pgb.setMaximum(1)
|
||||
self.pgb.setValue(0)
|
||||
|
||||
self.progress.connect(self.pgb.setValue)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<CartButton(cart_id={self.cart_id} "
|
||||
@ -195,9 +199,9 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
btn.player.play()
|
||||
btn.is_playing = True
|
||||
colour = Config.COLOUR_CART_PLAYING
|
||||
# thread = threading.Thread(target=self.cart_progressbar,
|
||||
# args=(btn,))
|
||||
# thread.start()
|
||||
thread = threading.Thread(target=self.cart_progressbar,
|
||||
args=(btn,))
|
||||
thread.start()
|
||||
else:
|
||||
colour = Config.COLOUR_CART_ERROR
|
||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||
@ -260,7 +264,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
ms = 0
|
||||
btn.pgb.setMaximum(btn.duration)
|
||||
while ms <= btn.duration:
|
||||
btn.pgb.setValue(ms)
|
||||
btn.progress.emit(ms)
|
||||
ms += 100
|
||||
sleep(0.1)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user