From f42261277e59c22c0bb95873a9ff31d489641710 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 21 Oct 2022 22:54:50 +0100 Subject: [PATCH] Carts: tidy up code --- app/config.py | 2 +- app/musicmuster.py | 47 +++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/app/config.py b/app/config.py index cdcf179..8e4f0e1 100644 --- a/app/config.py +++ b/app/config.py @@ -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') diff --git a/app/musicmuster.py b/app/musicmuster.py index 24a6201..e4733ba 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -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"""