Skip to content

Commit

Permalink
Add fixed name option to interactive load widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mcraig-ibme committed Apr 6, 2023
1 parent fb75094 commit b34a331
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions quantiphyse/gui/main_window.py
Expand Up @@ -38,7 +38,7 @@ class DragOptions(QtWidgets.QDialog):
Interface for dealing with drag and drop
"""

def __init__(self, parent, fname, ivm, force_t_option=False, default_main=False, possible_roi=True):
def __init__(self, parent, fname, ivm, force_t_option=False, default_main=False, possible_roi=True, fixed_name=None):
super(DragOptions, self).__init__(parent)
self.setWindowTitle("Load Data")
self.ivm = ivm
Expand All @@ -52,10 +52,14 @@ def __init__(self, parent, fname, ivm, force_t_option=False, default_main=False,
grid = QtWidgets.QGridLayout()
grid.addWidget(QtWidgets.QLabel("Name:"), 1, 0)
self.name_combo = QtWidgets.QComboBox()
def_name = self.ivm.suggest_name(os.path.split(fname)[1].split(".", 1)[0])
for name in [def_name, 'MRI', 'T10', 'Ktrans', 'kep', 've', 'vp', 'model_curves']:
self.name_combo.addItem(name)
self.name_combo.setEditable(True)
if not fixed_name:
def_name = self.ivm.suggest_name(os.path.split(fname)[1].split(".", 1)[0])
for name in [def_name, 'MRI', 'T10', 'Ktrans', 'kep', 've', 'vp', 'model_curves']:
self.name_combo.addItem(name)
self.name_combo.setEditable(True)
else:
self.name_combo.addItem(fixed_name)
self.name_combo.setEditable(False)
grid.addWidget(self.name_combo, 1, 1)
layout.addLayout(grid)
hbox = QtWidgets.QHBoxLayout()
Expand Down Expand Up @@ -432,15 +436,15 @@ def load_data_interactive(self, fname, name=None):
# third dimension as time - some broken NIFTI files require this.
force_t_option = (data.nvols == 1 and data.grid.shape[2] > 1)
force_t = False

options = DragOptions(self, fname, self.ivm, force_t_option=force_t_option,
default_main=self.ivm.main is None, possible_roi=(data.nvols ==1))
if not options.exec_(): return

data.name = options.name
data.roi = options.type == "roi"
if force_t_option: force_t = options.force_t

# If we had to do anything evil to make data fit, warn and give user the chance to back out
if force_t:
msg_box = QtWidgets.QMessageBox(self)
Expand All @@ -449,7 +453,7 @@ def load_data_interactive(self, fname, name=None):
msg_box.setDefaultButton(QtWidgets.QMessageBox.Ok)
if msg_box.exec_() != QtWidgets.QMessageBox.Ok: return
data.set_2dt()

self.ivm.add(data, make_main=options.make_main, make_current=not options.make_main)

def load_data(self, fname):
Expand Down
2 changes: 1 addition & 1 deletion quantiphyse/packages/core/batch_explorer/widget.py
Expand Up @@ -170,7 +170,7 @@ def _add(self, path, relpath):
md = self._saved_metadata.get(name, None)
if md is None:
from quantiphyse.gui.main_window import DragOptions
options = DragOptions(self, path, self.ivm, force_t_option=False,
options = DragOptions(self, path, self.ivm, force_t_option=False, fixed_name=name,
default_main=self.ivm.main is None, possible_roi=(qpdata.nvols == 1))
if not options.exec_(): return

Expand Down

0 comments on commit b34a331

Please sign in to comment.