No more sessions in playlists!
Save/restore playlist column widths.
This commit is contained in:
parent
098ce7198e
commit
ed7ac0758c
@ -38,7 +38,6 @@ from audacity_controller import AudacityController
|
||||
from classes import (
|
||||
ApplicationError,
|
||||
Col,
|
||||
InsertTrack,
|
||||
MusicMusterSignals,
|
||||
PlaylistStyle,
|
||||
TrackInfo
|
||||
@ -55,6 +54,7 @@ from log import log, log_call
|
||||
from models import db, Settings
|
||||
from playlistrow import TrackSequence
|
||||
from playlistmodel import PlaylistModel, PlaylistProxyModel
|
||||
import repository
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from musicmuster import Window
|
||||
@ -686,11 +686,10 @@ class PlaylistTab(QTableView):
|
||||
# Resize rows if necessary
|
||||
self.resizeRowsToContents()
|
||||
|
||||
with db.Session() as session:
|
||||
attr_name = f"playlist_col_{column_number}_width"
|
||||
record = Settings.get_setting(session, attr_name)
|
||||
record.f_int = self.columnWidth(column_number)
|
||||
session.commit()
|
||||
# Save settings
|
||||
repository.set_setting(
|
||||
f"playlist_col_{column_number}_width", self.columnWidth(column_number)
|
||||
)
|
||||
|
||||
def _context_menu(self, pos):
|
||||
"""Display right-click menu"""
|
||||
@ -1064,14 +1063,13 @@ class PlaylistTab(QTableView):
|
||||
return
|
||||
|
||||
# Last column is set to stretch so ignore it here
|
||||
with db.Session() as session:
|
||||
for column_number in range(header.count() - 1):
|
||||
attr_name = f"playlist_col_{column_number}_width"
|
||||
record = Settings.get_setting(session, attr_name)
|
||||
if record.f_int is not None:
|
||||
self.setColumnWidth(column_number, record.f_int)
|
||||
else:
|
||||
self.setColumnWidth(column_number, Config.DEFAULT_COLUMN_WIDTH)
|
||||
for column_number in range(header.count() - 1):
|
||||
attr_name = f"playlist_col_{column_number}_width"
|
||||
value = repository.get_setting(attr_name)
|
||||
if value is not None:
|
||||
self.setColumnWidth(column_number, value)
|
||||
else:
|
||||
self.setColumnWidth(column_number, Config.DEFAULT_COLUMN_WIDTH)
|
||||
|
||||
def set_row_as_next_track(self) -> None:
|
||||
"""
|
||||
|
||||
@ -527,7 +527,7 @@ def get_playlist_row(playlistrow_id: int) -> PlaylistRowDTO | None:
|
||||
|
||||
|
||||
def get_playlist_rows(
|
||||
playlist_id: int, check_playlist_itegrity=True
|
||||
playlist_id: int, check_playlist_itegrity: bool = True
|
||||
) -> list[PlaylistRowDTO]:
|
||||
# Alias PlaydatesTable for subquery
|
||||
LatestPlaydate = aliased(Playdates)
|
||||
@ -724,7 +724,7 @@ def get_setting(name: str) -> int | None:
|
||||
with db.Session() as session:
|
||||
record = session.execute(
|
||||
select(Settings).where(Settings.name == name)
|
||||
).one_or_none()
|
||||
).scalars().one_or_none()
|
||||
if not record:
|
||||
return None
|
||||
|
||||
@ -739,7 +739,7 @@ def set_setting(name: str, value: int) -> None:
|
||||
with db.Session() as session:
|
||||
record = session.execute(
|
||||
select(Settings).where(Settings.name == name)
|
||||
).one_or_none()
|
||||
).scalars().one_or_none()
|
||||
if not record:
|
||||
record = Settings(session=session, name=name)
|
||||
if not record:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user