Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add GUI for prefixing marker streams #240

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## [UNRELEASED] - XXXX-XX-XX
### Added
- Add option to use effective sampling rate when importing XDF files ([#236](https://github.com/cbrnr/mnelab/pull/236) by [Clemens Brunner](https://github.com/cbrnr))
- Add option to disambiguate markers with identical names in different marker streams with the `prefix_markers` parameter ([#239](https://github.com/cbrnr/mnelab/pull/239) by [Clemens Brunner](https://github.com/cbrnr))
- Add option to disambiguate markers with identical names in different marker streams with the `prefix_markers` parameter ([#239](https://github.com/cbrnr/mnelab/pull/239) and [#240](https://github.com/cbrnr/mnelab/pull/240) by [Clemens Brunner](https://github.com/cbrnr))

### Fixed
- Fix history for importing XDF files and dropping channels ([#234](https://github.com/cbrnr/mnelab/pull/234) by [Clemens Brunner](https://github.com/cbrnr))
Expand Down
17 changes: 14 additions & 3 deletions mnelab/dialogs/xdfstreamsdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License: BSD (3-clause)

from qtpy.QtWidgets import (QDialog, QVBoxLayout, QDialogButtonBox, QAbstractItemView,
QTableView, QCheckBox)
QTableView, QCheckBox, QHBoxLayout)
from qtpy.QtGui import QStandardItemModel, QStandardItem
from qtpy.QtCore import Qt

Expand Down Expand Up @@ -43,19 +43,30 @@ def __init__(self, parent, rows, selected=None, disabled=None):

vbox = QVBoxLayout(self)
vbox.addWidget(self.view)
hbox = QHBoxLayout()
self._effective_srate = QCheckBox("Use effective sampling rate")
self._effective_srate.setChecked(True)
vbox.addWidget(self._effective_srate)
hbox.addWidget(self._effective_srate)
self._prefix_markers = QCheckBox("Prefix markers with stream ID")
self._prefix_markers.setChecked(False)
if not disabled:
self._prefix_markers.setEnabled(False)
hbox.addWidget(self._prefix_markers)
vbox.addLayout(hbox)
self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
vbox.addWidget(self.buttonbox)
self.buttonbox.accepted.connect(self.accept)
self.buttonbox.rejected.connect(self.reject)

self.resize(775, 650)
self.view.setColumnWidth(0, 80)
self.view.setColumnWidth(0, 90)
self.view.setColumnWidth(1, 200)
self.view.setColumnWidth(2, 140)

@property
def effective_srate(self):
return self._effective_srate.isChecked()

@property
def prefix_markers(self):
return self._prefix_markers.isChecked()
8 changes: 7 additions & 1 deletion mnelab/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,13 @@ def open_data(self, fname=None):
row = dialog.view.selectionModel().selectedRows()[0].row()
stream_id = dialog.model.data(dialog.model.index(row, 0))
srate = "effective" if dialog.effective_srate else "nominal"
self.model.load(fname, stream_id=stream_id, srate=srate)
prefix_markers = dialog.prefix_markers
kwargs = {}
if srate == "nominal":
kwargs["srate"] = srate
if prefix_markers:
kwargs["prefix_markers"] = prefix_markers
self.model.load(fname, stream_id=stream_id, **kwargs)
else: # all other file formats
try:
self.model.load(fname)
Expand Down
3 changes: 2 additions & 1 deletion mnelab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def load(self, fname, *args, **kwargs):
kwargstr = ", " + f"{', '.join(f'{k}={repr(v)}' for k, v in kwargs.items())}"
else:
kwargstr = ""
self.history.append(f'data = read_raw("{fname}"{argstr}{kwargstr}, preload=True)')
self.history.append(f'data = read_raw("{fname}"{argstr}{kwargstr}, preload=True)'.
replace("'", '"'))
fsize = getsize(data.filenames[0]) / 1024**2 # convert to MB
name, ext = Path(fname).stem, "".join(Path(fname).suffixes)
self.insert_data(defaultdict(lambda: None, name=name, fname=fname,
Expand Down
4 changes: 2 additions & 2 deletions mnelab/utils/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def __init__(self, document):
# strings
f = QTextCharFormat()
f.setForeground(Qt.darkCyan)
self.rules.append((QRegularExpression("\".*\""), f))
self.rules.append((QRegularExpression("'.*'"), f))
self.rules.append((QRegularExpression('"[^"]*"'), f))
self.rules.append((QRegularExpression("'[^']*'"), f))

def highlightBlock(self, text):
for rule in self.rules:
Expand Down