diff --git a/components/AddToPlaylistWindow.py b/components/AddToPlaylistWindow.py new file mode 100644 index 0000000..f09eb03 --- /dev/null +++ b/components/AddToPlaylistWindow.py @@ -0,0 +1,44 @@ +from PyQt5.QtWidgets import ( + QWidget, + QListWidget, + QFrame, + QVBoxLayout, + QLabel, + QLineEdit, + QPushButton, +) +from PyQt5.QtGui import QFont + + +class AddToPlaylistWindow(QListWidget): + def __init__(self, list_options: dict): + super(AddToPlaylistWindow, self).__init__() + # self.setWindowTitle("Choose") + # self.setMinimumSize(400, 400) + for k, v in list_options: + self.addItem(f"{k} | {v}") + # layout = QVBoxLayout() + # + # label = QLabel("Playlists") + # label.setFont(QFont("Sans", weight=QFont.Bold)) + # layout.addWidget(label) + # layout.addWidget(self) + + # Save button + # save_button = QPushButton("Add") + # save_button.clicked.connect(self.save) + # layout.addWidget(save_button) + self.show() + + def save(self): + # Upcate the config fields + for key in self.input_fields: + for category in self.config.sections(): + if key in self.config[category]: + self.config[category][key] = self.input_fields[key].text() + + # Write the config file + with open("config.ini", "w") as configfile: + self.config.write(configfile) + + self.close() diff --git a/components/MusicTable.py b/components/MusicTable.py index 63c5286..810331b 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -18,6 +18,7 @@ from PyQt5.QtWidgets import ( ) from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt, pyqtSignal, QTimer from components.LyricsWindow import LyricsWindow +from components.AddToPlaylistWindow import AddToPlaylistWindow from utils import add_files_to_library from utils import update_song_in_library from utils import get_id3_tags @@ -81,12 +82,11 @@ class MusicTable(QTableView): self.model.layoutChanged.connect(self.restore_scroll_position) def contextMenuEvent(self, event): - """Show a context menu when you right-click a row""" + """Right-click context menu for rows in Music Table""" menu = QMenu(self) - # delete song - delete_action = QAction("Delete", self) - delete_action.triggered.connect(self.delete_songs) - menu.addAction(delete_action) + add_to_playlist_action = QAction("Add to playlist", self) + add_to_playlist_action.triggered.connect(self.add_selected_files_to_playlist) + menu.addAction(add_to_playlist_action) # lyrics lyrics_menu = QAction("Lyrics (View/Edit)", self) lyrics_menu.triggered.connect(self.show_lyrics_menu) @@ -95,6 +95,10 @@ class MusicTable(QTableView): open_containing_folder_action = QAction("Open in system file manager", self) open_containing_folder_action.triggered.connect(self.open_directory) menu.addAction(open_containing_folder_action) + # delete song + delete_action = QAction("Delete", self) + delete_action.triggered.connect(self.delete_songs) + menu.addAction(delete_action) # show self.set_selected_song_filepath() menu.exec_(event.globalPos()) @@ -133,6 +137,16 @@ class MusicTable(QTableView): path = "/".join(filepath) Popen(["xdg-open", path]) + def add_selected_files_to_playlist(self): + """Opens a playlist choice menu and adds the currently selected files to the chosen playlist""" + playlist_dict = {} + with DBA.DBAccess() as db: + data = db.query("SELECT id, name from playlist", ()) + for row in data: + playlist_dict[row[0][0]] = row[0][1] + playlist_choice_window = AddToPlaylistWindow(playlist_dict) + playlist_choice_window.exec_() + def show_lyrics_menu(self): """Shows the lyrics for the currently selected song""" selected_song_filepath = self.get_selected_song_filepath() diff --git a/components/PreferencesWindow.py b/components/PreferencesWindow.py index 578005b..7c9c035 100644 --- a/components/PreferencesWindow.py +++ b/components/PreferencesWindow.py @@ -1,4 +1,12 @@ -from PyQt5.QtWidgets import QDialog, QFrame, QVBoxLayout, QLabel, QLineEdit, QPushButton +from PyQt5.QtWidgets import ( + QDialog, + QFrame, + QVBoxLayout, + QLabel, + QLineEdit, + QPushButton, + QDial, +) from PyQt5.QtGui import QFont diff --git a/components/__init__.py b/components/__init__.py index 60c5353..96919cf 100644 --- a/components/__init__.py +++ b/components/__init__.py @@ -4,3 +4,4 @@ from .AudioVisualizer import AudioVisualizer from .PreferencesWindow import PreferencesWindow from .ErrorDialog import ErrorDialog from .LyricsWindow import LyricsWindow +from .AddToPlaylistWindow import AddToPlaylistWindow diff --git a/utils/add_files_to_library.py b/utils/add_files_to_library.py index 5200d67..4545cd5 100644 --- a/utils/add_files_to_library.py +++ b/utils/add_files_to_library.py @@ -1,6 +1,6 @@ import DBA from configparser import ConfigParser -from utils import get_id3_tags, id3_timestamp_to_datetime, safe_get +from utils import get_id3_tags, id3_timestamp_to_datetime config = ConfigParser() config.read("config.ini") diff --git a/utils/scan_for_music.py b/utils/scan_for_music.py index 1462095..330c35d 100644 --- a/utils/scan_for_music.py +++ b/utils/scan_for_music.py @@ -1,8 +1,6 @@ import os -import DBA from configparser import ConfigParser -from utils import add_files_to_library, get_id3_tags -from utils import safe_get +from utils import add_files_to_library config = ConfigParser() config.read("config.ini") @@ -10,7 +8,6 @@ config.read("config.ini") def scan_for_music(): root_dir = config.get("directories", "library") - # for dirpath, dirnames, filenames ... for _, _, filenames in os.walk(root_dir): add_files_to_library(filenames)