reorganize stuff and make playlist stuff better sql and getting rid of linter errors with better code stuff
This commit is contained in:
parent
1c8a2f38c3
commit
7e7302528b
@ -5,15 +5,17 @@ from PyQt5.QtWidgets import (
|
||||
QLabel,
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
QCheckBox,
|
||||
)
|
||||
from PyQt5.QtGui import QFont
|
||||
|
||||
|
||||
|
||||
class EditPlaylistOptionsWindow(QDialog):
|
||||
def __init__(self, playlist_id):
|
||||
super(EditPlaylistOptionsWindow, self).__init__()
|
||||
self.setWindowTitle("Playlist options")
|
||||
self.setMinimumSize(600, 400)
|
||||
# self.setMinimumSize(600, 400)
|
||||
self.playlist_id = playlist_id
|
||||
# self.playlist_path_prefix: str = self.config.get(
|
||||
# "settings", "playlist_path_prefix"
|
||||
@ -35,14 +37,21 @@ class EditPlaylistOptionsWindow(QDialog):
|
||||
|
||||
# Get options from db
|
||||
with DBA.DBAccess() as db:
|
||||
data = db.query("SELECT auto_export_path, path_prefix from playlist WHERE id = ?;", (self.playlist_id,))
|
||||
data = db.query("SELECT auto_export_path, path_prefix, auto_export from playlist WHERE id = ?;", (self.playlist_id,))
|
||||
auto_export_path = data[0][0]
|
||||
path_prefix = data[0][1]
|
||||
auto_export = data[0][2]
|
||||
|
||||
self.checkbox = QCheckBox(text="Auto export?")
|
||||
self.checkbox.setChecked(auto_export)
|
||||
layout.addWidget(self.checkbox)
|
||||
|
||||
# Relative export path label
|
||||
label = QLabel("Auto export path (../music/playlists/my_playlist.m3u)")
|
||||
label.setFont(QFont("Sans", weight=QFont.Bold)) # bold category
|
||||
label.setStyleSheet("text-transform:lowercase;") # uppercase category
|
||||
label = QLabel("Export to file:")
|
||||
label.setFont(QFont("Sans", weight=QFont.Bold))
|
||||
layout.addWidget(label)
|
||||
label = QLabel('i.e.: ../music/playlists/my-playlist.m3u')
|
||||
label.setFont(QFont("Serif", weight=QFont.Style.StyleItalic)) # bold category
|
||||
layout.addWidget(label)
|
||||
|
||||
# Relative export path line edit widget
|
||||
@ -50,9 +59,11 @@ class EditPlaylistOptionsWindow(QDialog):
|
||||
layout.addWidget(self.auto_export_path)
|
||||
|
||||
# Playlist file save path label
|
||||
label = QLabel("Path prefix (/prefix/song.mp3, /prefix/song2.mp3)")
|
||||
label = QLabel("Path prefix")
|
||||
label.setFont(QFont("Sans", weight=QFont.Bold))
|
||||
label.setStyleSheet("text-transform:lowercase;")
|
||||
layout.addWidget(label)
|
||||
label = QLabel("i.e.: /prefix/song.mp3")
|
||||
label.setFont(QFont("Serif", weight=QFont.Style.StyleItalic)) # bold category
|
||||
layout.addWidget(label)
|
||||
|
||||
# Playlist file save path line edit widget
|
||||
@ -73,10 +84,12 @@ class EditPlaylistOptionsWindow(QDialog):
|
||||
"""
|
||||
with DBA.DBAccess() as db:
|
||||
db.execute('''
|
||||
UPDATE playlist SET auto_export_path = ?, path_prefix = ? WHERE id = ?
|
||||
''', (self.auto_export_path.text(), self.path_prefix.text(), self.playlist_id)
|
||||
UPDATE playlist SET auto_export_path = ?, path_prefix = ?, auto_export = ? WHERE id = ?
|
||||
''', (self.auto_export_path.text(),
|
||||
self.path_prefix.text(),
|
||||
self.checkbox.isChecked(),
|
||||
self.playlist_id)
|
||||
)
|
||||
|
||||
self.close()
|
||||
return
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialog,
|
||||
QListWidgetItem,
|
||||
@ -9,7 +9,6 @@ from PyQt5.QtWidgets import (
|
||||
QHBoxLayout,
|
||||
QListWidget,
|
||||
QWidget,
|
||||
QDial,
|
||||
QStyle,
|
||||
)
|
||||
from logging import debug
|
||||
@ -20,11 +19,12 @@ from appdirs import user_config_dir
|
||||
|
||||
|
||||
class PreferencesWindow(QDialog):
|
||||
def __init__(self, reloadConfigSignal, reloadDatabaseSignal):
|
||||
reloadConfigSignal = pyqtSignal()
|
||||
reloadDatabaseSignal = pyqtSignal()
|
||||
|
||||
def __init__(self):
|
||||
super(PreferencesWindow, self).__init__()
|
||||
# Config
|
||||
self.reloadConfigSignal = reloadConfigSignal
|
||||
self.reloadDatabaseSignal = reloadDatabaseSignal
|
||||
self.setWindowTitle("Preferences")
|
||||
self.setMinimumSize(800, 600)
|
||||
self.cfg_file = (
|
||||
@ -74,14 +74,13 @@ class PreferencesWindow(QDialog):
|
||||
self.clear_layout(self.content_layout)
|
||||
|
||||
# Edit toggle button
|
||||
edit_button = QPushButton()
|
||||
self.edit_button: QPushButton = edit_button
|
||||
self.edit_button = QPushButton()
|
||||
self.edit_button.setText("view mode")
|
||||
self.edit_button.clicked.connect(self.on_edit_toggled)
|
||||
self.content_layout.addWidget(edit_button)
|
||||
self.content_layout.addWidget(self.edit_button)
|
||||
|
||||
# dict of text input fields
|
||||
self.input_fields: dict[str, QLineEdit] = {}
|
||||
self.input_fields = {}
|
||||
if isinstance(item, str):
|
||||
self.current_category_str = item
|
||||
else:
|
||||
|
||||
14
main.py
14
main.py
@ -2,7 +2,6 @@ import os
|
||||
import sys
|
||||
import logging
|
||||
from PyQt5 import QtCore
|
||||
import qdarktheme
|
||||
import typing
|
||||
import DBA
|
||||
from subprocess import run
|
||||
@ -31,7 +30,6 @@ from PyQt5.QtCore import (
|
||||
QSize,
|
||||
QUrl,
|
||||
QTimer,
|
||||
pyqtSignal,
|
||||
QThreadPool,
|
||||
)
|
||||
from PyQt5.QtMultimedia import (
|
||||
@ -70,9 +68,6 @@ from utils.export_playlist_by_id import export_playlist_by_id
|
||||
|
||||
|
||||
class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
reloadConfigSignal: pyqtSignal = pyqtSignal()
|
||||
reloadDatabaseSignal: pyqtSignal = pyqtSignal()
|
||||
|
||||
def __init__(self, clipboard):
|
||||
super(ApplicationWindow, self).__init__()
|
||||
self.clipboard = clipboard
|
||||
@ -257,7 +252,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
# auto export any playlists that want it
|
||||
try:
|
||||
with DBA.DBAccess() as db:
|
||||
result = db.query('SELECT id FROM playlist WHERE auto_export_path IS NOT NULL;', ())
|
||||
result = db.query('SELECT id FROM playlist WHERE auto_export = true;', ())
|
||||
ids = [id[0] for id in result]
|
||||
for id in ids:
|
||||
export_playlist_by_id(id)
|
||||
@ -446,7 +441,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
filepath default value = `tableView.current_song_filepath`
|
||||
"""
|
||||
print("play audio file")
|
||||
if not filepath:
|
||||
filepath = self.tableView.get_selected_song_filepath()
|
||||
metadata = id3_remap(get_tags(filepath)[0])
|
||||
@ -588,9 +582,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def open_preferences(self) -> None:
|
||||
"""Opens the preferences window"""
|
||||
preferences_window = PreferencesWindow(
|
||||
self.reloadConfigSignal, self.reloadDatabaseSignal
|
||||
)
|
||||
preferences_window = PreferencesWindow()
|
||||
preferences_window.reloadConfigSignal.connect(self.load_config)
|
||||
preferences_window.reloadDatabaseSignal.connect(self.tableView.load_music_table)
|
||||
preferences_window.exec_() # Display the preferences window modally
|
||||
@ -744,7 +736,7 @@ if __name__ == "__main__":
|
||||
clipboard = app.clipboard()
|
||||
# Dark theme >:3
|
||||
# qdarktheme.setup_theme()
|
||||
qdarktheme.setup_theme("auto") # this is supposed to work but doesnt
|
||||
# qdarktheme.setup_theme("auto") # this is supposed to work but doesnt
|
||||
# Show the UI
|
||||
ui = ApplicationWindow(clipboard)
|
||||
# window size
|
||||
|
||||
@ -23,6 +23,7 @@ CREATE TABLE playlist(
|
||||
id integer primary key,
|
||||
name varchar(64),
|
||||
date_created TIMESTAMP default CURRENT_TIMESTAMP,
|
||||
auto_export boolean default 0,
|
||||
auto_export_path varchar(512),
|
||||
path_prefix varchar(255)
|
||||
);
|
||||
@ -4,7 +4,7 @@ from logging import debug
|
||||
|
||||
def delete_and_create_library_database():
|
||||
"""Clears all songs in database"""
|
||||
with open("utils/delete_and_create_library.sql", "r") as file:
|
||||
with open("sql/delete_and_create_library.sql", "r") as file:
|
||||
lines = file.read()
|
||||
for statement in lines.split(";"):
|
||||
debug(f"executing [{statement}]")
|
||||
|
||||
@ -27,6 +27,10 @@ def export_playlist_by_id(playlist_db_id: int) -> bool:
|
||||
if not path_prefix:
|
||||
path_prefix = ""
|
||||
|
||||
# If the path is nothing, just stop
|
||||
if not auto_export_path:
|
||||
return False
|
||||
|
||||
# Get filepaths for selected playlist from the database
|
||||
try:
|
||||
with DBA.DBAccess() as db:
|
||||
|
||||
@ -5,7 +5,7 @@ from logging import debug
|
||||
def initialize_db():
|
||||
"""Recreates everything in the database"""
|
||||
with DBA.DBAccess() as db:
|
||||
with open("utils/init.sql", "r") as file:
|
||||
with open("sql/init.sql", "r") as file:
|
||||
lines = file.read()
|
||||
for statement in lines.split(";"):
|
||||
debug(f"executing [{statement}]")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user