Compare commits
6 Commits
243bc765f9
...
b86b7f7f33
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b86b7f7f33 | ||
|
|
c1dd111453 | ||
|
|
7ed54f2bab | ||
|
|
06ef175b46 | ||
|
|
e313e84010 | ||
|
|
6391490f9d |
@ -54,6 +54,10 @@ class TrackSelectDialog(QDialog):
|
|||||||
height = record.f_int or 600
|
height = record.f_int or 600
|
||||||
self.resize(width, height)
|
self.resize(width, height)
|
||||||
|
|
||||||
|
if add_to_header:
|
||||||
|
self.ui.lblNote.setVisible(False)
|
||||||
|
self.ui.txtNote.setVisible(False)
|
||||||
|
|
||||||
def add_selected(self) -> None:
|
def add_selected(self) -> None:
|
||||||
"""Handle Add button"""
|
"""Handle Add button"""
|
||||||
|
|
||||||
@ -65,18 +69,22 @@ class TrackSelectDialog(QDialog):
|
|||||||
track = item.data(Qt.ItemDataRole.UserRole)
|
track = item.data(Qt.ItemDataRole.UserRole)
|
||||||
|
|
||||||
note = self.ui.txtNote.text()
|
note = self.ui.txtNote.text()
|
||||||
|
track_id = None
|
||||||
|
if track:
|
||||||
|
track_id = track.id
|
||||||
|
|
||||||
if not note and not track:
|
if not track_id:
|
||||||
|
if note:
|
||||||
|
self.model.insert_row(self.new_row_number, track_id, note)
|
||||||
|
self.ui.txtNote.clear()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# No note, no track
|
||||||
return
|
return
|
||||||
|
|
||||||
self.ui.txtNote.clear()
|
self.ui.txtNote.clear()
|
||||||
self.select_searchtext()
|
self.select_searchtext()
|
||||||
|
|
||||||
track_id = None
|
|
||||||
if track:
|
|
||||||
track_id = track.id
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
# Check whether track is already in playlist
|
# Check whether track is already in playlist
|
||||||
move_existing = False
|
move_existing = False
|
||||||
existing_prd = self.model.is_track_in_playlist(track_id)
|
existing_prd = self.model.is_track_in_playlist(track_id)
|
||||||
@ -87,14 +95,16 @@ class TrackSelectDialog(QDialog):
|
|||||||
default_yes=True,
|
default_yes=True,
|
||||||
):
|
):
|
||||||
move_existing = True
|
move_existing = True
|
||||||
if self.add_to_header and existing_prd: # "and existing_prd" for mypy's benefit
|
|
||||||
if move_existing:
|
if self.add_to_header:
|
||||||
|
if move_existing and existing_prd: # "and existing_prd" for mypy's benefit
|
||||||
self.model.move_track_to_header(self.new_row_number, existing_prd, note)
|
self.model.move_track_to_header(self.new_row_number, existing_prd, note)
|
||||||
else:
|
else:
|
||||||
self.model.add_track_to_header(self.new_row_number, track_id)
|
self.model.add_track_to_header(self.new_row_number, track_id)
|
||||||
# Close dialog - we can only add one track to a header
|
# Close dialog - we can only add one track to a header
|
||||||
self.accept()
|
self.accept()
|
||||||
else:
|
else:
|
||||||
|
# Adding a new track row
|
||||||
if move_existing and existing_prd: # "and existing_prd" for mypy's benefit
|
if move_existing and existing_prd: # "and existing_prd" for mypy's benefit
|
||||||
self.model.move_track_add_note(self.new_row_number, existing_prd, note)
|
self.model.move_track_add_note(self.new_row_number, existing_prd, note)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -239,6 +239,20 @@ class Playlists(Base):
|
|||||||
session.add(self)
|
session.add(self)
|
||||||
session.flush()
|
session.flush()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def clear_tabs(session: scoped_session, playlist_ids: List[int]) -> None:
|
||||||
|
"""
|
||||||
|
Make all tab records NULL
|
||||||
|
"""
|
||||||
|
|
||||||
|
session.execute(
|
||||||
|
update(Playlists)
|
||||||
|
.where(
|
||||||
|
(Playlists.id.in_(playlist_ids))
|
||||||
|
)
|
||||||
|
.values(tab=None)
|
||||||
|
)
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
"""Mark playlist as unloaded"""
|
"""Mark playlist as unloaded"""
|
||||||
|
|
||||||
|
|||||||
@ -875,15 +875,23 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
def load_last_playlists(self) -> None:
|
def load_last_playlists(self) -> None:
|
||||||
"""Load the playlists that were open when the last session closed"""
|
"""Load the playlists that were open when the last session closed"""
|
||||||
|
|
||||||
|
playlist_ids = []
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
for playlist in Playlists.get_open(session):
|
for playlist in Playlists.get_open(session):
|
||||||
if playlist:
|
if playlist:
|
||||||
_ = self.create_playlist_tab(playlist)
|
_ = self.create_playlist_tab(playlist)
|
||||||
|
playlist_ids.append(playlist.id)
|
||||||
# Set active tab
|
# Set active tab
|
||||||
record = Settings.get_int_settings(session, "active_tab")
|
record = Settings.get_int_settings(session, "active_tab")
|
||||||
if record.f_int and record.f_int >= 0:
|
if record.f_int is not None and record.f_int >= 0:
|
||||||
self.tabPlaylist.setCurrentIndex(record.f_int)
|
self.tabPlaylist.setCurrentIndex(record.f_int)
|
||||||
|
|
||||||
|
# Tabs may move during use. Rather than track where tabs
|
||||||
|
# are, we record the tab index when we close the main
|
||||||
|
# window. To avoid possible duplicate tab entries, we null
|
||||||
|
# them all out now.
|
||||||
|
Playlists.clear_tabs(session, playlist_ids)
|
||||||
|
|
||||||
def lookup_row_in_songfacts(self) -> None:
|
def lookup_row_in_songfacts(self) -> None:
|
||||||
"""
|
"""
|
||||||
Display songfacts page for title in highlighted row
|
Display songfacts page for title in highlighted row
|
||||||
|
|||||||
@ -306,7 +306,13 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
if unplayed_rows:
|
if unplayed_rows:
|
||||||
try:
|
try:
|
||||||
# Find next row after current track
|
# Find next row after current track
|
||||||
next_row = min([a for a in unplayed_rows if a > row_number])
|
next_row = min(
|
||||||
|
[
|
||||||
|
a
|
||||||
|
for a in unplayed_rows
|
||||||
|
if a > row_number and not self.is_header_row(a)
|
||||||
|
]
|
||||||
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Find first unplayed track
|
# Find first unplayed track
|
||||||
next_row = min(unplayed_rows)
|
next_row = min(unplayed_rows)
|
||||||
@ -724,6 +730,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
self.refresh_data(session)
|
self.refresh_data(session)
|
||||||
super().endInsertRows()
|
super().endInsertRows()
|
||||||
|
|
||||||
|
self.signals.resize_rows_signal.emit(self.playlist_id)
|
||||||
self.reset_track_sequence_row_numbers()
|
self.reset_track_sequence_row_numbers()
|
||||||
self.invalidate_rows(list(range(new_row_number, len(self.playlist_rows))))
|
self.invalidate_rows(list(range(new_row_number, len(self.playlist_rows))))
|
||||||
|
|
||||||
@ -1472,6 +1479,9 @@ class PlaylistProxyModel(QSortFilterProxyModel):
|
|||||||
def get_row_track_path(self, row_number: int) -> str:
|
def get_row_track_path(self, row_number: int) -> str:
|
||||||
return self.data_model.get_row_track_path(row_number)
|
return self.data_model.get_row_track_path(row_number)
|
||||||
|
|
||||||
|
def get_unplayed_rows(self) -> List[int]:
|
||||||
|
return self.data_model.get_unplayed_rows()
|
||||||
|
|
||||||
def hide_played_tracks(self, hide: bool) -> None:
|
def hide_played_tracks(self, hide: bool) -> None:
|
||||||
return self.data_model.hide_played_tracks(hide)
|
return self.data_model.hide_played_tracks(hide)
|
||||||
|
|
||||||
|
|||||||
@ -234,13 +234,15 @@ class PlaylistTab(QTableView):
|
|||||||
super().dropEvent(event)
|
super().dropEvent(event)
|
||||||
|
|
||||||
from_rows = self.selected_model_row_numbers()
|
from_rows = self.selected_model_row_numbers()
|
||||||
to_row = self.indexAt(event.position().toPoint()).row()
|
to_index = self.indexAt(event.position().toPoint())
|
||||||
|
to_model_row = self.proxy_model.mapToSource(to_index).row()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
0 <= min(from_rows) <= self.model().rowCount()
|
0 <= min(from_rows) <= self.data_model.rowCount()
|
||||||
and 0 <= max(from_rows) <= self.model().rowCount()
|
and 0 <= max(from_rows) <= self.data_model.rowCount()
|
||||||
and 0 <= to_row <= self.model().rowCount()
|
and 0 <= to_model_row <= self.data_model.rowCount()
|
||||||
):
|
):
|
||||||
self.model().move_rows(from_rows, to_row)
|
self.data_model.move_rows(from_rows, to_model_row)
|
||||||
|
|
||||||
# Reset drag mode to allow row selection by dragging
|
# Reset drag mode to allow row selection by dragging
|
||||||
self.setDragEnabled(False)
|
self.setDragEnabled(False)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user