Skip to content

Commit

Permalink
Change Set Montage dialog view (#459)
Browse files Browse the repository at this point in the history
* change the set montage dialog to display the figure in the same window

* changelog entry

* Merge branch 'main' into montage

* cosmetic / styling changes

* move buttons to bottom-right corner

* Minor tweaks

* Fix changelog
  • Loading branch information
bkloeckl authored Dec 9, 2024
1 parent 523ebc8 commit 73c07ee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
### 🌀 Changed
- Change the append dialog appearance to include original indices used for identifying the data ([#449](https://github.com/cbrnr/mnelab/pull/449) by [Benedikt Klöckl](https://github.com/bkloeckl))
- Include unique dataset indices in sidebar ([#454](https://github.com/cbrnr/mnelab/pull/454) by [Benedikt Klöckl](https://github.com/bkloeckl))
- Show a montage preview in the channel montage dialog ([#459](https://github.com/cbrnr/mnelab/pull/459) by [Benedikt Klöckl](https://github.com/bkloeckl))

### 🗑️ Removed
- Remove Python 3.9 support ([#457](https://github.com/cbrnr/mnelab/pull/457) by [Clemens Brunner](https://github.com/cbrnr))

### 🔧 Fixed
- Fix a bug where appending data would not be correctly displayed in the history ([#446](https://github.com/cbrnr/mnelab/pull/446) by [Benedikt Klöckl](https://github.com/bkloeckl))
- Fix resetting the settings to default values ([#456](https://github.com/cbrnr/mnelab/pull/456) by [Clemens Brunner](https://github.com/cbrnr))
- Fix an issue where the channel montage figure could not be closed on macOS ([#459](https://github.com/cbrnr/mnelab/pull/459) by [Benedikt Klöckl](https://github.com/bkloeckl))

## [0.9.2] · 2024-10-20
### ✨ Added
Expand Down
72 changes: 40 additions & 32 deletions src/mnelab/dialogs/montage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
#
# License: BSD (3-clause)

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from mne.channels import make_standard_montage
from PySide6.QtCore import Qt, Slot
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (
QCheckBox,
QDialog,
QDialogButtonBox,
QHBoxLayout,
QListWidget,
QPushButton,
QVBoxLayout,
QWidget,
)


class MontageDialog(QDialog):
def __init__(self, parent, montages, selected=None):
def __init__(self, parent, montages):
super().__init__(parent)
self.setWindowTitle("Set montage")
vbox = QVBoxLayout(self)
self.resize(760, 500)

vbox = QVBoxLayout()
self.montages = QListWidget()
self.montages.insertItems(0, montages)
self.montages.setSelectionMode(QListWidget.SingleSelection)
if selected is not None:
for i in range(self.montages.count()):
if self.montages.item(i).data(0) == selected:
self.montages.item(i).setSelected(True)
vbox.addWidget(self.montages)

self.montages.itemSelectionChanged.connect(self.view_montage)
self.match_case = QCheckBox("Match case-sensitive", self)
self.match_alias = QCheckBox("Match aliases", self)
self.ignore_missing = QCheckBox("Ignore missing", self)
Expand All @@ -38,34 +38,42 @@ def __init__(self, parent, montages, selected=None):
vbox.addWidget(self.ignore_missing)

hbox = QHBoxLayout()
self.view_button = QPushButton("View")
self.view_button.clicked.connect(self.view_montage)
hbox.addWidget(self.view_button)
hbox.addStretch()
hbox.addLayout(vbox, stretch=1)
self.figure = Figure()
self.canvas = FigureCanvas(self.figure)
self.canvas_container = QWidget(self)
self.canvas_container.setMinimumWidth(240)
self.canvas_container.setMinimumHeight(220)
self.canvas_layout = QVBoxLayout(self.canvas_container)
self.canvas_layout.setContentsMargins(0, 0, 0, 0)
self.canvas_layout.setSpacing(0)
self.canvas_layout.addWidget(self.canvas)
self.canvas_container.setLayout(self.canvas_layout)
hbox.addWidget(self.canvas_container, stretch=2)

button_layout = QHBoxLayout()
button_layout.addStretch()
self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
hbox.addWidget(self.buttonbox)
vbox.addLayout(hbox)
self.buttonbox.accepted.connect(self.accept)
self.buttonbox.rejected.connect(self.reject)
self.montages.itemSelectionChanged.connect(self.toggle_buttons)
self.toggle_buttons() # initialize OK and View buttons state
button_layout.addWidget(self.buttonbox, alignment=Qt.AlignLeft)

main_layout = QVBoxLayout(self)
main_layout.addLayout(hbox)
main_layout.addLayout(button_layout)
self.setLayout(main_layout)

@Slot()
def toggle_buttons(self):
"""Toggle OK and View buttons."""
if self.montages.selectedItems():
self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(True)
self.view_button.setEnabled(True)
else:
self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(False)
self.view_button.setEnabled(False)
if self.montages.count() > 0:
self.montages.setCurrentRow(0)
self.view_montage()

def view_montage(self):
name = self.montages.selectedItems()[0].data(0)
montage = make_standard_montage(name)
fig = montage.plot(show_names=True, show=False)
win = fig.canvas.manager.window
win.setWindowModality(Qt.WindowModal)
win.setWindowTitle("Montage")
win.statusBar().hide() # not necessary since matplotlib 3.3
fig.show()
self.figure.clear()
ax = self.figure.add_subplot()
montage.plot(show_names=True, show=False, axes=ax)
ax.set_aspect("equal")
self.figure.tight_layout(pad=0.5)
ax.margins(0)
self.canvas.draw()

0 comments on commit 73c07ee

Please sign in to comment.