WIP: Carts
This commit is contained in:
parent
ef17b359e2
commit
a649fa8c59
@ -10,12 +10,14 @@ class Config(object):
|
||||
BITRATE_OK_THRESHOLD = 300
|
||||
CHECK_AUDACITY_AT_STARTUP = True
|
||||
CART_DIRECTORY = "/home/kae/radio/CartTracks"
|
||||
CARTS_COUNT = 10
|
||||
COLOUR_BITRATE_LOW = "#ffcdd2"
|
||||
COLOUR_BITRATE_MEDIUM = "#ffeb6f"
|
||||
COLOUR_BITRATE_OK = "#dcedc8"
|
||||
COLOUR_CART_ERROR = "#dc3545"
|
||||
COLOUR_CART_PLAYING = "#248f24"
|
||||
COLOUR_CART_READY = "#ffc107"
|
||||
COLOUR_CART_UNCONFIGURED = "#f2f2f2"
|
||||
COLOUR_CURRENT_HEADER = "#d4edda"
|
||||
COLOUR_CURRENT_PLAYLIST = "#7eca8f"
|
||||
COLOUR_CURRENT_TAB = "#248f24"
|
||||
|
||||
@ -63,12 +63,12 @@ class Carts(Base):
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<Carts(id={self.id}, cart={self.cart}, "
|
||||
f"<Carts(id={self.id}, cart={self.cart_number}, "
|
||||
f"name={self.name}, path={self.path}>"
|
||||
)
|
||||
|
||||
def __init__(self, session: Session, cart_number: int, name: str = None,
|
||||
duration: int = None, path: str = None,
|
||||
duration: int = None, path: str = None,
|
||||
enabled: bool = True) -> None:
|
||||
"""Create new cart"""
|
||||
|
||||
@ -82,18 +82,18 @@ class Carts(Base):
|
||||
session.commit()
|
||||
|
||||
@classmethod
|
||||
def enabled_carts(cls, session: Session) -> List["Carts"]:
|
||||
"""Return a list of all active carts"""
|
||||
def all_as_dict(cls, session: Session) -> dict:
|
||||
"""Return a dictionary of all carts keyed by cart number"""
|
||||
|
||||
return (
|
||||
result = (
|
||||
session.execute(
|
||||
select(Carts)
|
||||
.where(Carts.enabled.is_(True))
|
||||
.order_by(Carts.cart_number)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
return {a.id: a for a in result}
|
||||
|
||||
@classmethod
|
||||
def get_or_create(cls, session: Session, cart_number: int) -> "Carts":
|
||||
|
||||
@ -110,7 +110,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
pass
|
||||
|
||||
def cart_button(self, cart: Carts) -> QPushButton:
|
||||
"""Create a cart pushbutton"""
|
||||
"""Create a cart pushbutton and set it disabled"""
|
||||
|
||||
btn = QPushButton(self)
|
||||
btn.setEnabled(True)
|
||||
@ -121,6 +121,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
btn.setObjectName("cart_" + str(cart.cart_number))
|
||||
btn.setText(cart.name)
|
||||
btn.clicked.connect(self.cart_click)
|
||||
btn.setEnabled(False)
|
||||
# Insert button on left of cart space after existing buttons
|
||||
self.horizontalLayout_Carts.insertWidget(len(self.carts), btn)
|
||||
|
||||
@ -169,7 +170,15 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""Initialse carts data structures"""
|
||||
|
||||
with Session() as session:
|
||||
for cart in Carts.enabled_carts(session):
|
||||
carts_in_db = Carts.all_as_dict(session)
|
||||
# Number carts from 1 for humanity
|
||||
for cart_number in range(1, Config.CARTS_COUNT + 1):
|
||||
if cart_number in carts_in_db:
|
||||
cart = carts_in_db[cart_number]
|
||||
else:
|
||||
cart = Carts(session, cart_number,
|
||||
name=f"Cart #{cart_number}")
|
||||
|
||||
btn = self.cart_button(cart)
|
||||
|
||||
self.carts[btn] = {}
|
||||
@ -180,10 +189,15 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
player = self.music.VLC.media_player_new(cart.path)
|
||||
player.audio_set_volume(Config.VOLUME_VLC_DEFAULT)
|
||||
self.carts[btn]['player'] = player
|
||||
if helpers.file_is_readable(cart.path):
|
||||
colour = Config.COLOUR_CART_READY
|
||||
if cart.path:
|
||||
if helpers.file_is_readable(cart.path):
|
||||
colour = Config.COLOUR_CART_READY
|
||||
btn.setEnabled(True)
|
||||
else:
|
||||
colour = Config.COLOUR_CART_ERROR
|
||||
else:
|
||||
colour = Config.COLOUR_CART_ERROR
|
||||
colour = Config.COLOUR_CART_UNCONFIGURED
|
||||
|
||||
btn.setStyleSheet("background-color: " + colour + ";\n")
|
||||
|
||||
def cart_tick(self) -> None:
|
||||
|
||||
@ -865,7 +865,6 @@ padding-left: 8px;</string>
|
||||
<property name="title">
|
||||
<string>&Carts</string>
|
||||
</property>
|
||||
<addaction name="actionAdd_cart"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuPlaylist"/>
|
||||
@ -1158,7 +1157,7 @@ padding-left: 8px;</string>
|
||||
</action>
|
||||
<action name="actionAdd_cart">
|
||||
<property name="text">
|
||||
<string>Add &cart...</string>
|
||||
<string>Edit cart &1...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
||||
@ -530,7 +530,6 @@ class Ui_MainWindow(object):
|
||||
self.menuSearc_h.addAction(self.actionSelect_previous_track)
|
||||
self.menuHelp.addAction(self.action_About)
|
||||
self.menuHelp.addAction(self.actionDebug)
|
||||
self.menu_Carts.addAction(self.actionAdd_cart)
|
||||
self.menubar.addAction(self.menuFile.menuAction())
|
||||
self.menubar.addAction(self.menuPlaylist.menuAction())
|
||||
self.menubar.addAction(self.menuSearc_h.menuAction())
|
||||
@ -629,6 +628,6 @@ class Ui_MainWindow(object):
|
||||
self.actionSave_as_template.setText(_translate("MainWindow", "Save as template..."))
|
||||
self.actionNew_from_template.setText(_translate("MainWindow", "New from template..."))
|
||||
self.actionDebug.setText(_translate("MainWindow", "Debug"))
|
||||
self.actionAdd_cart.setText(_translate("MainWindow", "Add &cart..."))
|
||||
self.actionAdd_cart.setText(_translate("MainWindow", "Edit cart &1..."))
|
||||
from infotabs import InfoTabs
|
||||
import icons_rc
|
||||
|
||||
Loading…
Reference in New Issue
Block a user