delete song and reload table working again
This commit is contained in:
parent
e35d7915b0
commit
176ea1360a
@ -539,6 +539,7 @@ class MusicTable(QTableView):
|
|||||||
Removes rows from the QTableView based on a list of indices
|
Removes rows from the QTableView based on a list of indices
|
||||||
and then reload the table
|
and then reload the table
|
||||||
"""
|
"""
|
||||||
|
debug('delete_selected_row_indices')
|
||||||
selected_indices = self.get_selected_rows()
|
selected_indices = self.get_selected_rows()
|
||||||
self.disconnect_data_changed()
|
self.disconnect_data_changed()
|
||||||
for index in selected_indices:
|
for index in selected_indices:
|
||||||
@ -686,8 +687,7 @@ class MusicTable(QTableView):
|
|||||||
)
|
)
|
||||||
# debug(f"reorganize_files() | Moved: {filepath} -> {new_path}")
|
# debug(f"reorganize_files() | Moved: {filepath} -> {new_path}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(
|
error(f"reorganize_files() | Error moving file: {filepath} | {e}")
|
||||||
f"reorganize_files() | Error moving file: {filepath} | {e}")
|
|
||||||
# Draw the rest of the owl
|
# Draw the rest of the owl
|
||||||
# QMessageBox.information(
|
# QMessageBox.information(
|
||||||
# self, "Reorganization complete", "Files successfully reorganized"
|
# self, "Reorganization complete", "Files successfully reorganized"
|
||||||
@ -700,7 +700,7 @@ class MusicTable(QTableView):
|
|||||||
self.set_current_song_filepath()
|
self.set_current_song_filepath()
|
||||||
self.playPauseSignal.emit()
|
self.playPauseSignal.emit()
|
||||||
|
|
||||||
def load_music_table(self, *playlist_id: int):
|
def load_music_table(self, *playlist_id):
|
||||||
"""
|
"""
|
||||||
Loads data into self (QTableView)
|
Loads data into self (QTableView)
|
||||||
Loads all songs in library, by default
|
Loads all songs in library, by default
|
||||||
@ -724,6 +724,7 @@ class MusicTable(QTableView):
|
|||||||
# Load a playlist
|
# Load a playlist
|
||||||
if playlist_id:
|
if playlist_id:
|
||||||
self.selected_playlist_id = playlist_id[0]
|
self.selected_playlist_id = playlist_id[0]
|
||||||
|
if self.selected_playlist_id:
|
||||||
try:
|
try:
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
query = f"SELECT id, {
|
query = f"SELECT id, {
|
||||||
@ -746,7 +747,6 @@ class MusicTable(QTableView):
|
|||||||
return
|
return
|
||||||
# Load the entire library
|
# Load the entire library
|
||||||
else:
|
else:
|
||||||
self.selected_playlist_id = None
|
|
||||||
try:
|
try:
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
query = f"SELECT id, {fields} FROM song"
|
query = f"SELECT id, {fields} FROM song"
|
||||||
@ -794,8 +794,7 @@ class MusicTable(QTableView):
|
|||||||
# reloading the model destroys and makes new indexes
|
# reloading the model destroys and makes new indexes
|
||||||
# so we look for the new index of the current song on load
|
# so we look for the new index of the current song on load
|
||||||
current_song_filepath = self.get_current_song_filepath()
|
current_song_filepath = self.get_current_song_filepath()
|
||||||
debug(
|
debug(f"load_music_table() | current filepath: {current_song_filepath}")
|
||||||
f"load_music_table() | current filepath: {current_song_filepath}")
|
|
||||||
for row in range(self.model2.rowCount()):
|
for row in range(self.model2.rowCount()):
|
||||||
real_index = self.model2.index(
|
real_index = self.model2.index(
|
||||||
row, self.headers.user_fields.index("filepath")
|
row, self.headers.user_fields.index("filepath")
|
||||||
@ -806,10 +805,7 @@ class MusicTable(QTableView):
|
|||||||
|
|
||||||
db_name: str = self.config.get("settings", "db").split("/").pop()
|
db_name: str = self.config.get("settings", "db").split("/").pop()
|
||||||
db_filename = self.config.get("settings", "db")
|
db_filename = self.config.get("settings", "db")
|
||||||
self.playlistStatsSignal.emit(
|
self.playlistStatsSignal.emit(f"Songs: {row_count} | Total time: {total_time} | {db_name} | {db_filename}")
|
||||||
f"Songs: {row_count} | Total time: {
|
|
||||||
total_time} | {db_name} | {db_filename}"
|
|
||||||
)
|
|
||||||
self.loadMusicTableSignal.emit()
|
self.loadMusicTableSignal.emit()
|
||||||
self.connect_data_changed()
|
self.connect_data_changed()
|
||||||
self.connect_layout_changed()
|
self.connect_layout_changed()
|
||||||
@ -920,10 +916,7 @@ class MusicTable(QTableView):
|
|||||||
return []
|
return []
|
||||||
selected_rows = set(index.row() for index in indexes)
|
selected_rows = set(index.row() for index in indexes)
|
||||||
id_list = [
|
id_list = [
|
||||||
self.proxymodel.data(
|
self.proxymodel.data(self.proxymodel.index(row, 0), Qt.ItemDataRole.UserRole) for row in selected_rows
|
||||||
self.proxymodel.index(row, 0), Qt.ItemDataRole.UserRole
|
|
||||||
)
|
|
||||||
for row in selected_rows
|
|
||||||
]
|
]
|
||||||
return id_list
|
return id_list
|
||||||
|
|
||||||
@ -947,9 +940,7 @@ class MusicTable(QTableView):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
# if the user doesnt have filepath selected as a header, retrieve the file from db
|
# if the user doesnt have filepath selected as a header, retrieve the file from db
|
||||||
row = self.currentIndex().row()
|
row = self.currentIndex().row()
|
||||||
id = self.proxymodel.data(
|
id = self.proxymodel.data(self.proxymodel.index(row, 0), Qt.ItemDataRole.UserRole)
|
||||||
self.proxymodel.index(row, 0), Qt.ItemDataRole.UserRole
|
|
||||||
)
|
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
filepath = db.query("SELECT filepath FROM song WHERE id = ?", (id,))[0][0]
|
filepath = db.query("SELECT filepath FROM song WHERE id = ?", (id,))[0][0]
|
||||||
self.selected_song_filepath = filepath
|
self.selected_song_filepath = filepath
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user