refactor musictable drag and drop into its own class
This commit is contained in:
parent
bb6725f3a3
commit
b9c045574c
@ -1,6 +1,6 @@
|
||||
from mutagen.easyid3 import EasyID3
|
||||
import DBA
|
||||
from PyQt5.QtGui import QStandardItem, QStandardItemModel, QKeySequence
|
||||
from PyQt5.QtGui import QStandardItem, QStandardItemModel, QKeySequence, QDragEnterEvent, QDropEvent
|
||||
from PyQt5.QtWidgets import QTableView, QShortcut, QMessageBox, QAbstractItemView
|
||||
from PyQt5.QtCore import QModelIndex, Qt, pyqtSignal, QTimer
|
||||
from utils import add_files_to_library
|
||||
@ -42,6 +42,32 @@ class MusicTable(QTableView):
|
||||
self.model.layoutChanged.connect(self.restore_scroll_position)
|
||||
|
||||
|
||||
def dragEnterEvent(self, event: QDragEnterEvent):
|
||||
if event.mimeData().hasUrls():
|
||||
event.accept()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
|
||||
def dragMoveEvent(self, event: QDragEnterEvent):
|
||||
if event.mimeData().hasUrls():
|
||||
event.accept()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
|
||||
def dropEvent(self, event: QDropEvent):
|
||||
if event.mimeData().hasUrls():
|
||||
files = []
|
||||
for url in event.mimeData().urls():
|
||||
if url.isLocalFile():
|
||||
files.append(url.path())
|
||||
self.add_files(files)
|
||||
event.accept()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
|
||||
def setup_keyboard_shortcuts(self):
|
||||
"""Setup shortcuts here"""
|
||||
shortcut = QShortcut(QKeySequence("Ctrl+Shift+R"), self)
|
||||
|
||||
19
main.py
19
main.py
@ -86,23 +86,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)
|
||||
if (source is self.tableView.viewport() and
|
||||
(event.type() == QEvent.DragEnter or
|
||||
event.type() == QEvent.DragMove or
|
||||
event.type() == QEvent.Drop) and
|
||||
event.mimeData().hasUrls()):
|
||||
files = []
|
||||
if event.type() == QEvent.Drop:
|
||||
for url in event.mimeData().urls():
|
||||
if url.isLocalFile():
|
||||
files.append(url.path())
|
||||
self.tableView.add_files(files)
|
||||
event.accept()
|
||||
return True
|
||||
return super().eventFilter(source, event)
|
||||
|
||||
def closeEvent(self, event):
|
||||
"""Save settings when closing the application"""
|
||||
@ -142,7 +125,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.load_album_art(self.current_song_album_art)
|
||||
|
||||
def load_album_art(self, album_art_data):
|
||||
"""Sets the album art for the currently playing track"""
|
||||
"""Displays the album art for the currently playing track in the GraphicsView"""
|
||||
if self.current_song_album_art:
|
||||
# Clear the scene
|
||||
self.album_art_scene.clear()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user