Skip to content

Commit

Permalink
Drag&Drop Fix, Refactor 31.01.2024 (macOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gdalik committed Jan 31, 2024
1 parent 296f976 commit 9335be8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
16 changes: 6 additions & 10 deletions GUI/MainWindow/View/mw_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from GUI.UpdateChecker.update_checker_view import UpdCheckView
from GUI.About.about_dialog_view import AboutDialogView
from Utilities.str2bool import str2bool
from Utilities.urlcheck import validUrls
from Utilities.checkMimeData import checkDroppedMimeData
from definitions import Settings


Expand Down Expand Up @@ -130,29 +130,25 @@ def keyReleaseEvent(self, event):

def dragEnterEvent(self, event):
super(MainWindowView, self).dragEnterEvent(event)
if self.checkDroppedMimeData(event.mimeData()):
if checkDroppedMimeData(event.mimeData()):
event.accept()
else:
event.ignore()

def dragMoveEvent(self, event):
super(MainWindowView, self).dragMoveEvent(event)
if self.checkDroppedMimeData(event.mimeData()):
if checkDroppedMimeData(event.mimeData()):
event.setDropAction(Qt.DropAction.CopyAction)
event.accept()
else:
event.ignore()

def dropEvent(self, event):
super(MainWindowView, self).dropEvent(event)
if self.checkDroppedMimeData(event.mimeData()):
checkedDroppedMimeData = checkDroppedMimeData(event.mimeData())
if checkedDroppedMimeData:
event.accept()
valid_urls = validUrls(event.mimeData().urls())
if valid_urls:
self.PlaylistView.signals.urlsDropped.emit(valid_urls, -1)

def checkDroppedMimeData(self, data):
return data.hasUrls() and data.objectName() != 'FromPlaylist'
self.PlaylistView.signals.urlsDropped.emit(checkedDroppedMimeData, -1)

def _setUpEQSettingsButtons(self):
icon = self.EQSettings_But1.icon()
Expand Down
16 changes: 6 additions & 10 deletions GUI/Playlist/playlistview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from PyQt6.QtCore import Qt, pyqtSignal, QObject, QMimeData, QUrl, QItemSelection, QItemSelectionModel, QModelIndex
from PyQt6.QtGui import QPainter, QDrag, QColor
from PyQt6.QtWidgets import QTableView, QAbstractItemView, QHeaderView
from Utilities.urlcheck import validUrls
from Utilities.checkMimeData import checkDroppedMimeData


class PL_Signals(QObject):
Expand Down Expand Up @@ -74,27 +74,23 @@ def paintEvent(self, event):

def dragEnterEvent(self, event):
super(PlaylistView, self).dragEnterEvent(event)
if self.checkDroppedMimeData(event.mimeData()):
if checkDroppedMimeData(event.mimeData()):
event.setDropAction(Qt.DropAction.CopyAction)
event.accept()

def dragMoveEvent(self, event):
super(PlaylistView, self).dragMoveEvent(event)
if self.checkDroppedMimeData(event.mimeData()):
if checkDroppedMimeData(event.mimeData()):
cur_index = self.indexAt(self.viewport().mapFromGlobal(self.cursor().pos()))
self.setCurrentIndex(cur_index)
event.accept()

def dropEvent(self, event):
super(PlaylistView, self).dropEvent(event)
if self.checkDroppedMimeData(event.mimeData()):
checkedDroppedMimeData = checkDroppedMimeData(event.mimeData())
if checkedDroppedMimeData:
event.accept()
valid_urls = validUrls(event.mimeData().urls())
if valid_urls:
self.signals.urlsDropped.emit(valid_urls, self.model().mapToSource(self.currentIndex()).row())

def checkDroppedMimeData(self, data):
return data.hasUrls() and data.objectName() != 'FromPlaylist'
self.signals.urlsDropped.emit(checkedDroppedMimeData, self.model().mapToSource(self.currentIndex()).row())

def mousePressEvent(self, e) -> None:
super(PlaylistView, self).mousePressEvent(e)
Expand Down
27 changes: 27 additions & 0 deletions Utilities/checkMimeData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# EarQuiz Frequencies. Software for technical ear training on equalization.
# Copyright (C) 2023-2024, Gdaliy Garmiza.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from Utilities.urlcheck import validUrls


def checkDroppedMimeData(data):
if data.objectName() == 'FromPlaylist':
return False
if data.hasUrls():
valid_urls = validUrls(data.urls())
if valid_urls:
return valid_urls
return False
4 changes: 3 additions & 1 deletion Utilities/urlcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@


def validUrls(urls: list):
return [url for url in urls if url.toLocalFile() and Path(url.toLocalFile()).exists()]
available_ext = ('.wav', '.aiff', '.flac', '.ogg', '.mp3', '.m3u', '.m3u8', '.pls', '.xspf')
return [url for url in urls if url.toLocalFile() and Path(url.toLocalFile()).exists()
and (Path(url.toLocalFile()).is_dir() or Path(url.toLocalFile()).suffix in available_ext)]

0 comments on commit 9335be8

Please sign in to comment.