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 PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt, pyqtSignal, QTimer
|
||||||
from components.LyricsWindow import LyricsWindow
|
from components.LyricsWindow import LyricsWindow
|
||||||
|
from components.AddToPlaylistWindow import AddToPlaylistWindow
|
||||||
from utils import add_files_to_library
|
from utils import add_files_to_library
|
||||||
from utils import update_song_in_library
|
from utils import update_song_in_library
|
||||||
from utils import get_id3_tags
|
from utils import get_id3_tags
|
||||||
@ -81,12 +82,11 @@ class MusicTable(QTableView):
|
|||||||
self.model.layoutChanged.connect(self.restore_scroll_position)
|
self.model.layoutChanged.connect(self.restore_scroll_position)
|
||||||
|
|
||||||
def contextMenuEvent(self, event):
|
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)
|
menu = QMenu(self)
|
||||||
# delete song
|
add_to_playlist_action = QAction("Add to playlist", self)
|
||||||
delete_action = QAction("Delete", self)
|
add_to_playlist_action.triggered.connect(self.add_selected_files_to_playlist)
|
||||||
delete_action.triggered.connect(self.delete_songs)
|
menu.addAction(add_to_playlist_action)
|
||||||
menu.addAction(delete_action)
|
|
||||||
# lyrics
|
# lyrics
|
||||||
lyrics_menu = QAction("Lyrics (View/Edit)", self)
|
lyrics_menu = QAction("Lyrics (View/Edit)", self)
|
||||||
lyrics_menu.triggered.connect(self.show_lyrics_menu)
|
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 = QAction("Open in system file manager", self)
|
||||||
open_containing_folder_action.triggered.connect(self.open_directory)
|
open_containing_folder_action.triggered.connect(self.open_directory)
|
||||||
menu.addAction(open_containing_folder_action)
|
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
|
# show
|
||||||
self.set_selected_song_filepath()
|
self.set_selected_song_filepath()
|
||||||
menu.exec_(event.globalPos())
|
menu.exec_(event.globalPos())
|
||||||
@ -133,6 +137,16 @@ class MusicTable(QTableView):
|
|||||||
path = "/".join(filepath)
|
path = "/".join(filepath)
|
||||||
Popen(["xdg-open", path])
|
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):
|
def show_lyrics_menu(self):
|
||||||
"""Shows the lyrics for the currently selected song"""
|
"""Shows the lyrics for the currently selected song"""
|
||||||
selected_song_filepath = self.get_selected_song_filepath()
|
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
|
from PyQt5.QtGui import QFont
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,3 +4,4 @@ from .AudioVisualizer import AudioVisualizer
|
|||||||
from .PreferencesWindow import PreferencesWindow
|
from .PreferencesWindow import PreferencesWindow
|
||||||
from .ErrorDialog import ErrorDialog
|
from .ErrorDialog import ErrorDialog
|
||||||
from .LyricsWindow import LyricsWindow
|
from .LyricsWindow import LyricsWindow
|
||||||
|
from .AddToPlaylistWindow import AddToPlaylistWindow
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import DBA
|
import DBA
|
||||||
from configparser import ConfigParser
|
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 = ConfigParser()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import DBA
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from utils import add_files_to_library, get_id3_tags
|
from utils import add_files_to_library
|
||||||
from utils import safe_get
|
|
||||||
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
@ -10,7 +8,6 @@ config.read("config.ini")
|
|||||||
|
|
||||||
def scan_for_music():
|
def scan_for_music():
|
||||||
root_dir = config.get("directories", "library")
|
root_dir = config.get("directories", "library")
|
||||||
|
|
||||||
# for dirpath, dirnames, filenames ...
|
# for dirpath, dirnames, filenames ...
|
||||||
for _, _, filenames in os.walk(root_dir):
|
for _, _, filenames in os.walk(root_dir):
|
||||||
add_files_to_library(filenames)
|
add_files_to_library(filenames)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user