Scroll current row to top; improve session handling
This commit is contained in:
parent
e7004688d0
commit
9c0371d41c
@ -54,6 +54,7 @@ class Config(object):
|
|||||||
NORMALISE_ON_IMPORT = True
|
NORMALISE_ON_IMPORT = True
|
||||||
NOTE_TIME_FORMAT = "%H:%M:%S"
|
NOTE_TIME_FORMAT = "%H:%M:%S"
|
||||||
ROOT = os.environ.get('ROOT') or "/home/kae/music"
|
ROOT = os.environ.get('ROOT') or "/home/kae/music"
|
||||||
|
SCROLL_TOP_MARGIN = 3
|
||||||
TESTMODE = True
|
TESTMODE = True
|
||||||
TOD_TIME_FORMAT = "%H:%M:%S"
|
TOD_TIME_FORMAT = "%H:%M:%S"
|
||||||
TIMER_MS = 500
|
TIMER_MS = 500
|
||||||
|
|||||||
@ -235,8 +235,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
"Can't close next track playlist", 5000)
|
"Can't close next track playlist", 5000)
|
||||||
return
|
return
|
||||||
# It's OK to close this playlist so remove from open playlist list
|
# It's OK to close this playlist so remove from open playlist list
|
||||||
with Session() as session:
|
self.tabPlaylist.widget(index).close()
|
||||||
self.tabPlaylist.widget(index).playlist.close(session)
|
|
||||||
|
|
||||||
# Close regardless of tab type
|
# Close regardless of tab type
|
||||||
self.tabPlaylist.removeTab(index)
|
self.tabPlaylist.removeTab(index)
|
||||||
@ -516,6 +515,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
self.current_track = self.next_track
|
self.current_track = self.next_track
|
||||||
self.next_track = None
|
self.next_track = None
|
||||||
|
|
||||||
|
# Ensure track is in session
|
||||||
|
if self.current_track not in session:
|
||||||
|
session.add(self.current_track)
|
||||||
|
|
||||||
# If current track on different playlist_tab to last, reset
|
# If current track on different playlist_tab to last, reset
|
||||||
# last track playlist_tab colour
|
# last track playlist_tab colour
|
||||||
# Set current track playlist_tab colour
|
# Set current track playlist_tab colour
|
||||||
|
|||||||
@ -220,8 +220,9 @@ class PlaylistTab(QTableWidget):
|
|||||||
if row not in self._get_notes_rows():
|
if row not in self._get_notes_rows():
|
||||||
if not current and not next_row:
|
if not current and not next_row:
|
||||||
act_setnext = self.menu.addAction("Set next")
|
act_setnext = self.menu.addAction("Set next")
|
||||||
|
with Session() as session:
|
||||||
act_setnext.triggered.connect(
|
act_setnext.triggered.connect(
|
||||||
lambda: self._set_next(row))
|
lambda: self._set_next(row, session))
|
||||||
act_copypath = self.menu.addAction("Copy track path")
|
act_copypath = self.menu.addAction("Copy track path")
|
||||||
act_copypath.triggered.connect(
|
act_copypath.triggered.connect(
|
||||||
lambda: self._copy_path(row))
|
lambda: self._copy_path(row))
|
||||||
@ -397,7 +398,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
- Note start time
|
- Note start time
|
||||||
- Mark next-track row as current
|
- Mark next-track row as current
|
||||||
- Mark current row as played
|
- Mark current row as played
|
||||||
- Scroll to put current track in middle
|
- Scroll to put current track as required
|
||||||
- Set next track
|
- Set next track
|
||||||
- Update display
|
- Update display
|
||||||
"""
|
"""
|
||||||
@ -414,15 +415,20 @@ class PlaylistTab(QTableWidget):
|
|||||||
# Mark current row as played
|
# Mark current row as played
|
||||||
self._set_played_row(current_row)
|
self._set_played_row(current_row)
|
||||||
|
|
||||||
# Scroll to put current track in middle
|
# Scroll to put current track as requiredin middle We want this
|
||||||
scroll_to = self.item(current_row, self.COL_MSS)
|
# row to be Config.SCROLL_TOP_MARGIN from the top. Rows number
|
||||||
self.scrollToItem(scroll_to, QAbstractItemView.PositionAtCenter)
|
# from zero, so set (current_row - Config.SCROLL_TOP_MARGIN + 1)
|
||||||
|
# row to be top row
|
||||||
|
|
||||||
|
top_row = max(0, current_row - Config.SCROLL_TOP_MARGIN + 1)
|
||||||
|
scroll_item = self.item(top_row, self.COL_MSS)
|
||||||
|
self.scrollToItem(scroll_item, QAbstractItemView.PositionAtTop)
|
||||||
|
|
||||||
# Set next track
|
# Set next track
|
||||||
search_from = current_row + 1
|
search_from = current_row + 1
|
||||||
next_row = self._find_next_track_row(search_from)
|
next_row = self._find_next_track_row(search_from)
|
||||||
if next_row:
|
if next_row:
|
||||||
self._set_next(next_row)
|
self._set_next(next_row, session)
|
||||||
|
|
||||||
# Update display
|
# Update display
|
||||||
self.update_display(session)
|
self.update_display(session)
|
||||||
@ -636,7 +642,8 @@ class PlaylistTab(QTableWidget):
|
|||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self._set_next(row)
|
with Session() as session:
|
||||||
|
self._set_next(row, session)
|
||||||
|
|
||||||
def update_display(self, session, clear_selection: bool = True) -> None:
|
def update_display(self, session, clear_selection: bool = True) -> None:
|
||||||
"""
|
"""
|
||||||
@ -1398,7 +1405,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
else:
|
else:
|
||||||
self.setColumnWidth(column, Config.DEFAULT_COLUMN_WIDTH)
|
self.setColumnWidth(column, Config.DEFAULT_COLUMN_WIDTH)
|
||||||
|
|
||||||
def _set_next(self, row: int) -> None:
|
def _set_next(self, row: int, session: Session) -> None:
|
||||||
"""
|
"""
|
||||||
Set passed row as next track to play.
|
Set passed row as next track to play.
|
||||||
|
|
||||||
@ -1412,7 +1419,6 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
DEBUG(f"_set_next({row=})")
|
DEBUG(f"_set_next({row=})")
|
||||||
|
|
||||||
with Session() as session:
|
|
||||||
# Check row is a track row
|
# Check row is a track row
|
||||||
if row in self._get_notes_rows():
|
if row in self._get_notes_rows():
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user