Skip to content

Commit

Permalink
Merge pull request #44 from cibr-jyu/add-sample-data-to-subject-dialog
Browse files Browse the repository at this point in the history
Add sample data option to subject dialog
  • Loading branch information
teekuningas authored Mar 25, 2024
2 parents 642278a + e9a6561 commit 5133c0e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 19 deletions.
33 changes: 33 additions & 0 deletions meggie/mainwindow/dialogs/addSubjectDialogMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

import os
import mne
import logging

from PyQt5 import QtWidgets
Expand Down Expand Up @@ -73,6 +74,38 @@ def _create_subject():
self.parent.initialize_ui()
self.close()

def on_pushButtonSample_clicked(self, checked=None):
if checked is None:
return

experiment = self.parent.experiment
old_names = experiment.subjects.keys()
subject_name = next_available_name(old_names, "sample_audvis_raw")

@threaded
def _create_subject():
raw_path = os.path.join(
str(mne.datasets.sample.data_path()),
"MEG",
"sample",
"sample_audvis_raw.fif",
)
experiment.create_subject(subject_name, raw_path)

try:
_create_subject(do_meanwhile=self.parent.update_ui)
except Exception:
logging.getLogger("ui_logger").exception("")

try:
self.parent.experiment.save_experiment_settings()
except Exception as exc:
exc_messagebox(self, exc)
return

self.parent.initialize_ui()
self.close()

def on_pushButtonBrowse_clicked(self, checked=None):
if checked is None:
return
Expand Down
28 changes: 17 additions & 11 deletions meggie/mainwindow/dialogs/addSubjectDialogUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

# Form implementation generated from reading ui file 'addSubjectDialogUi.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING! All changes made in this file will be lost!
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets

Expand Down Expand Up @@ -46,13 +48,7 @@ def setupUi(self, AddSubject):
self.pushButtonRemove = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButtonRemove.setEnabled(False)
self.pushButtonRemove.setObjectName("pushButtonRemove")
self.gridLayout_2.addWidget(self.pushButtonRemove, 2, 0, 1, 1)
self.listWidgetFileNames = QtWidgets.QListWidget(self.scrollAreaWidgetContents)
self.listWidgetFileNames.setSelectionMode(
QtWidgets.QAbstractItemView.ExtendedSelection
)
self.listWidgetFileNames.setObjectName("listWidgetFileNames")
self.gridLayout_2.addWidget(self.listWidgetFileNames, 0, 0, 1, 1)
self.gridLayout_2.addWidget(self.pushButtonRemove, 3, 0, 1, 1)
self.pushButtonBrowse = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
sizePolicy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed
Expand All @@ -65,12 +61,21 @@ def setupUi(self, AddSubject):
self.pushButtonBrowse.setSizePolicy(sizePolicy)
self.pushButtonBrowse.setObjectName("pushButtonBrowse")
self.gridLayout_2.addWidget(self.pushButtonBrowse, 1, 0, 1, 1)
self.listWidgetFileNames = QtWidgets.QListWidget(self.scrollAreaWidgetContents)
self.listWidgetFileNames.setSelectionMode(
QtWidgets.QAbstractItemView.ExtendedSelection
)
self.listWidgetFileNames.setObjectName("listWidgetFileNames")
self.gridLayout_2.addWidget(self.listWidgetFileNames, 0, 0, 1, 1)
self.pushButtonSample = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButtonSample.setObjectName("pushButtonSample")
self.gridLayout_2.addWidget(self.pushButtonSample, 2, 0, 1, 1)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.gridLayout.addWidget(self.scrollArea, 1, 0, 1, 3)

self.retranslateUi(AddSubject)
self.pushButtonCancel.clicked.connect(AddSubject.reject)
self.pushButtonOk.clicked.connect(AddSubject.accept)
self.pushButtonCancel.clicked.connect(AddSubject.reject) # type: ignore
self.pushButtonOk.clicked.connect(AddSubject.accept) # type: ignore
QtCore.QMetaObject.connectSlotsByName(AddSubject)

def retranslateUi(self, AddSubject):
Expand All @@ -83,3 +88,4 @@ def retranslateUi(self, AddSubject):
self.pushButtonOk.setText(_translate("AddSubject", "Ok"))
self.pushButtonRemove.setText(_translate("AddSubject", "Remove"))
self.pushButtonBrowse.setText(_translate("AddSubject", "Browse..."))
self.pushButtonSample.setText(_translate("AddSubject", "Add MNE sample data"))
23 changes: 15 additions & 8 deletions meggie/mainwindow/dialogs/addSubjectDialogUi.ui
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<item row="3" column="0">
<widget class="QPushButton" name="pushButtonRemove">
<property name="enabled">
<bool>false</bool>
Expand All @@ -83,13 +83,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QListWidget" name="listWidgetFileNames">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pushButtonBrowse">
<property name="sizePolicy">
Expand All @@ -103,6 +96,20 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QListWidget" name="listWidgetFileNames">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="pushButtonSample">
<property name="text">
<string>Add MNE sample data</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down

0 comments on commit 5133c0e

Please sign in to comment.