LeftPane -> PlaylistsPane, MusicTable loading from library or playlist working
This commit is contained in:
parent
97e335ba00
commit
4292091d3b
@ -585,7 +585,7 @@ class MainWindow(QMainWindow):
|
|||||||
"""Scans for new files in the configured library folder
|
"""Scans for new files in the configured library folder
|
||||||
Refreshes the datagridview"""
|
Refreshes the datagridview"""
|
||||||
scan_for_music()
|
scan_for_music()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def clear_database(self) -> None:
|
def clear_database(self) -> None:
|
||||||
"""Clears all songs from the database"""
|
"""Clears all songs from the database"""
|
||||||
@ -598,7 +598,7 @@ class MainWindow(QMainWindow):
|
|||||||
)
|
)
|
||||||
if reply:
|
if reply:
|
||||||
delete_and_create_library_database()
|
delete_and_create_library_database()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def delete_database(self) -> None:
|
def delete_database(self) -> None:
|
||||||
"""Deletes the entire database"""
|
"""Deletes the entire database"""
|
||||||
@ -611,7 +611,7 @@ class MainWindow(QMainWindow):
|
|||||||
)
|
)
|
||||||
if reply:
|
if reply:
|
||||||
initialize_db()
|
initialize_db()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def reinitialize_database(self) -> None:
|
def reinitialize_database(self) -> None:
|
||||||
"""Clears all tables in database and recreates"""
|
"""Clears all tables in database and recreates"""
|
||||||
@ -624,7 +624,7 @@ class MainWindow(QMainWindow):
|
|||||||
)
|
)
|
||||||
if reply:
|
if reply:
|
||||||
initialize_db()
|
initialize_db()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def process_probe(self, buff) -> None:
|
def process_probe(self, buff) -> None:
|
||||||
buff.startTime()
|
buff.startTime()
|
||||||
|
|||||||
@ -81,7 +81,7 @@ class MusicTable(QTableView):
|
|||||||
self.doubleClicked.connect(self.set_current_song_filepath)
|
self.doubleClicked.connect(self.set_current_song_filepath)
|
||||||
self.enterKey.connect(self.set_current_song_filepath)
|
self.enterKey.connect(self.set_current_song_filepath)
|
||||||
self.deleteKey.connect(self.delete_songs)
|
self.deleteKey.connect(self.delete_songs)
|
||||||
self.fetch_library()
|
self.load_music_table()
|
||||||
self.setup_keyboard_shortcuts()
|
self.setup_keyboard_shortcuts()
|
||||||
self.model.dataChanged.connect(self.on_cell_data_changed) # editing cells
|
self.model.dataChanged.connect(self.on_cell_data_changed) # editing cells
|
||||||
self.model.layoutChanged.connect(self.restore_scroll_position)
|
self.model.layoutChanged.connect(self.restore_scroll_position)
|
||||||
@ -137,7 +137,7 @@ class MusicTable(QTableView):
|
|||||||
model.removeRow(index)
|
model.removeRow(index)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info(f"MusicTable.py delete_songs() failed | {e}")
|
logging.info(f"MusicTable.py delete_songs() failed | {e}")
|
||||||
self.fetch_library()
|
self.load_music_table()
|
||||||
self.model.dataChanged.connect(self.on_cell_data_changed)
|
self.model.dataChanged.connect(self.on_cell_data_changed)
|
||||||
|
|
||||||
def open_directory(self):
|
def open_directory(self):
|
||||||
@ -316,7 +316,7 @@ class MusicTable(QTableView):
|
|||||||
print(f"Error moving file: {filepath} | {e}")
|
print(f"Error moving file: {filepath} | {e}")
|
||||||
# Draw the rest of the owl
|
# Draw the rest of the owl
|
||||||
self.model.dataChanged.disconnect(self.on_cell_data_changed)
|
self.model.dataChanged.disconnect(self.on_cell_data_changed)
|
||||||
self.fetch_library()
|
self.load_music_table()
|
||||||
self.model.dataChanged.connect(self.on_cell_data_changed)
|
self.model.dataChanged.connect(self.on_cell_data_changed)
|
||||||
QMessageBox.information(
|
QMessageBox.information(
|
||||||
self, "Reorganization complete", "Files successfully reorganized"
|
self, "Reorganization complete", "Files successfully reorganized"
|
||||||
@ -328,7 +328,7 @@ class MusicTable(QTableView):
|
|||||||
self.set_current_song_filepath()
|
self.set_current_song_filepath()
|
||||||
self.playPauseSignal.emit()
|
self.playPauseSignal.emit()
|
||||||
|
|
||||||
def fetch_library(self):
|
def load_music_table(self, *playlist_id):
|
||||||
"""Initializes the tableview model"""
|
"""Initializes the tableview model"""
|
||||||
self.vertical_scroll_position = (
|
self.vertical_scroll_position = (
|
||||||
self.verticalScrollBar().value()
|
self.verticalScrollBar().value()
|
||||||
@ -336,6 +336,25 @@ class MusicTable(QTableView):
|
|||||||
# temporarily disconnect the datachanged signal to avoid EVERY SONG getting triggered
|
# temporarily disconnect the datachanged signal to avoid EVERY SONG getting triggered
|
||||||
self.model.clear()
|
self.model.clear()
|
||||||
self.model.setHorizontalHeaderLabels(self.table_headers)
|
self.model.setHorizontalHeaderLabels(self.table_headers)
|
||||||
|
if playlist_id:
|
||||||
|
playlist_id = playlist_id[0]
|
||||||
|
# Fetch playlist data
|
||||||
|
print(
|
||||||
|
f"MusicTable.py load_music_table() | fetching playlist data, playlist_id: {playlist_id}"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
with DBA.DBAccess() as db:
|
||||||
|
data = db.query(
|
||||||
|
"SELECT s.id, s.title, s.artist, s.album, s.track_number, s.genre, s.codec, s.album_date, s.filepath FROM song s JOIN song_playlist sp ON s.id = sp.id WHERE sp.id = ?",
|
||||||
|
(playlist_id,),
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(
|
||||||
|
f"MusicTable.py | load_music_table | Unhandled exception: {e}"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print("MusicTable.py load_music_table() | fetching library data")
|
||||||
# Fetch library data
|
# Fetch library data
|
||||||
try:
|
try:
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
@ -344,7 +363,9 @@ class MusicTable(QTableView):
|
|||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning(f"MusicTable.py | fetch_library | Unhandled exception: {e}")
|
logging.warning(
|
||||||
|
f"MusicTable.py | load_music_table | Unhandled exception: {e}"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
# Populate the model
|
# Populate the model
|
||||||
for row_data in data:
|
for row_data in data:
|
||||||
@ -373,7 +394,7 @@ class MusicTable(QTableView):
|
|||||||
number_of_files_added = add_files_to_library(files)
|
number_of_files_added = add_files_to_library(files)
|
||||||
if number_of_files_added:
|
if number_of_files_added:
|
||||||
self.model.dataChanged.disconnect(self.on_cell_data_changed)
|
self.model.dataChanged.disconnect(self.on_cell_data_changed)
|
||||||
self.fetch_library()
|
self.load_music_table()
|
||||||
self.model.dataChanged.connect(self.on_cell_data_changed)
|
self.model.dataChanged.connect(self.on_cell_data_changed)
|
||||||
|
|
||||||
def get_selected_rows(self) -> list[int]:
|
def get_selected_rows(self) -> list[int]:
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from PyQt5.QtWidgets import QListWidget, QTreeWidget, QTreeWidgetItem
|
from PyQt5.QtWidgets import QListWidget, QTreeWidget, QTreeWidgetItem
|
||||||
|
from PyQt5.QtCore import pyqtSignal
|
||||||
import DBA
|
import DBA
|
||||||
|
|
||||||
|
|
||||||
@ -8,7 +9,9 @@ class PlaylistWidgetItem(QTreeWidgetItem):
|
|||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
|
||||||
class LeftPane(QTreeWidget):
|
class PlaylistsPane(QTreeWidget):
|
||||||
|
playlistChoiceSignal = pyqtSignal(int)
|
||||||
|
|
||||||
def __init__(self: QTreeWidget, parent=None):
|
def __init__(self: QTreeWidget, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
library_root = QTreeWidgetItem(["Library"])
|
library_root = QTreeWidgetItem(["Library"])
|
||||||
@ -25,10 +28,13 @@ class LeftPane(QTreeWidget):
|
|||||||
playlists_root.addChild(branch)
|
playlists_root.addChild(branch)
|
||||||
|
|
||||||
self.currentItemChanged.connect(self.playlist_clicked)
|
self.currentItemChanged.connect(self.playlist_clicked)
|
||||||
|
self.playlist_db_id_choice: int | None = None
|
||||||
|
|
||||||
def playlist_clicked(self, item):
|
def playlist_clicked(self, item):
|
||||||
if isinstance(item, PlaylistWidgetItem):
|
if isinstance(item, PlaylistWidgetItem):
|
||||||
print(f"ID: {item.id}, name: {item.text(0)}")
|
print(f"ID: {item.id}, name: {item.text(0)}")
|
||||||
|
self.playlist_db_id_choice = item.id
|
||||||
|
self.playlistChoiceSignal.emit(item.id)
|
||||||
elif item.text(0).lower() == "all songs":
|
elif item.text(0).lower() == "all songs":
|
||||||
self.all_songs_selected()
|
self.all_songs_selected()
|
||||||
|
|
||||||
@ -6,4 +6,4 @@ from .ErrorDialog import ErrorDialog
|
|||||||
from .LyricsWindow import LyricsWindow
|
from .LyricsWindow import LyricsWindow
|
||||||
from .AddToPlaylistWindow import AddToPlaylistWindow
|
from .AddToPlaylistWindow import AddToPlaylistWindow
|
||||||
from .CreatePlaylistWindow import CreatePlaylistWindow
|
from .CreatePlaylistWindow import CreatePlaylistWindow
|
||||||
from .LeftPane import LeftPane
|
from .PlaylistsPane import PlaylistsPane
|
||||||
|
|||||||
13
main.py
13
main.py
@ -117,6 +117,11 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
self.on_play_clicked
|
self.on_play_clicked
|
||||||
) # Spacebar toggle play/pause signal
|
) # Spacebar toggle play/pause signal
|
||||||
|
|
||||||
|
## Playlist triggers
|
||||||
|
self.playlistTreeView.playlistChoiceSignal.connect(
|
||||||
|
self.tableView.load_music_table
|
||||||
|
)
|
||||||
|
|
||||||
# albumGraphicsView
|
# albumGraphicsView
|
||||||
self.albumGraphicsView.albumArtDropped.connect(
|
self.albumGraphicsView.albumArtDropped.connect(
|
||||||
self.set_album_art_for_selected_songs
|
self.set_album_art_for_selected_songs
|
||||||
@ -357,7 +362,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
"""Scans for new files in the configured library folder
|
"""Scans for new files in the configured library folder
|
||||||
Refreshes the datagridview"""
|
Refreshes the datagridview"""
|
||||||
scan_for_music()
|
scan_for_music()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def clear_database(self) -> None:
|
def clear_database(self) -> None:
|
||||||
"""Clears all songs from the database"""
|
"""Clears all songs from the database"""
|
||||||
@ -370,7 +375,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
)
|
)
|
||||||
if reply:
|
if reply:
|
||||||
delete_and_create_library_database()
|
delete_and_create_library_database()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def delete_database(self) -> None:
|
def delete_database(self) -> None:
|
||||||
"""Deletes the entire database"""
|
"""Deletes the entire database"""
|
||||||
@ -383,7 +388,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
)
|
)
|
||||||
if reply:
|
if reply:
|
||||||
initialize_db()
|
initialize_db()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def reinitialize_database(self) -> None:
|
def reinitialize_database(self) -> None:
|
||||||
"""Clears all tables in database and recreates"""
|
"""Clears all tables in database and recreates"""
|
||||||
@ -396,7 +401,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
)
|
)
|
||||||
if reply:
|
if reply:
|
||||||
initialize_db()
|
initialize_db()
|
||||||
self.tableView.fetch_library()
|
self.tableView.load_music_table()
|
||||||
|
|
||||||
def process_probe(self, buff) -> None:
|
def process_probe(self, buff) -> None:
|
||||||
buff.startTime()
|
buff.startTime()
|
||||||
|
|||||||
11
ui.py
11
ui.py
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# Form implementation generated from reading ui file 'ui.ui'
|
# Form implementation generated from reading ui file 'ui.ui'
|
||||||
#
|
#
|
||||||
# Created by: PyQt5 UI code generator 5.15.10
|
# Created by: PyQt5 UI code generator 5.15.11
|
||||||
#
|
#
|
||||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||||
# run again. Do not edit this file unless you know what you are doing.
|
# run again. Do not edit this file unless you know what you are doing.
|
||||||
@ -21,7 +21,8 @@ class Ui_MainWindow(object):
|
|||||||
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.centralwidget)
|
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.centralwidget)
|
||||||
self.verticalLayout_3.setObjectName("verticalLayout_3")
|
self.verticalLayout_3.setObjectName("verticalLayout_3")
|
||||||
self.verticalLayout = QtWidgets.QVBoxLayout()
|
self.verticalLayout = QtWidgets.QVBoxLayout()
|
||||||
self.verticalLayout.setContentsMargins(-1, -1, 10, -1)
|
self.verticalLayout.setContentsMargins(-1, -1, 0, -1)
|
||||||
|
self.verticalLayout.setSpacing(6)
|
||||||
self.verticalLayout.setObjectName("verticalLayout")
|
self.verticalLayout.setObjectName("verticalLayout")
|
||||||
self.hLayoutHead = QtWidgets.QHBoxLayout()
|
self.hLayoutHead = QtWidgets.QHBoxLayout()
|
||||||
self.hLayoutHead.setObjectName("hLayoutHead")
|
self.hLayoutHead.setObjectName("hLayoutHead")
|
||||||
@ -101,7 +102,7 @@ class Ui_MainWindow(object):
|
|||||||
self.hLayoutMusicTable = QtWidgets.QHBoxLayout()
|
self.hLayoutMusicTable = QtWidgets.QHBoxLayout()
|
||||||
self.hLayoutMusicTable.setContentsMargins(0, -1, 0, -1)
|
self.hLayoutMusicTable.setContentsMargins(0, -1, 0, -1)
|
||||||
self.hLayoutMusicTable.setObjectName("hLayoutMusicTable")
|
self.hLayoutMusicTable.setObjectName("hLayoutMusicTable")
|
||||||
self.playlistTreeView = LeftPane(self.centralwidget)
|
self.playlistTreeView = PlaylistsPane(self.centralwidget)
|
||||||
self.playlistTreeView.setObjectName("playlistTreeView")
|
self.playlistTreeView.setObjectName("playlistTreeView")
|
||||||
self.hLayoutMusicTable.addWidget(self.playlistTreeView)
|
self.hLayoutMusicTable.addWidget(self.playlistTreeView)
|
||||||
self.tableView = MusicTable(self.centralwidget)
|
self.tableView = MusicTable(self.centralwidget)
|
||||||
@ -129,6 +130,7 @@ class Ui_MainWindow(object):
|
|||||||
self.verticalLayout.addLayout(self.hLayoutMusicTable)
|
self.verticalLayout.addLayout(self.hLayoutMusicTable)
|
||||||
self.verticalLayout_3.addLayout(self.verticalLayout)
|
self.verticalLayout_3.addLayout(self.verticalLayout)
|
||||||
self.hLayoutControls = QtWidgets.QHBoxLayout()
|
self.hLayoutControls = QtWidgets.QHBoxLayout()
|
||||||
|
self.hLayoutControls.setSpacing(6)
|
||||||
self.hLayoutControls.setObjectName("hLayoutControls")
|
self.hLayoutControls.setObjectName("hLayoutControls")
|
||||||
self.previousButton = QtWidgets.QPushButton(self.centralwidget)
|
self.previousButton = QtWidgets.QPushButton(self.centralwidget)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
@ -150,6 +152,7 @@ class Ui_MainWindow(object):
|
|||||||
self.hLayoutControls.addWidget(self.nextButton)
|
self.hLayoutControls.addWidget(self.nextButton)
|
||||||
self.verticalLayout_3.addLayout(self.hLayoutControls)
|
self.verticalLayout_3.addLayout(self.hLayoutControls)
|
||||||
self.hLayoutControls2 = QtWidgets.QHBoxLayout()
|
self.hLayoutControls2 = QtWidgets.QHBoxLayout()
|
||||||
|
self.hLayoutControls2.setSpacing(6)
|
||||||
self.hLayoutControls2.setObjectName("hLayoutControls2")
|
self.hLayoutControls2.setObjectName("hLayoutControls2")
|
||||||
self.volumeSlider = QtWidgets.QSlider(self.centralwidget)
|
self.volumeSlider = QtWidgets.QSlider(self.centralwidget)
|
||||||
self.volumeSlider.setMaximum(100)
|
self.volumeSlider.setMaximum(100)
|
||||||
@ -226,5 +229,5 @@ class Ui_MainWindow(object):
|
|||||||
self.actionOpenFiles.setText(_translate("MainWindow", "Open file(s)"))
|
self.actionOpenFiles.setText(_translate("MainWindow", "Open file(s)"))
|
||||||
self.actionDeleteDatabase.setText(_translate("MainWindow", "Delete Database"))
|
self.actionDeleteDatabase.setText(_translate("MainWindow", "Delete Database"))
|
||||||
self.actionNewPlaylist.setText(_translate("MainWindow", "New playlist"))
|
self.actionNewPlaylist.setText(_translate("MainWindow", "New playlist"))
|
||||||
from components import AlbumArtGraphicsView, LeftPane, MusicTable
|
from components import AlbumArtGraphicsView, MusicTable, PlaylistsPane
|
||||||
from pyqtgraph import PlotWidget
|
from pyqtgraph import PlotWidget
|
||||||
|
|||||||
4
ui.ui
4
ui.ui
@ -173,7 +173,7 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="LeftPane" name="playlistTreeView"/>
|
<widget class="PlaylistsPane" name="playlistTreeView"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="MusicTable" name="tableView">
|
<widget class="MusicTable" name="tableView">
|
||||||
@ -386,7 +386,7 @@
|
|||||||
<header>components</header>
|
<header>components</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>LeftPane</class>
|
<class>PlaylistsPane</class>
|
||||||
<extends>QTreeView</extends>
|
<extends>QTreeView</extends>
|
||||||
<header>components</header>
|
<header>components</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user