Compare commits
No commits in common. "9ac2911a55970763327ac1d8a97e169cfcdbef52" and "a8c5a56c1a20946438efb553fec99b5574ecfd7b" have entirely different histories.
9ac2911a55
...
a8c5a56c1a
@ -30,10 +30,10 @@ else:
|
||||
|
||||
engine = create_engine(
|
||||
MYSQL_CONNECT,
|
||||
encoding="utf-8",
|
||||
echo=Config.DISPLAY_SQL,
|
||||
pool_pre_ping=True,
|
||||
future=True,
|
||||
connect_args={"charset": "utf8mb4"},
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -75,8 +75,8 @@ def log_uncaught_exceptions(_ex_cls, ex, tb):
|
||||
print("\033[1;31;47m")
|
||||
logging.critical(''.join(traceback.format_tb(tb)))
|
||||
print("\033[1;37;40m")
|
||||
# print(stackprinter.format(ex, show_vals="all", add_summary=True,
|
||||
# style="darkbg"))
|
||||
print(stackprinter.format(ex, show_vals="all", add_summary=True,
|
||||
style="darkbg"))
|
||||
if os.environ["MM_ENV"] == "PRODUCTION":
|
||||
msg = stackprinter.format(ex)
|
||||
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
|
||||
|
||||
175
app/models.py
175
app/models.py
@ -6,27 +6,27 @@ from config import Config
|
||||
from dbconfig import scoped_session
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List, Optional, Sequence
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
delete,
|
||||
Float,
|
||||
ForeignKey,
|
||||
func,
|
||||
Integer,
|
||||
select,
|
||||
String,
|
||||
update,
|
||||
)
|
||||
|
||||
from sqlalchemy.orm import (
|
||||
DeclarativeBase,
|
||||
declarative_base,
|
||||
joinedload,
|
||||
lazyload,
|
||||
Mapped,
|
||||
mapped_column,
|
||||
relationship,
|
||||
)
|
||||
from sqlalchemy.orm.exc import (
|
||||
@ -37,21 +37,19 @@ from sqlalchemy.exc import (
|
||||
)
|
||||
from log import log
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
# Database classes
|
||||
class Carts(Base):
|
||||
__tablename__ = "carts"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
cart_number: Mapped[int] = mapped_column(unique=True)
|
||||
name: Mapped[str] = mapped_column(String(256), index=True)
|
||||
duration: Mapped[int] = mapped_column(index=True)
|
||||
path: Mapped[str] = mapped_column(String(2048), index=False)
|
||||
enabled: Mapped[bool] = mapped_column(default=False)
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
cart_number: int = Column(Integer, nullable=False, unique=True)
|
||||
name = Column(String(256), index=True)
|
||||
duration = Column(Integer, index=True)
|
||||
path = Column(String(2048), index=False)
|
||||
enabled: bool = Column(Boolean, default=False, nullable=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
@ -83,13 +81,13 @@ class Carts(Base):
|
||||
class NoteColours(Base):
|
||||
__tablename__ = "notecolours"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
substring: Mapped[str] = mapped_column(String(256), index=False)
|
||||
colour: Mapped[str] = mapped_column(String(21), index=False)
|
||||
enabled: Mapped[bool] = mapped_column(default=True, index=True)
|
||||
is_regex: Mapped[bool] = mapped_column(default=False, index=False)
|
||||
is_casesensitive: Mapped[bool] = mapped_column(default=False, index=False)
|
||||
order: Mapped[Optional[int]] = mapped_column(index=True)
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
substring = Column(String(256), index=False)
|
||||
colour = Column(String(21), index=False)
|
||||
enabled = Column(Boolean, default=True, index=True)
|
||||
is_regex = Column(Boolean, default=False, index=False)
|
||||
is_casesensitive = Column(Boolean, default=False, index=False)
|
||||
order = Column(Integer, index=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
@ -136,10 +134,10 @@ class NoteColours(Base):
|
||||
class Playdates(Base):
|
||||
__tablename__ = "playdates"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
lastplayed: Mapped[datetime] = mapped_column(index=True)
|
||||
track_id: Mapped[int] = mapped_column(ForeignKey("tracks.id"))
|
||||
track: Mapped["Tracks"] = relationship("Tracks", back_populates="playdates")
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
lastplayed: datetime = Column(DateTime, index=True)
|
||||
track_id = Column(Integer, ForeignKey("tracks.id"))
|
||||
track: "Tracks" = relationship("Tracks", back_populates="playdates")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
@ -172,7 +170,7 @@ class Playdates(Base):
|
||||
return Config.EPOCH
|
||||
|
||||
@staticmethod
|
||||
def played_after(session: scoped_session, since: datetime) -> Sequence["Playdates"]:
|
||||
def played_after(session: scoped_session, since: datetime) -> List["Playdates"]:
|
||||
"""Return a list of Playdates objects since passed time"""
|
||||
|
||||
return (
|
||||
@ -193,13 +191,16 @@ class Playlists(Base):
|
||||
|
||||
__tablename__ = "playlists"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(32), unique=True)
|
||||
last_used: Mapped[Optional[datetime]] = mapped_column(DateTime, default=None)
|
||||
tab: Mapped[Optional[int]] = mapped_column(default=None, unique=True)
|
||||
is_template: Mapped[bool] = mapped_column(default=False)
|
||||
deleted: Mapped[bool] = mapped_column(default=False)
|
||||
rows: Mapped[List["PlaylistRows"]] = relationship(
|
||||
id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
|
||||
name: str = Column(String(32), nullable=False, unique=True)
|
||||
last_used = Column(DateTime, default=None, nullable=True)
|
||||
tab = Column(Integer, default=None, nullable=True, unique=True)
|
||||
# TODO sort_column is unused
|
||||
sort_column = Column(Integer, default=None, nullable=True, unique=False)
|
||||
is_template: bool = Column(Boolean, default=False, nullable=False)
|
||||
query = Column(String(256), default=None, nullable=True, unique=False)
|
||||
deleted: bool = Column(Boolean, default=False, nullable=False)
|
||||
rows: List["PlaylistRows"] = relationship(
|
||||
"PlaylistRows",
|
||||
back_populates="playlist",
|
||||
cascade="all, delete-orphan",
|
||||
@ -256,7 +257,7 @@ class Playlists(Base):
|
||||
session.flush()
|
||||
|
||||
@classmethod
|
||||
def get_all(cls, session: scoped_session) -> Sequence["Playlists"]:
|
||||
def get_all(cls, session: scoped_session) -> List["Playlists"]:
|
||||
"""Returns a list of all playlists ordered by last use"""
|
||||
|
||||
return (
|
||||
@ -270,7 +271,7 @@ class Playlists(Base):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_all_templates(cls, session: scoped_session) -> Sequence["Playlists"]:
|
||||
def get_all_templates(cls, session: scoped_session) -> List["Playlists"]:
|
||||
"""Returns a list of all templates ordered by name"""
|
||||
|
||||
return (
|
||||
@ -282,7 +283,7 @@ class Playlists(Base):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_closed(cls, session: scoped_session) -> Sequence["Playlists"]:
|
||||
def get_closed(cls, session: scoped_session) -> List["Playlists"]:
|
||||
"""Returns a list of all closed playlists ordered by last use"""
|
||||
|
||||
return (
|
||||
@ -300,7 +301,7 @@ class Playlists(Base):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_open(cls, session: scoped_session) -> Sequence[Optional["Playlists"]]:
|
||||
def get_open(cls, session: scoped_session) -> List[Optional["Playlists"]]:
|
||||
"""
|
||||
Return a list of loaded playlists ordered by tab order.
|
||||
"""
|
||||
@ -358,17 +359,14 @@ class Playlists(Base):
|
||||
class PlaylistRows(Base):
|
||||
__tablename__ = "playlist_rows"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
plr_rownum: Mapped[int]
|
||||
note: Mapped[str] = mapped_column(String(2048), index=False, default="", nullable=False)
|
||||
playlist_id: Mapped[int] = mapped_column(ForeignKey("playlists.id"))
|
||||
playlist: Mapped[Playlists] = relationship(back_populates="rows")
|
||||
track_id: Mapped[Optional[int]] = mapped_column(ForeignKey("tracks.id"))
|
||||
track: Mapped["Tracks"] = relationship(
|
||||
"Tracks",
|
||||
back_populates="playlistrows",
|
||||
)
|
||||
played: Mapped[bool] = mapped_column(Boolean, nullable=False, index=False, default=False)
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
plr_rownum: int = Column(Integer, nullable=False)
|
||||
note: str = Column(String(2048), index=False, default="", nullable=False)
|
||||
playlist_id: int = Column(Integer, ForeignKey("playlists.id"), nullable=False)
|
||||
playlist: Playlists = relationship(Playlists, back_populates="rows")
|
||||
track_id = Column(Integer, ForeignKey("tracks.id"), nullable=True)
|
||||
track: "Tracks" = relationship("Tracks", back_populates="playlistrows")
|
||||
played: bool = Column(Boolean, nullable=False, index=False, default=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
@ -435,23 +433,6 @@ class PlaylistRows(Base):
|
||||
)
|
||||
session.flush()
|
||||
|
||||
@classmethod
|
||||
def deep_rows(cls, session: scoped_session, playlist_id: int) -> Sequence["PlaylistRows"]:
|
||||
"""
|
||||
Return a list of playlist rows that include full track and lastplayed data for
|
||||
given playlist_id., Sequence
|
||||
"""
|
||||
|
||||
stmt = (
|
||||
select(PlaylistRows)
|
||||
.options(joinedload(cls.track))
|
||||
.where(PlaylistRows.playlist_id == playlist_id)
|
||||
.order_by(PlaylistRows.plr_rownum)
|
||||
# .options(joinedload(Tracks.playdates))
|
||||
)
|
||||
|
||||
return session.scalars(stmt).unique().all()
|
||||
|
||||
@staticmethod
|
||||
def fixup_rownumbers(session: scoped_session, playlist_id: int) -> None:
|
||||
"""
|
||||
@ -477,7 +458,7 @@ class PlaylistRows(Base):
|
||||
@classmethod
|
||||
def plrids_to_plrs(
|
||||
cls, session: scoped_session, playlist_id: int, plr_ids: List[int]
|
||||
) -> Sequence["PlaylistRows"]:
|
||||
) -> List["PlaylistRows"]:
|
||||
"""
|
||||
Take a list of PlaylistRows ids and return a list of corresponding
|
||||
PlaylistRows objects
|
||||
@ -523,7 +504,7 @@ class PlaylistRows(Base):
|
||||
@classmethod
|
||||
def get_played_rows(
|
||||
cls, session: scoped_session, playlist_id: int
|
||||
) -> Sequence["PlaylistRows"]:
|
||||
) -> List["PlaylistRows"]:
|
||||
"""
|
||||
For passed playlist, return a list of rows that
|
||||
have been played.
|
||||
@ -548,7 +529,7 @@ class PlaylistRows(Base):
|
||||
playlist_id: int,
|
||||
from_row: Optional[int] = None,
|
||||
to_row: Optional[int] = None,
|
||||
) -> Sequence["PlaylistRows"]:
|
||||
) -> List["PlaylistRows"]:
|
||||
"""
|
||||
For passed playlist, return a list of rows that
|
||||
contain tracks
|
||||
@ -569,7 +550,7 @@ class PlaylistRows(Base):
|
||||
@classmethod
|
||||
def get_unplayed_rows(
|
||||
cls, session: scoped_session, playlist_id: int
|
||||
) -> Sequence["PlaylistRows"]:
|
||||
) -> List["PlaylistRows"]:
|
||||
"""
|
||||
For passed playlist, return a list of playlist rows that
|
||||
have not been played.
|
||||
@ -615,11 +596,11 @@ class Settings(Base):
|
||||
|
||||
__tablename__ = "settings"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(64), unique=True)
|
||||
f_datetime: Mapped[Optional[datetime]] = mapped_column(default=None)
|
||||
f_int: Mapped[Optional[int]] = mapped_column(default=None)
|
||||
f_string: Mapped[Optional[str]] = mapped_column(String(128), default=None)
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name: str = Column(String(64), nullable=False, unique=True)
|
||||
f_datetime = Column(DateTime, default=None, nullable=True)
|
||||
f_int: int = Column(Integer, default=None, nullable=True)
|
||||
f_string = Column(String(128), default=None, nullable=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
value = self.f_datetime or self.f_int or self.f_string
|
||||
@ -630,20 +611,6 @@ class Settings(Base):
|
||||
session.add(self)
|
||||
session.flush()
|
||||
|
||||
@classmethod
|
||||
def all_as_dict(cls, session):
|
||||
"""
|
||||
Return all setting in a dictionary keyed by name
|
||||
"""
|
||||
|
||||
result = {}
|
||||
|
||||
settings = session.execute(select(cls)).scalars().all()
|
||||
for setting in settings:
|
||||
result[setting.name] = setting
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_int_settings(cls, session: scoped_session, name: str) -> "Settings":
|
||||
"""Get setting for an integer or return new setting record"""
|
||||
@ -664,25 +631,21 @@ class Settings(Base):
|
||||
class Tracks(Base):
|
||||
__tablename__ = "tracks"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
title: Mapped[str] = mapped_column(String(256), index=True)
|
||||
artist: Mapped[str] = mapped_column(String(256), index=True)
|
||||
duration: Mapped[int] = mapped_column(index=True)
|
||||
start_gap: Mapped[int] = mapped_column(index=False)
|
||||
fade_at: Mapped[int] = mapped_column(index=False)
|
||||
silence_at: Mapped[int] = mapped_column(index=False)
|
||||
path: Mapped[str] = mapped_column(String(2048), index=False, unique=True)
|
||||
mtime: Mapped[float] = mapped_column(index=True)
|
||||
bitrate: Mapped[Optional[int]] = mapped_column(default=None)
|
||||
playlistrows: Mapped[List[PlaylistRows]] = relationship(
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(String(256), index=True)
|
||||
artist = Column(String(256), index=True)
|
||||
duration = Column(Integer, index=True)
|
||||
start_gap = Column(Integer, index=False)
|
||||
fade_at = Column(Integer, index=False)
|
||||
silence_at = Column(Integer, index=False)
|
||||
path: str = Column(String(2048), index=False, nullable=False, unique=True)
|
||||
mtime = Column(Float, index=True)
|
||||
bitrate = Column(Integer, nullable=True, default=None)
|
||||
playlistrows: List[PlaylistRows] = relationship(
|
||||
"PlaylistRows", back_populates="track"
|
||||
)
|
||||
playlists = association_proxy("playlistrows", "playlist")
|
||||
playdates: Mapped[List[Playdates]] = relationship(
|
||||
"Playdates",
|
||||
back_populates="track",
|
||||
lazy="joined",
|
||||
)
|
||||
playdates: List[Playdates] = relationship("Playdates", back_populates="track")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
@ -744,7 +707,7 @@ class Tracks(Base):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def search_artists(cls, session: scoped_session, text: str) -> Sequence["Tracks"]:
|
||||
def search_artists(cls, session: scoped_session, text: str) -> List["Tracks"]:
|
||||
"""
|
||||
Search case-insenstively for artists containing str
|
||||
|
||||
@ -766,7 +729,7 @@ class Tracks(Base):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def search_titles(cls, session: scoped_session, text: str) -> Sequence["Tracks"]:
|
||||
def search_titles(cls, session: scoped_session, text: str) -> List["Tracks"]:
|
||||
"""
|
||||
Search case-insenstively for titles containing str
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ from typing import (
|
||||
cast,
|
||||
List,
|
||||
Optional,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from PyQt6.QtCore import (
|
||||
@ -34,7 +33,6 @@ from PyQt6.QtCore import (
|
||||
QTimer,
|
||||
)
|
||||
from PyQt6.QtGui import (
|
||||
QCloseEvent,
|
||||
QColor,
|
||||
QFont,
|
||||
QMouseEvent,
|
||||
@ -121,12 +119,9 @@ class CartButton(QPushButton):
|
||||
f"path={self.path}, is_playing={self.is_playing}>"
|
||||
)
|
||||
|
||||
def event(self, event: Optional[QEvent]) -> bool:
|
||||
def event(self, event: QEvent) -> bool:
|
||||
"""Allow right click even when button is disabled"""
|
||||
|
||||
if not event:
|
||||
return False
|
||||
|
||||
if event.type() == QEvent.Type.MouseButtonRelease:
|
||||
mouse_event = cast(QMouseEvent, event)
|
||||
if mouse_event.button() == Qt.MouseButton.RightButton:
|
||||
@ -135,7 +130,7 @@ class CartButton(QPushButton):
|
||||
|
||||
return super().event(event)
|
||||
|
||||
def resizeEvent(self, event: Optional[QResizeEvent]) -> None:
|
||||
def resizeEvent(self, event: QResizeEvent) -> None:
|
||||
"""Resize progess bar when button size changes"""
|
||||
|
||||
self.pgb.setGeometry(0, 0, self.width(), 10)
|
||||
@ -539,12 +534,9 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# Clear the search bar
|
||||
self.search_playlist_clear()
|
||||
|
||||
def closeEvent(self, event: Optional[QCloseEvent]) -> None:
|
||||
def closeEvent(self, event: QEvent) -> None:
|
||||
"""Handle attempt to close main window"""
|
||||
|
||||
if not event:
|
||||
return
|
||||
|
||||
# Don't allow window to close when a track is playing
|
||||
if self.playing:
|
||||
event.ignore()
|
||||
@ -553,20 +545,19 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
)
|
||||
else:
|
||||
with Session() as session:
|
||||
settings = Settings.all_as_dict(session)
|
||||
record = settings["mainwindow_height"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_height")
|
||||
if record.f_int != self.height():
|
||||
record.update(session, {"f_int": self.height()})
|
||||
|
||||
record = settings["mainwindow_width"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_width")
|
||||
if record.f_int != self.width():
|
||||
record.update(session, {"f_int": self.width()})
|
||||
|
||||
record = settings["mainwindow_x"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_x")
|
||||
if record.f_int != self.x():
|
||||
record.update(session, {"f_int": self.x()})
|
||||
|
||||
record = settings["mainwindow_y"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_y")
|
||||
if record.f_int != self.y():
|
||||
record.update(session, {"f_int": self.y()})
|
||||
|
||||
@ -575,16 +566,16 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
assert len(splitter_sizes) == 2
|
||||
splitter_top, splitter_bottom = splitter_sizes
|
||||
|
||||
record = settings["splitter_top"]
|
||||
record = Settings.get_int_settings(session, "splitter_top")
|
||||
if record.f_int != splitter_top:
|
||||
record.update(session, {"f_int": splitter_top})
|
||||
|
||||
record = settings["splitter_bottom"]
|
||||
record = Settings.get_int_settings(session, "splitter_bottom")
|
||||
if record.f_int != splitter_bottom:
|
||||
record.update(session, {"f_int": splitter_bottom})
|
||||
|
||||
# Save current tab
|
||||
record = settings["active_tab"]
|
||||
record = Settings.get_int_settings(session, "active_tab")
|
||||
record.update(session, {"f_int": self.tabPlaylist.currentIndex()})
|
||||
|
||||
event.accept()
|
||||
@ -1046,11 +1037,11 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
_ = self.create_playlist_tab(session, playlist)
|
||||
# Set active tab
|
||||
record = Settings.get_int_settings(session, "active_tab")
|
||||
if record.f_int and record.f_int >= 0:
|
||||
if record and record.f_int >= 0:
|
||||
self.tabPlaylist.setCurrentIndex(record.f_int)
|
||||
|
||||
def move_playlist_rows(
|
||||
self, session: scoped_session, playlistrows: Sequence[PlaylistRows]
|
||||
self, session: scoped_session, playlistrows: List[PlaylistRows]
|
||||
) -> None:
|
||||
"""
|
||||
Move passed playlist rows to another playlist
|
||||
@ -1113,7 +1104,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
visible_tab.save_playlist(session)
|
||||
|
||||
# Disable sort undo
|
||||
self.sort_undo = []
|
||||
self.sort_undo = None
|
||||
|
||||
# Update destination playlist_tab if visible (if not visible, it
|
||||
# will be re-populated when it is opened)
|
||||
@ -1493,19 +1484,18 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""Set size of window from database"""
|
||||
|
||||
with Session() as session:
|
||||
settings = Settings.all_as_dict(session)
|
||||
record = settings["mainwindow_x"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_x")
|
||||
x = record.f_int or 1
|
||||
record = settings["mainwindow_y"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_y")
|
||||
y = record.f_int or 1
|
||||
record = settings["mainwindow_width"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_width")
|
||||
width = record.f_int or 1599
|
||||
record = settings["mainwindow_height"]
|
||||
record = Settings.get_int_settings(session, "mainwindow_height")
|
||||
height = record.f_int or 981
|
||||
self.setGeometry(x, y, width, height)
|
||||
record = settings["splitter_top"]
|
||||
record = Settings.get_int_settings(session, "splitter_top")
|
||||
splitter_top = record.f_int or 256
|
||||
record = settings["splitter_bottom"]
|
||||
record = Settings.get_int_settings(session, "splitter_bottom")
|
||||
splitter_bottom = record.f_int or 256
|
||||
self.splitter.setSizes([splitter_top, splitter_bottom])
|
||||
return
|
||||
@ -2171,6 +2161,6 @@ if __name__ == "__main__":
|
||||
msg,
|
||||
)
|
||||
|
||||
# print("\033[1;31;47mUnhandled exception starts")
|
||||
# stackprinter.show(style="darkbg")
|
||||
# print("Unhandled exception ends\033[1;37;40m")
|
||||
print("\033[1;31;47mUnhandled exception starts")
|
||||
stackprinter.show(style="darkbg")
|
||||
print("Unhandled exception ends\033[1;37;40m")
|
||||
|
||||
@ -164,19 +164,16 @@ class PlaylistTab(QTableWidget):
|
||||
self.setVerticalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel)
|
||||
self.setRowCount(0)
|
||||
self.setColumnCount(len(columns))
|
||||
self.v_header = self.verticalHeader()
|
||||
self.v_header.setMinimumSectionSize(Config.MINIMUM_ROW_HEIGHT)
|
||||
self.horizontalHeader().setStretchLastSection(True)
|
||||
|
||||
# Header row
|
||||
self.h_header = self.horizontalHeader()
|
||||
for idx in [a for a in range(len(columns))]:
|
||||
item = QTableWidgetItem()
|
||||
self.setHorizontalHeaderItem(idx, item)
|
||||
if self.h_header:
|
||||
self.h_header.setStretchLastSection(True)
|
||||
self.h_header.setMinimumSectionSize(0)
|
||||
self.horizontalHeader().setMinimumSectionSize(0)
|
||||
# Set column headings sorted by idx
|
||||
self.v_header = self.verticalHeader()
|
||||
if self.v_header:
|
||||
self.v_header.setMinimumSectionSize(Config.MINIMUM_ROW_HEIGHT)
|
||||
self.setHorizontalHeaderLabels(
|
||||
[
|
||||
a.heading
|
||||
@ -218,16 +215,13 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
# ########## Events other than cell editing ##########
|
||||
|
||||
def dropEvent(self, event: Optional[QDropEvent]) -> None:
|
||||
def dropEvent(self, event: QDropEvent) -> None:
|
||||
"""
|
||||
Handle drag/drop of rows
|
||||
|
||||
https://stackoverflow.com/questions/26227885/drag-and-drop-rows-within-qtablewidget
|
||||
"""
|
||||
|
||||
if not event:
|
||||
return
|
||||
|
||||
if not event.source() == self:
|
||||
return # We don't accept external drops
|
||||
|
||||
@ -273,7 +267,7 @@ class PlaylistTab(QTableWidget):
|
||||
# Reset drag mode to allow row selection by dragging
|
||||
self.setDragEnabled(False)
|
||||
# Disable sort undo
|
||||
self.sort_undo = []
|
||||
self.sort_undo = None
|
||||
|
||||
with Session() as session:
|
||||
self.save_playlist(session)
|
||||
@ -619,6 +613,8 @@ class PlaylistTab(QTableWidget):
|
||||
if played:
|
||||
bold = False
|
||||
_ = self._set_row_userdata(row_number, self.PLAYED, True)
|
||||
if plr.note is None:
|
||||
plr.note = ""
|
||||
self._set_row_note_text(session, row_number, plr.note)
|
||||
else:
|
||||
# This is a section header so it must have note text
|
||||
@ -749,7 +745,7 @@ class PlaylistTab(QTableWidget):
|
||||
stackprinter.format(),
|
||||
)
|
||||
print("playlists:play_started:current_row is None")
|
||||
# stackprinter.show(add_summary=True, style="darkbg")
|
||||
stackprinter.show(add_summary=True, style="darkbg")
|
||||
return
|
||||
|
||||
# Mark current row as played
|
||||
@ -801,10 +797,10 @@ class PlaylistTab(QTableWidget):
|
||||
stackprinter.format(),
|
||||
)
|
||||
print("playlists:populate_display:no playlist")
|
||||
# stackprinter.show(add_summary=True, style="darkbg")
|
||||
stackprinter.show(add_summary=True, style="darkbg")
|
||||
return
|
||||
|
||||
for plr in PlaylistRows.deep_rows(session, playlist_id):
|
||||
for plr in playlist.rows:
|
||||
self.insert_row(
|
||||
session,
|
||||
plr,
|
||||
@ -821,6 +817,7 @@ class PlaylistTab(QTableWidget):
|
||||
# Set widths
|
||||
self._set_column_widths(session)
|
||||
|
||||
self.save_playlist(session)
|
||||
# Queue up time calculations to take place after UI has
|
||||
# updated
|
||||
self._update_start_end_times(session)
|
||||
@ -1109,7 +1106,7 @@ class PlaylistTab(QTableWidget):
|
||||
)
|
||||
if sort_menu:
|
||||
sort_menu.setEnabled(self._sortable())
|
||||
self._add_context_menu("Undo sort", self._sort_undo, not bool(self.sort_undo))
|
||||
self._add_context_menu("Undo sort", self._sort_undo, self.sort_undo is None)
|
||||
|
||||
# Build submenu
|
||||
|
||||
@ -1146,7 +1143,6 @@ class PlaylistTab(QTableWidget):
|
||||
"""
|
||||
|
||||
with Session() as session:
|
||||
settings = Settings.all_as_dict(session)
|
||||
for column_name, data in columns.items():
|
||||
idx = data.idx
|
||||
if idx == len(columns) - 1:
|
||||
@ -1155,7 +1151,7 @@ class PlaylistTab(QTableWidget):
|
||||
continue
|
||||
width = self.columnWidth(idx)
|
||||
attribute_name = f"playlist_{column_name}_col_width"
|
||||
record = settings[attribute_name]
|
||||
record = Settings.get_int_settings(session, attribute_name)
|
||||
if record.f_int != self.columnWidth(idx):
|
||||
record.update(session, {"f_int": width})
|
||||
|
||||
@ -1900,8 +1896,6 @@ class PlaylistTab(QTableWidget):
|
||||
def _set_column_widths(self, session: scoped_session) -> None:
|
||||
"""Column widths from settings"""
|
||||
|
||||
settings = Settings.all_as_dict(session)
|
||||
|
||||
for column_name, data in columns.items():
|
||||
idx = data.idx
|
||||
if idx == len(columns) - 1:
|
||||
@ -1909,7 +1903,7 @@ class PlaylistTab(QTableWidget):
|
||||
self.setColumnWidth(idx, 0)
|
||||
continue
|
||||
attr_name = f"playlist_{column_name}_col_width"
|
||||
record = settings[attr_name]
|
||||
record: Settings = Settings.get_int_settings(session, attr_name)
|
||||
if record and record.f_int >= 0:
|
||||
self.setColumnWidth(idx, record.f_int)
|
||||
else:
|
||||
@ -2086,10 +2080,8 @@ class PlaylistTab(QTableWidget):
|
||||
"playlists:_set_row_header_text() called on track row",
|
||||
stackprinter.format(),
|
||||
)
|
||||
print(
|
||||
f"playists:_set_row_header_text() called on track row ({row_number=}, {text=}"
|
||||
)
|
||||
# stackprinter.show(add_summary=True, style="darkbg")
|
||||
print("playists:_set_row_header_text() called on track row")
|
||||
stackprinter.show(add_summary=True, style="darkbg")
|
||||
return
|
||||
|
||||
# Set text
|
||||
@ -2128,8 +2120,8 @@ class PlaylistTab(QTableWidget):
|
||||
"playlists:_set_row_note_colour() on header row",
|
||||
stackprinter.format(),
|
||||
)
|
||||
# stackprinter.show(add_summary=True, style="darkbg")
|
||||
print(f"playists:_set_row_note_colour() called on track row ({row_number=}")
|
||||
print("playists:_set_row_note_colour() called on header row")
|
||||
stackprinter.show(add_summary=True, style="darkbg")
|
||||
return
|
||||
|
||||
# Set colour
|
||||
@ -2154,10 +2146,8 @@ class PlaylistTab(QTableWidget):
|
||||
"playlists:_set_row_note_text() called on header row",
|
||||
stackprinter.format(),
|
||||
)
|
||||
print(
|
||||
f"playists:_set_row_note_text() called on header row ({row_number=}, {text=}"
|
||||
)
|
||||
# stackprinter.show(add_summary=True, style="darkbg")
|
||||
print("playists:_set_row_note_text() called on header row")
|
||||
stackprinter.show(add_summary=True, style="darkbg")
|
||||
return
|
||||
|
||||
# Set text
|
||||
@ -2398,11 +2388,9 @@ class PlaylistTab(QTableWidget):
|
||||
_ = self._set_row_bitrate(row, track.bitrate)
|
||||
_ = self._set_row_duration(row, track.duration)
|
||||
_ = self._set_row_end_time(row, None)
|
||||
if track.playdates:
|
||||
last_play = max([a.lastplayed for a in track.playdates])
|
||||
else:
|
||||
last_play = Config.EPOCH
|
||||
_ = self._set_row_last_played_time(row, last_play)
|
||||
_ = self._set_row_last_played_time(
|
||||
row, Playdates.last_played(session, track.id)
|
||||
)
|
||||
_ = self._set_row_start_gap(row, track.start_gap)
|
||||
_ = self._set_row_start_time(row, None)
|
||||
_ = self._set_row_title(row, track.title)
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
# Form implementation generated from reading ui file 'dlg_Cart.ui'
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'app/ui/dlg_Cart.ui'
|
||||
#
|
||||
# Created by: PyQt6 UI code generator 6.5.3
|
||||
# Created by: PyQt5 UI code generator 5.15.6
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_DialogCartEdit(object):
|
||||
@ -15,43 +17,43 @@ class Ui_DialogCartEdit(object):
|
||||
DialogCartEdit.resize(564, 148)
|
||||
self.gridLayout = QtWidgets.QGridLayout(DialogCartEdit)
|
||||
self.gridLayout.setObjectName("gridLayout")
|
||||
self.label = QtWidgets.QLabel(parent=DialogCartEdit)
|
||||
self.label = QtWidgets.QLabel(DialogCartEdit)
|
||||
self.label.setMaximumSize(QtCore.QSize(56, 16777215))
|
||||
self.label.setObjectName("label")
|
||||
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
|
||||
self.lineEditName = QtWidgets.QLineEdit(parent=DialogCartEdit)
|
||||
self.lineEditName = QtWidgets.QLineEdit(DialogCartEdit)
|
||||
self.lineEditName.setInputMask("")
|
||||
self.lineEditName.setObjectName("lineEditName")
|
||||
self.gridLayout.addWidget(self.lineEditName, 0, 1, 1, 2)
|
||||
self.chkEnabled = QtWidgets.QCheckBox(parent=DialogCartEdit)
|
||||
self.chkEnabled = QtWidgets.QCheckBox(DialogCartEdit)
|
||||
self.chkEnabled.setObjectName("chkEnabled")
|
||||
self.gridLayout.addWidget(self.chkEnabled, 0, 3, 1, 1)
|
||||
self.label_2 = QtWidgets.QLabel(parent=DialogCartEdit)
|
||||
self.label_2 = QtWidgets.QLabel(DialogCartEdit)
|
||||
self.label_2.setMaximumSize(QtCore.QSize(56, 16777215))
|
||||
self.label_2.setObjectName("label_2")
|
||||
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
|
||||
self.lblPath = QtWidgets.QLabel(parent=DialogCartEdit)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
|
||||
self.lblPath = QtWidgets.QLabel(DialogCartEdit)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.lblPath.sizePolicy().hasHeightForWidth())
|
||||
self.lblPath.setSizePolicy(sizePolicy)
|
||||
self.lblPath.setMinimumSize(QtCore.QSize(301, 41))
|
||||
self.lblPath.setText("")
|
||||
self.lblPath.setTextFormat(QtCore.Qt.TextFormat.PlainText)
|
||||
self.lblPath.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeading|QtCore.Qt.AlignmentFlag.AlignLeft|QtCore.Qt.AlignmentFlag.AlignTop)
|
||||
self.lblPath.setTextFormat(QtCore.Qt.PlainText)
|
||||
self.lblPath.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
|
||||
self.lblPath.setWordWrap(True)
|
||||
self.lblPath.setObjectName("lblPath")
|
||||
self.gridLayout.addWidget(self.lblPath, 1, 1, 1, 1)
|
||||
self.btnFile = QtWidgets.QPushButton(parent=DialogCartEdit)
|
||||
self.btnFile = QtWidgets.QPushButton(DialogCartEdit)
|
||||
self.btnFile.setMaximumSize(QtCore.QSize(31, 16777215))
|
||||
self.btnFile.setObjectName("btnFile")
|
||||
self.gridLayout.addWidget(self.btnFile, 1, 3, 1, 1)
|
||||
spacerItem = QtWidgets.QSpacerItem(116, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||
spacerItem = QtWidgets.QSpacerItem(116, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
||||
self.gridLayout.addItem(spacerItem, 2, 1, 1, 1)
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(parent=DialogCartEdit)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(DialogCartEdit)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
|
||||
self.buttonBox.setObjectName("buttonBox")
|
||||
self.gridLayout.addWidget(self.buttonBox, 2, 2, 1, 2)
|
||||
self.label.setBuddy(self.lineEditName)
|
||||
|
||||
@ -1,34 +1,10 @@
|
||||
# Form implementation generated from reading ui file 'dlg_SelectPlaylist.ui'
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'ui/playlist.ui'
|
||||
#
|
||||
# Created by: PyQt6 UI code generator 6.5.3
|
||||
# Created by: PyQt5 UI code generator 5.15.4
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_dlgSelectPlaylist(object):
|
||||
def setupUi(self, dlgSelectPlaylist):
|
||||
dlgSelectPlaylist.setObjectName("dlgSelectPlaylist")
|
||||
dlgSelectPlaylist.resize(276, 150)
|
||||
self.verticalLayout = QtWidgets.QVBoxLayout(dlgSelectPlaylist)
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
self.lstPlaylists = QtWidgets.QListWidget(parent=dlgSelectPlaylist)
|
||||
self.lstPlaylists.setObjectName("lstPlaylists")
|
||||
self.verticalLayout.addWidget(self.lstPlaylists)
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(parent=dlgSelectPlaylist)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||
self.buttonBox.setObjectName("buttonBox")
|
||||
self.verticalLayout.addWidget(self.buttonBox)
|
||||
|
||||
self.retranslateUi(dlgSelectPlaylist)
|
||||
self.buttonBox.accepted.connect(dlgSelectPlaylist.accept) # type: ignore
|
||||
self.buttonBox.rejected.connect(dlgSelectPlaylist.reject) # type: ignore
|
||||
QtCore.QMetaObject.connectSlotsByName(dlgSelectPlaylist)
|
||||
|
||||
def retranslateUi(self, dlgSelectPlaylist):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
dlgSelectPlaylist.setWindowTitle(_translate("dlgSelectPlaylist", "Dialog"))
|
||||
|
||||
@ -1,72 +0,0 @@
|
||||
"""Migrate SQLA 2 and remove redundant columns
|
||||
|
||||
Revision ID: 3a53a9fb26ab
|
||||
Revises: 07dcbe6c4f0e
|
||||
Create Date: 2023-10-15 09:39:16.449419
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3a53a9fb26ab'
|
||||
down_revision = '07dcbe6c4f0e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('playlists', 'query')
|
||||
op.drop_column('playlists', 'sort_column')
|
||||
op.alter_column('tracks', 'title',
|
||||
existing_type=mysql.VARCHAR(length=256),
|
||||
nullable=False)
|
||||
op.alter_column('tracks', 'artist',
|
||||
existing_type=mysql.VARCHAR(length=256),
|
||||
nullable=False)
|
||||
op.alter_column('tracks', 'duration',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=False)
|
||||
op.alter_column('tracks', 'start_gap',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=False)
|
||||
op.alter_column('tracks', 'fade_at',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=False)
|
||||
op.alter_column('tracks', 'silence_at',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=False)
|
||||
op.alter_column('tracks', 'mtime',
|
||||
existing_type=mysql.FLOAT(),
|
||||
nullable=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('tracks', 'mtime',
|
||||
existing_type=mysql.FLOAT(),
|
||||
nullable=True)
|
||||
op.alter_column('tracks', 'silence_at',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=True)
|
||||
op.alter_column('tracks', 'fade_at',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=True)
|
||||
op.alter_column('tracks', 'start_gap',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=True)
|
||||
op.alter_column('tracks', 'duration',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
nullable=True)
|
||||
op.alter_column('tracks', 'artist',
|
||||
existing_type=mysql.VARCHAR(length=256),
|
||||
nullable=True)
|
||||
op.alter_column('tracks', 'title',
|
||||
existing_type=mysql.VARCHAR(length=256),
|
||||
nullable=True)
|
||||
op.add_column('playlists', sa.Column('sort_column', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
|
||||
op.add_column('playlists', sa.Column('query', mysql.VARCHAR(length=256), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
1279
poetry.lock
generated
1279
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -7,12 +7,13 @@ authors = ["Keith Edmunds <kae@midnighthax.com>"]
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
tinytag = "^1.7.0"
|
||||
SQLAlchemy = "^2.0.22"
|
||||
SQLAlchemy = "^1.4.31"
|
||||
python-vlc = "^3.0.12118"
|
||||
mysqlclient = "^2.1.0"
|
||||
mutagen = "^1.45.1"
|
||||
alembic = "^1.7.5"
|
||||
psutil = "^5.9.0"
|
||||
PyQtWebEngine = "^5.15.5"
|
||||
pydub = "^0.25.1"
|
||||
types-psutil = "^5.8.22"
|
||||
python-slugify = "^6.1.2"
|
||||
@ -34,6 +35,8 @@ pytest-qt = "^4.0.2"
|
||||
pydub-stubs = "^0.25.1"
|
||||
line-profiler = "^4.0.2"
|
||||
flakehell = "^0.9.0"
|
||||
sqlalchemy2-stubs = "^0.0.2-alpha.32"
|
||||
mypy = "^0.991"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pudb = "^2022.1.3"
|
||||
@ -41,7 +44,6 @@ sphinx = "^7.0.1"
|
||||
furo = "^2023.5.20"
|
||||
black = "^23.3.0"
|
||||
flakehell = "^0.9.0"
|
||||
mypy = "^1.6.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
@ -50,6 +52,7 @@ build-backend = "poetry.core.masonry.api"
|
||||
[tool.mypy]
|
||||
# mypy_path = "/home/kae/.cache/pypoetry/virtualenvs/musicmuster-oWgGw1IG-py3.9:/home/kae/git/musicmuster/app"
|
||||
mypy_path = "/home/kae/git/musicmuster/app"
|
||||
plugins = "sqlalchemy.ext.mypy.plugin"
|
||||
|
||||
[tool.vulture]
|
||||
exclude = ["migrations", "app/ui", "archive"]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user