playlist choice component qlistwidget functional?
This commit is contained in:
parent
863c3d417b
commit
2da146ff8c
44
components/AddToPlaylistWindow.py
Normal file
44
components/AddToPlaylistWindow.py
Normal file
@ -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()
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -4,3 +4,4 @@ from .AudioVisualizer import AudioVisualizer
|
||||
from .PreferencesWindow import PreferencesWindow
|
||||
from .ErrorDialog import ErrorDialog
|
||||
from .LyricsWindow import LyricsWindow
|
||||
from .AddToPlaylistWindow import AddToPlaylistWindow
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user