Carts: tidy up code

This commit is contained in:
Keith Edmunds 2022-10-21 22:54:50 +01:00
parent 1899aac9ae
commit f42261277e
2 changed files with 25 additions and 24 deletions

View File

@ -56,7 +56,7 @@ class Config(object):
FADE_TIME = 3000
INFO_TAB_TITLE_LENGTH = 15
LAST_PLAYED_TODAY_STRING = "Today"
LOG_LEVEL_STDERR = logging.DEBUG
LOG_LEVEL_STDERR = logging.ERROR
LOG_LEVEL_SYSLOG = logging.DEBUG
LOG_NAME = "musicmuster"
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')

View File

@ -61,7 +61,6 @@ class CartButton(QPushButton):
self.player = None
self.is_playing = False
self.clicked.connect(self.parent.cart_click)
self.setEnabled(True)
self.setMinimumSize(QSize(147, 61))
font = QFont()
@ -75,7 +74,9 @@ class CartButton(QPushButton):
f"path={self.path}, is_playing={self.is_playing}>"
)
def event(self, event):
def event(self, event: QEvent) -> bool:
"""Allow right click even when button is disabled"""
if event.type() == QEvent.MouseButtonRelease:
if event.button() == Qt.RightButton:
self.parent.cart_edit(self, event)
@ -129,7 +130,6 @@ class Window(QMainWindow, Ui_MainWindow):
self.statusbar.addWidget(self.txtSearch)
self.txtSearch.setHidden(True)
self.hide_played_tracks = False
self.carts = {}
self.visible_playlist_tab: Callable[[], PlaylistTab] = \
self.tabPlaylist.currentWidget
@ -140,6 +140,26 @@ class Window(QMainWindow, Ui_MainWindow):
self.timer.start(Config.TIMER_MS)
self.connect_signals_slots()
def cart_configure(self, cart: Carts, btn: CartButton) -> None:
"""Configure button with cart data"""
btn.setEnabled(False)
if cart.path:
if helpers.file_is_readable(cart.path):
colour = Config.COLOUR_CART_READY
btn.path = cart.path
btn.player = self.music.VLC.media_player_new(cart.path)
btn.player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
if cart.enabled:
btn.setEnabled(True)
else:
colour = Config.COLOUR_CART_ERROR
else:
colour = Config.COLOUR_CART_UNCONFIGURED
btn.setStyleSheet("background-color: " + colour + ";\n")
btn.setText(cart.name)
def cart_click(self) -> None:
"""Handle cart click"""
@ -196,32 +216,13 @@ class Window(QMainWindow, Ui_MainWindow):
name=f"Cart #{cart_number}")
btn = CartButton(self, cart)
btn.clicked.connect(self.cart_click)
# Insert button on left of cart space starting at
# location zero
self.horizontalLayout_Carts.insertWidget(cart.id - 1, btn)
# Configure button
self.cart_configure(cart, btn)
def cart_configure(self, cart: Carts, btn: CartButton) -> None:
"""Configure button with cart data"""
btn.setEnabled(False)
if cart.path:
if helpers.file_is_readable(cart.path):
colour = Config.COLOUR_CART_READY
btn.path = cart.path
btn.player = self.music.VLC.media_player_new(cart.path)
btn.player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
if cart.enabled:
btn.setEnabled(True)
else:
colour = Config.COLOUR_CART_ERROR
else:
colour = Config.COLOUR_CART_UNCONFIGURED
btn.setStyleSheet("background-color: " + colour + ";\n")
btn.setText(cart.name)
def cart_tick(self) -> None:
"""Cart clock actions"""