preparation for reorganization function
This commit is contained in:
parent
ca5b9ad849
commit
6daadb09aa
@ -1,12 +1,12 @@
|
||||
import DBA
|
||||
from PyQt5.QtGui import QStandardItem, QStandardItemModel
|
||||
from PyQt5.QtWidgets import QTableView
|
||||
from PyQt5.QtCore import QTimer, Qt, pyqtSignal
|
||||
from tinytag import TinyTag
|
||||
from PyQt5.QtGui import QStandardItem, QStandardItemModel, QKeySequence
|
||||
from PyQt5.QtWidgets import QTableView, QShortcut
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from utils import add_files_to_library
|
||||
from utils import get_id3_tags
|
||||
from utils import get_album_art
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
|
||||
class MusicTable(QTableView):
|
||||
@ -19,12 +19,32 @@ class MusicTable(QTableView):
|
||||
self.selected_song_filepath = None
|
||||
self.current_song_filepath = None
|
||||
self.qapp = None
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read('config.ini')
|
||||
# self.tableView.resizeColumnsToContents()
|
||||
self.clicked.connect(self.set_selected_song_filepath)
|
||||
# doubleClicked is a built in event for QTableView - we listen for this event and run set_current_song_filepath
|
||||
self.doubleClicked.connect(self.set_current_song_filepath)
|
||||
self.enterKey.connect(self.set_current_song_filepath)
|
||||
self.fetch_library()
|
||||
self.setup_keyboard_shortcuts()
|
||||
|
||||
def setup_keyboard_shortcuts(self):
|
||||
"""Setup shortcuts here"""
|
||||
shortcut = QShortcut(QKeySequence("Ctrl+Shift+R"), self)
|
||||
shortcut.activated.connect(self.reorganize_selected_files)
|
||||
|
||||
def reorganize_selected_files(self):
|
||||
"""Ctrl+Shift+R = Reorganize"""
|
||||
filepaths = self.get_selected_songs_filepaths()
|
||||
# right now this just prints the filepaths to the songs obv.
|
||||
print(f'yay: {filepaths}')
|
||||
# TODO
|
||||
# Get user confirmation screen (default yes, so i can press enter and go)
|
||||
# Get target directory
|
||||
# Copy files to new dir
|
||||
# delete files from current dir
|
||||
# add new files to library
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
"""Press a key. Do a thing"""
|
||||
@ -52,13 +72,6 @@ class MusicTable(QTableView):
|
||||
self.set_current_song_filepath()
|
||||
self.playPauseSignal.emit()
|
||||
|
||||
def get_selected_rows(self):
|
||||
"""Returns a list of indexes for every selected row"""
|
||||
rows = []
|
||||
for idx in self.selectionModel().siblingAtColumn():
|
||||
rows.append(idx.row())
|
||||
return rows
|
||||
|
||||
def set_selected_song_filepath(self):
|
||||
"""Sets the filepath of the currently selected song"""
|
||||
self.selected_song_filepath = self.currentIndex().siblingAtColumn(self.headers.index('path')).data()
|
||||
@ -71,6 +84,24 @@ class MusicTable(QTableView):
|
||||
self.current_song_filepath = self.currentIndex().siblingAtColumn(self.headers.index('path')).data()
|
||||
print(f'Current song: {self.current_song_filepath}')
|
||||
|
||||
def get_selected_rows(self):
|
||||
"""Returns a list of indexes for every selected row"""
|
||||
selection_model = self.selectionModel()
|
||||
return [index.row() for index in selection_model.selectedRows()]
|
||||
# rows = []
|
||||
# for idx in self.selectionModel().siblingAtColumn():
|
||||
# rows.append(idx.row())
|
||||
# return rows
|
||||
|
||||
def get_selected_songs_filepaths(self):
|
||||
"""Returns a list of the filepaths for the currently selected songs"""
|
||||
selected_rows = self.get_selected_rows()
|
||||
filepaths = []
|
||||
for row in selected_rows:
|
||||
idx = self.model.index(row, self.headers.index('path'))
|
||||
filepaths.append(idx.data())
|
||||
return filepaths
|
||||
|
||||
def get_selected_song_filepath(self):
|
||||
"""Returns the selected songs filepath"""
|
||||
return self.selected_song_filepath
|
||||
@ -91,7 +122,6 @@ class MusicTable(QTableView):
|
||||
"""Returns the APIC data (album art lol) for the currently playing song"""
|
||||
return get_album_art(self.current_song_filepath)
|
||||
|
||||
|
||||
def fetch_library(self):
|
||||
"""Initialize the tableview model"""
|
||||
self.model = QStandardItemModel()
|
||||
@ -118,10 +148,8 @@ class MusicTable(QTableView):
|
||||
if number_of_files_added:
|
||||
self.fetch_library()
|
||||
|
||||
|
||||
def load_qapp(self, qapp):
|
||||
# why was this necessary again? :thinking:
|
||||
self.qapp = qapp
|
||||
|
||||
|
||||
|
||||
|
||||
15
main.py
15
main.py
@ -1,5 +1,6 @@
|
||||
from ui import Ui_MainWindow
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QGraphicsScene, QHeaderView, QGraphicsPixmapItem
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QGraphicsScene, \
|
||||
QHeaderView, QGraphicsPixmapItem
|
||||
import qdarktheme
|
||||
from PyQt5.QtCore import QUrl, QTimer, QEvent, Qt
|
||||
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent, QAudioProbe
|
||||
@ -14,6 +15,7 @@ import configparser
|
||||
# Create ui.py file from Qt Designer
|
||||
# pyuic5 ui.ui -o ui.py
|
||||
|
||||
|
||||
class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, qapp):
|
||||
super(ApplicationWindow, self).__init__()
|
||||
@ -29,10 +31,8 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.tableView.load_qapp(self.qapp)
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read('config.ini')
|
||||
|
||||
global stopped
|
||||
stopped = False
|
||||
|
||||
# Initialization
|
||||
self.player = QMediaPlayer() # Audio player
|
||||
self.probe = QAudioProbe() # Get audio data
|
||||
@ -41,7 +41,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.audio_visualizer = AudioVisualizer(self.player)
|
||||
self.current_volume = 50
|
||||
self.player.setVolume(self.current_volume)
|
||||
|
||||
# Audio probe for processing audio signal in real time
|
||||
# Provides faster updates than move_slider
|
||||
self.probe.setSource(self.player)
|
||||
@ -56,7 +55,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.PlotWidget.setYRange(0,0.3,padding=0) # y axis range
|
||||
self.PlotWidget.getAxis('bottom').setTicks([]) # Remove x-axis ticks
|
||||
self.PlotWidget.getAxis('bottom').setLabel('') # Remove x-axis label
|
||||
self.PlotWidget.setLogMode(False,False)
|
||||
self.PlotWidget.setLogMode(False, False)
|
||||
# Remove y-axis labels and decorations
|
||||
self.PlotWidget.getAxis('left').setTicks([]) # Remove y-axis ticks
|
||||
self.PlotWidget.getAxis('left').setLabel('') # Remove y-axis label
|
||||
@ -80,7 +79,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.tableView.playPauseSignal.connect(self.on_play_clicked) # Spacebar toggle play/pause signal
|
||||
self.tableView.viewport().installEventFilter(self) # for drag & drop functionality
|
||||
# self.tableView.model.layoutChanged()
|
||||
### set column widths
|
||||
# set column widths
|
||||
table_view_column_widths = str(self.config['table']['column_widths']).split(',')
|
||||
for i in range(self.tableView.model.columnCount()):
|
||||
self.tableView.setColumnWidth(i, int(table_view_column_widths[i]))
|
||||
@ -88,7 +87,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
self.tableView.horizontalHeader().setStretchLastSection(False)
|
||||
|
||||
|
||||
def eventFilter(self, source, event):
|
||||
"""Handles events"""
|
||||
# tableView (drag & drop)
|
||||
@ -238,6 +236,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
def actionPreferencesClicked(self):
|
||||
preferences_window = PreferencesWindow(self.config)
|
||||
preferences_window.exec_() # Display the preferences window modally
|
||||
|
||||
def scan_libraries(self):
|
||||
scan_for_music()
|
||||
self.tableView.fetch_library()
|
||||
@ -251,8 +250,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.update_audio_visualization()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user