Skip to content

Commit

Permalink
Improve deletion of annotation (#173)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel McCloy <[email protected]>
Co-authored-by: Eric Larson <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2023
1 parent ba620e6 commit 8ce2b26
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
19 changes: 15 additions & 4 deletions mne_qt_browser/_pg_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ def mouseDragEvent(self, event, axis=None):
plot_onset, duration, self.mne.current_description,
region=self._drag_region)
self._drag_region.select(True)
self._drag_region.setZValue(2)

# Update Overview-Bar
self.mne.overview_bar.update_annotations()
Expand Down Expand Up @@ -2088,8 +2089,10 @@ def mouseClickEvent(self, event):
event.accept()
elif event.button() == Qt.RightButton and self.movable:
self.remove()
# Propagate remove request to lower annotations if overlapping
event.ignore()
# the annotation removed should be the one on top of all others, which
# should correspond to the one of the type currently selected and with
# the highest zValue
event.accept()
else:
event.ignore()

Expand Down Expand Up @@ -2228,7 +2231,7 @@ def _init_ui(self):

self.description_cmbx = QComboBox()
self.description_cmbx.setSizeAdjustPolicy(QComboBox.AdjustToContents)
self.description_cmbx.activated.connect(self._description_changed)
self.description_cmbx.currentIndexChanged.connect(self._description_changed)
self._update_description_cmbx()
layout.addWidget(self.description_cmbx)

Expand Down Expand Up @@ -2461,6 +2464,12 @@ def _select_annotations(self):
def _description_changed(self, descr_idx):
new_descr = self.description_cmbx.itemText(descr_idx)
self.mne.current_description = new_descr
# increase zValue of currently selected annotation and decrease all the others
for region in self.mne.regions:
if region.description == self.mne.current_description:
region.setZValue(2)
else:
region.setZValue(1)

def _start_changed(self):
start = self.start_bx.value()
Expand Down Expand Up @@ -4196,7 +4205,9 @@ def _change_annot_mode(self):
for region in self.mne.regions:
region.setMovable(self.mne.annotation_mode)
if self.mne.annotation_mode:
region.setZValue(2)
region.setZValue(
2 if region.description == self.mne.current_description else 1
)
else:
region.setZValue(0)

Expand Down
2 changes: 1 addition & 1 deletion mne_qt_browser/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def pytest_configure(config):
"""Configure pytest options."""
# Markers
for marker in ('benchmark',):
for marker in ('benchmark', 'pgtest', 'slowtest'):
config.addinivalue_line('markers', marker)


Expand Down
2 changes: 1 addition & 1 deletion mne_qt_browser/tests/test_pg_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_annotations_interactions(raw_orig, pg_backend):
fig._fake_keypress('a')

# Set current description to index 1
annot_dock.description_cmbx.activated.emit(1)
annot_dock.description_cmbx.setCurrentIndex(1)
assert fig.mne.current_description == 'B'

# Draw additional annotation
Expand Down
4 changes: 2 additions & 2 deletions mne_qt_browser/tests/test_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_scroll_speed_epochs_unicolor(raw_orig, benchmark_param, store,
# Prevent problems with info's locked-stated
epochs.info._unlocked = True

fig = epochs.plot(show=False, block=False, **benchmark_param)
fig = epochs.plot(show=False, block=False, events=False, **benchmark_param)
_Benchmark(fig, qapp, store, request)


Expand Down Expand Up @@ -189,6 +189,6 @@ def test_scroll_speed_epochs_multicolor(raw_orig, benchmark_param, store,
if sys.platform == 'darwin':
benchmark_param['use_opengl'] = True

fig = epochs.plot(show=False, block=False, epoch_colors=epoch_colors,
fig = epochs.plot(show=False, block=False, events=False, epoch_colors=epoch_colors,
**benchmark_param)
_Benchmark(fig, qapp, store, request)

0 comments on commit 8ce2b26

Please sign in to comment.