Carts: tidy up code
This commit is contained in:
parent
1899aac9ae
commit
f42261277e
@ -56,7 +56,7 @@ class Config(object):
|
|||||||
FADE_TIME = 3000
|
FADE_TIME = 3000
|
||||||
INFO_TAB_TITLE_LENGTH = 15
|
INFO_TAB_TITLE_LENGTH = 15
|
||||||
LAST_PLAYED_TODAY_STRING = "Today"
|
LAST_PLAYED_TODAY_STRING = "Today"
|
||||||
LOG_LEVEL_STDERR = logging.DEBUG
|
LOG_LEVEL_STDERR = logging.ERROR
|
||||||
LOG_LEVEL_SYSLOG = logging.DEBUG
|
LOG_LEVEL_SYSLOG = logging.DEBUG
|
||||||
LOG_NAME = "musicmuster"
|
LOG_NAME = "musicmuster"
|
||||||
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
|
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
|
||||||
|
|||||||
@ -61,7 +61,6 @@ class CartButton(QPushButton):
|
|||||||
self.player = None
|
self.player = None
|
||||||
self.is_playing = False
|
self.is_playing = False
|
||||||
|
|
||||||
self.clicked.connect(self.parent.cart_click)
|
|
||||||
self.setEnabled(True)
|
self.setEnabled(True)
|
||||||
self.setMinimumSize(QSize(147, 61))
|
self.setMinimumSize(QSize(147, 61))
|
||||||
font = QFont()
|
font = QFont()
|
||||||
@ -75,7 +74,9 @@ class CartButton(QPushButton):
|
|||||||
f"path={self.path}, is_playing={self.is_playing}>"
|
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.type() == QEvent.MouseButtonRelease:
|
||||||
if event.button() == Qt.RightButton:
|
if event.button() == Qt.RightButton:
|
||||||
self.parent.cart_edit(self, event)
|
self.parent.cart_edit(self, event)
|
||||||
@ -129,7 +130,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
self.statusbar.addWidget(self.txtSearch)
|
self.statusbar.addWidget(self.txtSearch)
|
||||||
self.txtSearch.setHidden(True)
|
self.txtSearch.setHidden(True)
|
||||||
self.hide_played_tracks = False
|
self.hide_played_tracks = False
|
||||||
self.carts = {}
|
|
||||||
|
|
||||||
self.visible_playlist_tab: Callable[[], PlaylistTab] = \
|
self.visible_playlist_tab: Callable[[], PlaylistTab] = \
|
||||||
self.tabPlaylist.currentWidget
|
self.tabPlaylist.currentWidget
|
||||||
@ -140,6 +140,26 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
self.timer.start(Config.TIMER_MS)
|
self.timer.start(Config.TIMER_MS)
|
||||||
self.connect_signals_slots()
|
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:
|
def cart_click(self) -> None:
|
||||||
"""Handle cart click"""
|
"""Handle cart click"""
|
||||||
|
|
||||||
@ -196,32 +216,13 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
name=f"Cart #{cart_number}")
|
name=f"Cart #{cart_number}")
|
||||||
|
|
||||||
btn = CartButton(self, cart)
|
btn = CartButton(self, cart)
|
||||||
|
btn.clicked.connect(self.cart_click)
|
||||||
# Insert button on left of cart space starting at
|
# Insert button on left of cart space starting at
|
||||||
# location zero
|
# location zero
|
||||||
self.horizontalLayout_Carts.insertWidget(cart.id - 1, btn)
|
self.horizontalLayout_Carts.insertWidget(cart.id - 1, btn)
|
||||||
# Configure button
|
# Configure button
|
||||||
self.cart_configure(cart, btn)
|
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:
|
def cart_tick(self) -> None:
|
||||||
"""Cart clock actions"""
|
"""Cart clock actions"""
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user