Skip to content

Commit

Permalink
Fix drag and drop (#422)
Browse files Browse the repository at this point in the history
* Fix drag and drop

* Add changelog entry
  • Loading branch information
cbrnr authored May 9, 2024
1 parent b5417a4 commit 4b65c81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
- Prepare support for plotting raw data with MNE-Qt-Browser ([#403](https://github.com/cbrnr/mnelab/pull/403) by [Martin Schulz](https://github.com/marsipu) and [Clemens Brunner](https://github.com/cbrnr))
- Fix drag and drop for PySide ≥ 6.7.0 ([#422](https://github.com/cbrnr/mnelab/pull/422) by [Clemens Brunner](https://github.com/cbrnr))

## [0.9.0] - 2024-01-19
### Added
Expand Down
23 changes: 14 additions & 9 deletions src/mnelab/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import mne
import numpy as np
from mne import channel_type
from PySide6.QtCore import QEvent, QMetaObject, QModelIndex, Qt, QUrl, Slot
from PySide6.QtGui import QAction, QDesktopServices, QDropEvent, QIcon, QKeySequence
from PySide6.QtCore import QEvent, QMetaObject, QModelIndex, QObject, Qt, QUrl, Slot
from PySide6.QtGui import QAction, QDesktopServices, QIcon, QKeySequence
from PySide6.QtWidgets import (
QApplication,
QFileDialog,
Expand Down Expand Up @@ -71,6 +71,8 @@ def __init__(self, model: Model):
self.resize(settings["size"])
self.move(settings["pos"])

self.installEventFilter(self)

# remove None entries from self.recent
self.recent = [recent for recent in self.recent if recent is not None]

Expand All @@ -90,7 +92,6 @@ def __init__(self, model: Model):
[f"{Path(__file__).parent}/icons"] + QIcon.themeSearchPaths()
)
QIcon.setFallbackThemeName("light")
self.event(QEvent(QEvent.PaletteChange))

self.actions = {} # contains all actions

Expand Down Expand Up @@ -1378,12 +1379,16 @@ def _toggle_statusbar(self):
self.statusBar().hide()
write_settings(statusbar=not self.statusBar().isHidden())

@Slot(QDropEvent)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.acceptProposedAction()

@Slot(QDropEvent)
def dragMoveEvent(self, event):
event.acceptProposedAction()

def dragLeaveEvent(self, event):
event.accept()

def dropEvent(self, event):
mime = event.mimeData()
if mime.hasUrls():
Expand All @@ -1393,6 +1398,7 @@ def dropEvent(self, event):
self.open_data(url.toLocalFile())
except FileNotFoundError as e:
QMessageBox.critical(self, "File not found", str(e))
event.acceptProposedAction()

@Slot(QEvent)
def closeEvent(self, event):
Expand All @@ -1415,11 +1421,10 @@ def _plot_closed(self, event=None):
if self.bads != bads:
self.model.history.append(f'data.info["bads"] = {bads}')

def event(self, ev):
"""Catch system events."""
if ev.type() == QEvent.PaletteChange: # detect theme switches
def eventFilter(self, source, event):
if event.type() == QEvent.PaletteChange:
if (style := QApplication.styleHints().colorScheme()) != Qt.ColorScheme.Unknown:
QIcon.setThemeName(style.name.lower())
else:
QIcon.setThemeName("light") # fallback
return super().event(ev)
return QObject.eventFilter(self, source, event)

0 comments on commit 4b65c81

Please sign in to comment.