cleanup
This commit is contained in:
parent
b2406d2cbe
commit
82c2bd470f
@ -1,6 +1,5 @@
|
|||||||
import logging
|
from logging import error
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ class CreatePlaylistWindow(QDialog):
|
|||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
db.execute("INSERT INTO playlist (name) VALUES (?);", (value,))
|
db.execute("INSERT INTO playlist (name) VALUES (?);", (value,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(
|
error(
|
||||||
f"CreatePlaylistWindow.py save() | Could not create playlist: {e}"
|
f"CreatePlaylistWindow.py save() | Could not create playlist: {e}"
|
||||||
)
|
)
|
||||||
self.playlistCreatedSignal.emit()
|
self.playlistCreatedSignal.emit()
|
||||||
|
|||||||
@ -2,12 +2,8 @@ from PyQt5.QtWidgets import (
|
|||||||
QDialog,
|
QDialog,
|
||||||
QPlainTextEdit,
|
QPlainTextEdit,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QLabel,
|
|
||||||
QPushButton,
|
|
||||||
)
|
)
|
||||||
from PyQt5.QtGui import QFont
|
from pprint import pformat
|
||||||
from components.ErrorDialog import ErrorDialog
|
|
||||||
from utils import set_id3_tag
|
|
||||||
|
|
||||||
|
|
||||||
class DebugWindow(QDialog):
|
class DebugWindow(QDialog):
|
||||||
@ -20,7 +16,7 @@ class DebugWindow(QDialog):
|
|||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
# Labels & input fields
|
# Labels & input fields
|
||||||
self.input_field = QPlainTextEdit(self.text)
|
self.input_field = QPlainTextEdit(pformat(self.text))
|
||||||
layout.addWidget(self.input_field)
|
layout.addWidget(self.input_field)
|
||||||
|
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from mutagen.id3 import ID3
|
from mutagen.id3 import ID3
|
||||||
|
from json import load as jsonload
|
||||||
import DBA
|
import DBA
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QDragMoveEvent,
|
QDragMoveEvent,
|
||||||
@ -195,8 +196,10 @@ class MusicTable(QTableView):
|
|||||||
col_count = self.model2.columnCount()
|
col_count = self.model2.columnCount()
|
||||||
qtableview_width = self.size().width()
|
qtableview_width = self.size().width()
|
||||||
sum_of_cols = self.horizontal_header.length()
|
sum_of_cols = self.horizontal_header.length()
|
||||||
|
debug(f'qtable_width: {qtableview_width}')
|
||||||
|
debug(f'sum of cols: {sum_of_cols}')
|
||||||
|
|
||||||
if sum != qtableview_width:
|
if sum_of_cols <= qtableview_width:
|
||||||
# if not the last header
|
# if not the last header
|
||||||
if logicalIndex < (col_count):
|
if logicalIndex < (col_count):
|
||||||
next_header_size = self.horizontal_header.sectionSize(logicalIndex + 1)
|
next_header_size = self.horizontal_header.sectionSize(logicalIndex + 1)
|
||||||
@ -544,12 +547,11 @@ class MusicTable(QTableView):
|
|||||||
self.set_current_song_filepath()
|
self.set_current_song_filepath()
|
||||||
self.playPauseSignal.emit()
|
self.playPauseSignal.emit()
|
||||||
|
|
||||||
def add_files(self, files) -> None:
|
def add_files(self, files: list[str]) -> None:
|
||||||
"""Thread handles adding songs to library
|
"""Spawns a worker thread - adds a list of filepaths to the library
|
||||||
- Drag & Drop song(s) on tableView
|
- Drag & Drop song(s) on tableView
|
||||||
- File > Open > List of song(s)
|
- File > Open > List of song(s)
|
||||||
"""
|
"""
|
||||||
debug(f"add files, files: {files}")
|
|
||||||
worker = Worker(add_files_to_library, files)
|
worker = Worker(add_files_to_library, files)
|
||||||
worker.signals.signal_progress.connect(self.qapp.handle_progress)
|
worker.signals.signal_progress.connect(self.qapp.handle_progress)
|
||||||
worker.signals.signal_finished.connect(self.load_music_table)
|
worker.signals.signal_finished.connect(self.load_music_table)
|
||||||
@ -695,6 +697,7 @@ class MusicTable(QTableView):
|
|||||||
|
|
||||||
def set_current_song_filepath(self) -> None:
|
def set_current_song_filepath(self) -> None:
|
||||||
"""Sets the filepath of the currently playing song"""
|
"""Sets the filepath of the currently playing song"""
|
||||||
|
# NOTE:
|
||||||
# Setting the current song filepath automatically plays that song
|
# Setting the current song filepath automatically plays that song
|
||||||
# self.tableView listens to this function and plays the audio file located at self.current_song_filepath
|
# self.tableView listens to this function and plays the audio file located at self.current_song_filepath
|
||||||
self.current_song_filepath = (
|
self.current_song_filepath = (
|
||||||
|
|||||||
@ -18,8 +18,8 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
library_root = QTreeWidgetItem(["Library"])
|
library_root = QTreeWidgetItem(["Library"])
|
||||||
self.addTopLevelItem(library_root)
|
self.addTopLevelItem(library_root)
|
||||||
all_songs_branch = QTreeWidgetItem(["All Songs"])
|
# all_songs_branch = QTreeWidgetItem(["All Songs"])
|
||||||
library_root.addChild(all_songs_branch)
|
# library_root.addChild(all_songs_branch)
|
||||||
|
|
||||||
self.playlists_root = QTreeWidgetItem(["Playlists"])
|
self.playlists_root = QTreeWidgetItem(["Playlists"])
|
||||||
self.addTopLevelItem(self.playlists_root)
|
self.addTopLevelItem(self.playlists_root)
|
||||||
@ -36,17 +36,22 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
self.playlist_db_id_choice: int | None = None
|
self.playlist_db_id_choice: int | None = None
|
||||||
|
|
||||||
def playlist_clicked(self, item):
|
def playlist_clicked(self, item):
|
||||||
|
"""Specific playlist index was clicked"""
|
||||||
if isinstance(item, PlaylistWidgetItem):
|
if isinstance(item, PlaylistWidgetItem):
|
||||||
debug(f"ID: {item.id}, name: {item.text(0)}")
|
debug(f"ID: {item.id}, name: {item.text(0)}")
|
||||||
self.playlist_db_id_choice = item.id
|
self.playlist_db_id_choice = item.id
|
||||||
self.playlistChoiceSignal.emit(int(item.id))
|
self.playlistChoiceSignal.emit(int(item.id))
|
||||||
elif item.text(0).lower() == "all songs":
|
elif item.text(0).lower() == "library":
|
||||||
self.all_songs_selected()
|
self.all_songs_selected()
|
||||||
|
|
||||||
def all_songs_selected(self):
|
def all_songs_selected(self):
|
||||||
|
"""Emits a signal to display all songs in the library"""
|
||||||
|
# I have no idea why this has to be in its own function, but it does
|
||||||
|
# or else it doesn't work
|
||||||
self.allSongsSignal.emit()
|
self.allSongsSignal.emit()
|
||||||
|
|
||||||
def add_latest_playlist_to_tree(self):
|
def add_latest_playlist_to_tree(self):
|
||||||
|
"""Adds the most recently created playlist to the pane"""
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
playlist = db.query(
|
playlist = db.query(
|
||||||
"SELECT id, name FROM playlist ORDER BY date_created DESC LIMIT 1;", ()
|
"SELECT id, name FROM playlist ORDER BY date_created DESC LIMIT 1;", ()
|
||||||
|
|||||||
@ -93,7 +93,8 @@ class PreferencesWindow(QDialog):
|
|||||||
child.widget().deleteLater()
|
child.widget().deleteLater()
|
||||||
|
|
||||||
def save_preferences(self):
|
def save_preferences(self):
|
||||||
info("im saving")
|
# FIXME: this isnt working? at least not for database
|
||||||
|
|
||||||
# Upcate the config fields
|
# Upcate the config fields
|
||||||
for key in self.input_fields:
|
for key in self.input_fields:
|
||||||
for category in self.config.sections():
|
for category in self.config.sections():
|
||||||
|
|||||||
2
main.py
2
main.py
@ -492,7 +492,7 @@ 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"""
|
||||||
window = CreatePlaylistWindow(self.playlistCreatedSignal)
|
window = CreatePlaylistWindow(self.playlistCreatedSignal)
|
||||||
window.playlistCreatedSignal.connect(self.add_latest_playlist_to_tree)
|
window.playlistCreatedSignal.connect(self.add_latest_playlist_to_tree) # type: ignore
|
||||||
window.exec_()
|
window.exec_()
|
||||||
|
|
||||||
def import_playlist(self) -> None:
|
def import_playlist(self) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user