refresh playlist pane on new playlist added
This commit is contained in:
parent
a30054b6dc
commit
08a4b7fce3
@ -1,11 +1,13 @@
|
|||||||
import logging
|
import logging
|
||||||
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout
|
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QLineEdit, QPushButton, QVBoxLayout
|
||||||
|
from PyQt5.QtCore import pyqtSignal
|
||||||
import DBA
|
import DBA
|
||||||
|
|
||||||
|
|
||||||
class CreatePlaylistWindow(QDialog):
|
class CreatePlaylistWindow(QDialog):
|
||||||
def __init__(self):
|
def __init__(self, playlistCreatedSignal):
|
||||||
super(CreatePlaylistWindow, self).__init__()
|
super(CreatePlaylistWindow, self).__init__()
|
||||||
|
self.playlistCreatedSignal = playlistCreatedSignal
|
||||||
self.setWindowTitle("Create new playlist")
|
self.setWindowTitle("Create new playlist")
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
button_layout = QHBoxLayout()
|
button_layout = QHBoxLayout()
|
||||||
@ -38,6 +40,7 @@ class CreatePlaylistWindow(QDialog):
|
|||||||
logging.error(
|
logging.error(
|
||||||
f"CreatePlaylistWindow.py save() | Could not create playlist: {e}"
|
f"CreatePlaylistWindow.py save() | Could not create playlist: {e}"
|
||||||
)
|
)
|
||||||
|
self.playlistCreatedSignal.emit()
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def cancel(self) -> None:
|
def cancel(self) -> None:
|
||||||
|
|||||||
@ -179,7 +179,6 @@ class MusicTable(QTableView):
|
|||||||
Popen(["xdg-open", path])
|
Popen(["xdg-open", path])
|
||||||
|
|
||||||
def edit_selected_files_metadata(self):
|
def edit_selected_files_metadata(self):
|
||||||
# FIXME:
|
|
||||||
"""Opens a form with metadata from the selected audio files"""
|
"""Opens a form with metadata from the selected audio files"""
|
||||||
files = self.get_selected_songs_filepaths()
|
files = self.get_selected_songs_filepaths()
|
||||||
song_ids = self.get_selected_songs_db_ids()
|
song_ids = self.get_selected_songs_db_ids()
|
||||||
|
|||||||
@ -20,16 +20,16 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
all_songs_branch = QTreeWidgetItem(["All Songs"])
|
all_songs_branch = QTreeWidgetItem(["All Songs"])
|
||||||
library_root.addChild(all_songs_branch)
|
library_root.addChild(all_songs_branch)
|
||||||
|
|
||||||
playlists_root = QTreeWidgetItem(["Playlists"])
|
self.playlists_root = QTreeWidgetItem(["Playlists"])
|
||||||
self.addTopLevelItem(playlists_root)
|
self.addTopLevelItem(self.playlists_root)
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
playlists = db.query("SELECT id, name FROM playlist;", ())
|
playlists = db.query("SELECT id, name FROM playlist;", ())
|
||||||
for playlist in playlists:
|
for playlist in playlists:
|
||||||
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
||||||
playlists_root.addChild(branch)
|
self.playlists_root.addChild(branch)
|
||||||
|
|
||||||
library_root.setExpanded(True)
|
library_root.setExpanded(True)
|
||||||
playlists_root.setExpanded(True)
|
self.playlists_root.setExpanded(True)
|
||||||
|
|
||||||
self.currentItemChanged.connect(self.playlist_clicked)
|
self.currentItemChanged.connect(self.playlist_clicked)
|
||||||
self.playlist_db_id_choice: int | None = None
|
self.playlist_db_id_choice: int | None = None
|
||||||
@ -44,3 +44,11 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
|
|
||||||
def all_songs_selected(self):
|
def all_songs_selected(self):
|
||||||
self.allSongsSignal.emit()
|
self.allSongsSignal.emit()
|
||||||
|
|
||||||
|
def add_latest_playlist_to_tree(self):
|
||||||
|
with DBA.DBAccess() as db:
|
||||||
|
playlist = db.query(
|
||||||
|
"SELECT id, name FROM playlist ORDER BY date_created DESC LIMIT 1;", ()
|
||||||
|
)[0]
|
||||||
|
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
||||||
|
self.playlists_root.addChild(branch)
|
||||||
|
|||||||
15
main.py
15
main.py
@ -20,7 +20,7 @@ from PyQt5.QtWidgets import (
|
|||||||
QGraphicsPixmapItem,
|
QGraphicsPixmapItem,
|
||||||
QMessageBox,
|
QMessageBox,
|
||||||
)
|
)
|
||||||
from PyQt5.QtCore import QUrl, QTimer, Qt
|
from PyQt5.QtCore import QUrl, QTimer, Qt, pyqtSignal
|
||||||
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent, QAudioProbe
|
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent, QAudioProbe
|
||||||
from PyQt5.QtGui import QCloseEvent, QPixmap
|
from PyQt5.QtGui import QCloseEvent, QPixmap
|
||||||
from utils import scan_for_music, delete_and_create_library_database, initialize_db
|
from utils import scan_for_music, delete_and_create_library_database, initialize_db
|
||||||
@ -36,6 +36,8 @@ from components import (
|
|||||||
|
|
||||||
|
|
||||||
class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||||
|
playlistCreatedSignal = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, qapp):
|
def __init__(self, qapp):
|
||||||
super(ApplicationWindow, self).__init__()
|
super(ApplicationWindow, self).__init__()
|
||||||
global stopped
|
global stopped
|
||||||
@ -79,7 +81,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
self.PlotWidget.getAxis("left").setLabel("") # Remove y-axis label
|
self.PlotWidget.getAxis("left").setLabel("") # Remove y-axis label
|
||||||
|
|
||||||
# Playlist left-pane
|
# Playlist left-pane
|
||||||
self.playlistTreeView
|
# self.playlistTreeView
|
||||||
|
|
||||||
# Connections
|
# Connections
|
||||||
self.playbackSlider.sliderReleased.connect(
|
self.playbackSlider.sliderReleased.connect(
|
||||||
@ -357,8 +359,13 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
def create_playlist(self) -> None:
|
def create_playlist(self) -> None:
|
||||||
"""Creates a database record for a playlist, given a name"""
|
"""Creates a database record for a playlist, given a name"""
|
||||||
create_playlist_window = CreatePlaylistWindow()
|
window = CreatePlaylistWindow(self.playlistCreatedSignal)
|
||||||
create_playlist_window.exec_()
|
window.playlistCreatedSignal.connect(self.add_latest_playlist_to_tree)
|
||||||
|
window.exec_()
|
||||||
|
|
||||||
|
def add_latest_playlist_to_tree(self) -> None:
|
||||||
|
"""Refreshes the playlist tree"""
|
||||||
|
self.playlistTreeView.add_latest_playlist_to_tree()
|
||||||
|
|
||||||
def import_playlist(self) -> None:
|
def import_playlist(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user