Reorder functions alphabetically

This commit is contained in:
Keith Edmunds 2022-08-13 16:05:12 +01:00
parent a1060d1173
commit 0f8c648d1c
2 changed files with 177 additions and 174 deletions

View File

@ -85,30 +85,11 @@ class Window(QMainWindow, Ui_MainWindow):
self.visible_playlist_tab: Callable[[], PlaylistTab] = \
self.tabPlaylist.currentWidget
self._load_last_playlists()
self.load_last_playlists()
self.enable_play_next_controls()
self.timer.start(Config.TIMER_MS)
self.connect_signals_slots()
def set_main_window_size(self) -> None:
"""Set size of window from database"""
with Session() as session:
record = Settings.get_int_settings(session, "mainwindow_x")
x = record.f_int or 1
record = Settings.get_int_settings(session, "mainwindow_y")
y = record.f_int or 1
record = Settings.get_int_settings(session, "mainwindow_width")
width = record.f_int or 1599
record = Settings.get_int_settings(session, "mainwindow_height")
height = record.f_int or 981
self.setGeometry(x, y, width, height)
record = Settings.get_int_settings(session, "splitter_top")
splitter_top = record.f_int or 256
record = Settings.get_int_settings(session, "splitter_bottom")
splitter_bottom = record.f_int or 256
self.splitter.setSizes([splitter_top, splitter_bottom])
return
#
# @staticmethod
# def print_current_database():
@ -204,19 +185,6 @@ class Window(QMainWindow, Ui_MainWindow):
#
self.timer.timeout.connect(self.tick)
def create_playlist(self) -> None:
"""Create new playlist"""
dlg = QInputDialog(self)
dlg.setInputMode(QInputDialog.TextInput)
dlg.setLabelText("Playlist name:")
dlg.resize(500, 100)
ok = dlg.exec()
if ok:
with Session() as session:
playlist = Playlists(session, dlg.textValue())
self.create_playlist_tab(session, playlist)
def close_playlist_tab(self) -> None:
"""
Close active playlist tab, called by menu item
@ -256,6 +224,19 @@ class Window(QMainWindow, Ui_MainWindow):
# # Just return if there's no visible playlist tab
# return
def create_playlist(self) -> None:
"""Create new playlist"""
dlg = QInputDialog(self)
dlg.setInputMode(QInputDialog.TextInput)
dlg.setLabelText("Playlist name:")
dlg.resize(500, 100)
ok = dlg.exec()
if ok:
with Session() as session:
playlist = Playlists(session, dlg.textValue())
self.create_playlist_tab(session, playlist)
def create_playlist_tab(self, session: Session,
playlist: Playlists) -> None:
"""
@ -479,7 +460,7 @@ class Window(QMainWindow, Ui_MainWindow):
# # also be saved to database
# self.visible_playlist_tab().insert_track(session, track)
def _load_last_playlists(self) -> None:
def load_last_playlists(self) -> None:
"""Load the playlists that were open when the last session closed"""
with Session() as session:
@ -683,6 +664,26 @@ class Window(QMainWindow, Ui_MainWindow):
#
# self.visible_playlist_tab().select_unplayed_tracks()
def set_main_window_size(self) -> None:
"""Set size of window from database"""
with Session() as session:
record = Settings.get_int_settings(session, "mainwindow_x")
x = record.f_int or 1
record = Settings.get_int_settings(session, "mainwindow_y")
y = record.f_int or 1
record = Settings.get_int_settings(session, "mainwindow_width")
width = record.f_int or 1599
record = Settings.get_int_settings(session, "mainwindow_height")
height = record.f_int or 981
self.setGeometry(x, y, width, height)
record = Settings.get_int_settings(session, "splitter_top")
splitter_top = record.f_int or 256
record = Settings.get_int_settings(session, "splitter_bottom")
splitter_bottom = record.f_int or 256
self.splitter.setSizes([splitter_top, splitter_bottom])
return
def set_tab_colour(self, widget: PlaylistTab, colour: QColor) -> None:
"""
Find the tab containing the widget and set the text colour

View File

@ -159,22 +159,6 @@ class PlaylistTab(QTableWidget):
# Now load our tracks and notes
self.populate(session, self.playlist_id)
def _column_resize(self, idx: int, old: int, new: int) -> None:
"""
Called when column widths are changed.
Save column sizes to database
"""
with Session() as session:
for column_name, data in columns.items():
idx = data.idx
width = self.columnWidth(idx)
attribute_name = f"playlist_{column_name}_col_width"
record = Settings.get_int_settings(session, attribute_name)
if record.f_int != self.columnWidth(idx):
record.update(session, {'f_int': width})
def __repr__(self) -> str:
return f"<PlaylistTab(id={self.playlist_id}"
#
@ -184,6 +168,16 @@ class PlaylistTab(QTableWidget):
# super(PlaylistTab, self).closeEditor(editor, hint)
# self.cellEditingEnded.emit()
def closeEvent(self, event) -> None:
"""Handle closing playist tab"""
with Session() as session:
# Record playlist as closed
playlist = session.get(Playlists, self.playlist_id)
playlist.close(session)
event.accept()
def dropEvent(self, event: QDropEvent) -> None:
"""
Handle drag/drop of rows
@ -335,6 +329,12 @@ class PlaylistTab(QTableWidget):
# # ########## Externally called functions ##########
def clear_next(self, session) -> None:
"""Clear next track marker"""
self._meta_clear_next()
self.update_display(session)
def clear_selection(self) -> None:
"""Unselect all tracks and reset drag mode"""
@ -348,21 +348,6 @@ class PlaylistTab(QTableWidget):
return [self._get_playlistrow_id(a) for a in self._selected_rows()]
def closeEvent(self, event) -> None:
"""Handle closing playist tab"""
with Session() as session:
# Record playlist as closed
playlist = session.get(Playlists, self.playlist_id)
playlist.close(session)
event.accept()
def clear_next(self, session) -> None:
"""Clear next track marker"""
self._meta_clear_next()
self.update_display(session)
#
# def create_note(self) -> None:
# """
@ -372,7 +357,7 @@ class PlaylistTab(QTableWidget):
# set note row to be end of playlist.
# """
#
# row: Optional[int] = self.get_selected_row()
# row: Optional[int] = self._get_selected_row()
# if not row:
# row = self.rowCount()
#
@ -387,16 +372,8 @@ class PlaylistTab(QTableWidget):
# note: Notes = Notes(
# session, self.playlist_id, row, dlg.textValue())
# self._insert_note(session, note, row, True) # checked
def get_selected_row(self) -> Optional[int]:
"""Return row number of first selected row, or None if none selected"""
if not self.selectionModel().hasSelection():
return None
else:
return self.selectionModel().selectedRows()[0].row()
#
# def get_selected_rows(self) -> List[int]:
# def _get_selected_rows(self) -> List[int]:
# """Return a sorted list of selected row numbers"""
#
# rows = self.selectionModel().selectedRows()
@ -577,7 +554,7 @@ class PlaylistTab(QTableWidget):
# destination_row = Playlists.next_free_row(session, playlist_id)
# rows_to_remove = []
#
# for row in self.get_selected_rows():
# for row in self._get_selected_rows():
# if row in notes_rows:
# note_obj = self._get_row_notes_object(row, session)
# note_obj.move_row(session, destination_row, playlist_id)
@ -900,7 +877,7 @@ class PlaylistTab(QTableWidget):
def set_selected_as_next(self) -> None:
"""Sets the select track as next to play"""
row = self.get_selected_row()
row = self._get_selected_row()
if row is None:
return None
@ -1111,20 +1088,6 @@ class PlaylistTab(QTableWidget):
print("playlists._add_track() not yet implemented")
def _open_in_audacity(self, track_id: int) -> None:
"""Open track in Audacity. Audacity must be already running"""
with Session() as session:
track = session.get(Tracks, track_id)
if not track:
log.error(
f"playlists._open_in_audacity({track_id=}): "
"Track not found"
)
return
open_in_audacity(track.path)
def _calculate_end_time(self, start: Optional[datetime],
duration: int) -> Optional[datetime]:
"""Return datetime 'duration' ms after 'start'"""
@ -1134,6 +1097,34 @@ class PlaylistTab(QTableWidget):
return start + timedelta(milliseconds=duration)
def _clear_current_track_row(self) -> None:
"""
Clear current row if there is one.
"""
current_row = self._get_current_track_row()
if current_row is None:
return
self._meta_clear_attribute(current_row, RowMeta.CURRENT)
def _column_resize(self, idx: int, old: int, new: int) -> None:
"""
Called when column widths are changed.
Save column sizes to database
"""
with Session() as session:
for column_name, data in columns.items():
idx = data.idx
width = self.columnWidth(idx)
attribute_name = f"playlist_{column_name}_col_width"
record = Settings.get_int_settings(session, attribute_name)
if record.f_int != self.columnWidth(idx):
record.update(session, {'f_int': width})
def _context_menu(self, pos):
assert self.menu
@ -1240,18 +1231,6 @@ class PlaylistTab(QTableWidget):
# item.setText(note_object.note)
# return
def _clear_current_track_row(self) -> None:
"""
Clear current row if there is one.
"""
current_row = self._get_current_track_row()
if current_row is None:
return
self._meta_clear_attribute(current_row, RowMeta.CURRENT)
# def _clear_played_row_status(self, row: int) -> None:
# """Clear played status on row"""
#
@ -1312,22 +1291,6 @@ class PlaylistTab(QTableWidget):
# return self._meta_search(RowMeta.NOTE, one=False)
#
def _get_playlistrow_id(self, row: int) -> int:
"""Return the playlistrow_id associated with this row"""
playlistrow_id = (self.item(row, columns['userdata'].idx)
.data(self.PLAYLISTROW_ID))
return playlistrow_id
def _get_row_track_id(self, row: int) -> int:
"""Return the track_id associated with this row or None"""
track_id = (self.item(row, columns['userdata'].idx)
.data(self.ROW_TRACK_ID))
return track_id
def _find_next_track_row(self, session: Session,
starting_row: int = None) -> Optional[int]:
"""
@ -1390,6 +1353,14 @@ class PlaylistTab(QTableWidget):
except ValueError:
return None
def _get_playlistrow_id(self, row: int) -> int:
"""Return the playlistrow_id associated with this row"""
playlistrow_id = (self.item(row, columns['userdata'].idx)
.data(self.PLAYLISTROW_ID))
return playlistrow_id
def _get_row_duration(self, row: int) -> int:
"""Return duration associated with this row"""
@ -1399,6 +1370,15 @@ class PlaylistTab(QTableWidget):
return duration
else:
return 0
def _get_row_track_id(self, row: int) -> int:
"""Return the track_id associated with this row or None"""
track_id = (self.item(row, columns['userdata'].idx)
.data(self.ROW_TRACK_ID))
return track_id
#
# def _get_row_end_time(self, row) -> Optional[datetime]:
# """
@ -1443,6 +1423,14 @@ class PlaylistTab(QTableWidget):
return None
except ValueError:
return None
def _get_selected_row(self) -> Optional[int]:
"""Return row number of first selected row, or None if none selected"""
if not self.selectionModel().hasSelection():
return None
else:
return self.selectionModel().selectedRows()[0].row()
#
# def _get_row_track_object(self, row: int, session: Session) \
# -> Optional[Tracks]:
@ -1656,6 +1644,20 @@ class PlaylistTab(QTableWidget):
target=self._run_subprocess, args=(cmd_list,))
thread.start()
def _open_in_audacity(self, track_id: int) -> None:
"""Open track in Audacity. Audacity must be already running"""
with Session() as session:
track = session.get(Tracks, track_id)
if not track:
log.error(
f"playlists._open_in_audacity({track_id=}): "
"Track not found"
)
return
open_in_audacity(track.path)
def _remove_track(self, row: int) -> None:
"""Remove track from row, making it a section header"""
@ -1690,7 +1692,7 @@ class PlaylistTab(QTableWidget):
track = session.get(Tracks, track_id)
if not track:
log.error(
f"playlists._open_in_audacity({track_id=}): "
f"playlists._rescan({track_id=}): "
"Track not found"
)
return
@ -1703,30 +1705,6 @@ class PlaylistTab(QTableWidget):
subprocess.call(args)
def _set_current_track_row(self, row: int) -> None:
"""Mark this row as current track"""
self._clear_current_track_row()
self._meta_set_attribute(row, RowMeta.CURRENT)
def _set_next_track_row(self, row: int) -> None:
"""Mark this row as next track"""
self._meta_clear_next()
self._meta_set_attribute(row, RowMeta.NEXT)
def _set_played_row(self, session: Session, row: int) -> None:
"""Mark this row as played"""
plr = session.get(PlaylistRows, self._get_playlistrow_id(row))
plr.played = True
session.commit()
def _set_unreadable_row(self, row: int) -> None:
"""Mark this row as unreadable"""
self._meta_set_attribute(row, RowMeta.UNREADABLE)
def _select_event(self) -> None:
"""
Called when item selection changes.
@ -1761,28 +1739,6 @@ class PlaylistTab(QTableWidget):
# items in that row selected)
return [row for row in set([a.row() for a in self.selectedItems()])]
#
# def _select_tracks(self, played: bool) -> None:
# """
# Select all played (played=True) or unplayed (played=False)
# tracks in playlist
# """
#
# # Need to allow multiple rows to be selected
# self.setSelectionMode(QAbstractItemView.MultiSelection)
# self.clear_selection()
#
# if played:
# rows = self._get_played_track_rows()
# else:
# rows = self._get_unplayed_track_rows()
#
# for row in rows:
# self.selectRow(row)
#
# # Reset extended selection
# self.setSelectionMode(QAbstractItemView.ExtendedSelection)
def _set_column_widths(self, session: Session) -> None:
"""Column widths from settings"""
@ -1795,6 +1751,12 @@ class PlaylistTab(QTableWidget):
else:
self.setColumnWidth(idx, Config.DEFAULT_COLUMN_WIDTH)
def _set_current_track_row(self, row: int) -> None:
"""Mark this row as current track"""
self._clear_current_track_row()
self._meta_set_attribute(row, RowMeta.CURRENT)
def _set_next(self, session: Session, row_number: int) -> None:
"""
Set passed row as next track to play.
@ -1833,6 +1795,19 @@ class PlaylistTab(QTableWidget):
# Notify musicmuster
self.musicmuster.this_is_the_next_track(session, self, track)
def _set_next_track_row(self, row: int) -> None:
"""Mark this row as next track"""
self._meta_clear_next()
self._meta_set_attribute(row, RowMeta.NEXT)
def _set_played_row(self, session: Session, row: int) -> None:
"""Mark this row as played"""
plr = session.get(PlaylistRows, self._get_playlistrow_id(row))
plr.played = True
session.commit()
def _set_row_bold(self, row: int, bold: bool = True) -> None:
"""Make row bold (bold=True) or not bold"""
@ -1860,14 +1835,14 @@ class PlaylistTab(QTableWidget):
for j in range(1, self.columnCount()):
if self.item(row, j):
self.item(row, j).setBackground(brush)
#
# def _set_row_content(self, row: int, object_id: int) -> None:
# """Set content associated with this row"""
#
# assert self.item(row, FIXUP.COL_USERDATA)
#
# self.item(row, FIXUP.COL_USERDATA).setData(
# self.CONTENT_OBJECT, object_id)
#
# def _set_row_content(self, row: int, object_id: int) -> None:
# """Set content associated with this row"""
#
# assert self.item(row, FIXUP.COL_USERDATA)
#
# self.item(row, FIXUP.COL_USERDATA).setData(
# self.CONTENT_OBJECT, object_id)
def _set_row_duration(self, row: int, ms: int) -> None:
"""Set duration of this row in row metadata"""
@ -1898,6 +1873,33 @@ class PlaylistTab(QTableWidget):
time_str = ""
item: QTableWidgetItem = QTableWidgetItem(time_str)
self.setItem(row, columns['start_time'].idx, item)
def _set_unreadable_row(self, row: int) -> None:
"""Mark this row as unreadable"""
self._meta_set_attribute(row, RowMeta.UNREADABLE)
#
# def _select_tracks(self, played: bool) -> None:
# """
# Select all played (played=True) or unplayed (played=False)
# tracks in playlist
# """
#
# # Need to allow multiple rows to be selected
# self.setSelectionMode(QAbstractItemView.MultiSelection)
# self.clear_selection()
#
# if played:
# rows = self._get_played_track_rows()
# else:
# rows = self._get_unplayed_track_rows()
#
# for row in rows:
# self.selectRow(row)
#
# # Reset extended selection
# self.setSelectionMode(QAbstractItemView.ExtendedSelection)
#
# def _set_timed_section(self, session, start_row, ms, no_end=False):
# """Add duration to a marked section"""