def save_data(self): """ Dialog for saving an data as a nifti file """ if self.ivm.current_data is None: QtGui.QMessageBox.warning(self, "No data", "No current data to save", QtGui.QMessageBox.Close) else: if hasattr(self.ivm.current_data, "fname") and self.ivm.current_data.fname is not None: fname = self.ivm.current_data.fname else: fname = os.path.join(default_save_dir(), self.ivm.current_data.name + ".nii") fname, _ = QtGui.QFileDialog.getSaveFileName( self, 'Save file', dir=fname, filter="NIFTI files (*.nii *.nii.gz)") if fname != '': save(self.ivm.current_data, fname) else: # Cancelled pass
def _save(self): if self.data_list.selected is not None: name = self.data_list.selected.name data = self.ivm.data[name] if hasattr(data, "fname") and data.fname is not None: fname = data.fname else: fname = os.path.join(default_save_dir(), name + ".nii") fname, _ = QtGui.QFileDialog.getSaveFileName( self, 'Save file', dir=fname, filter="NIFTI files (*.nii *.nii.gz)") if fname != '': save(self.ivm.data[name], fname) else: # Cancelled pass
def load_data_interactive(self, fname=None, name=None): """ Load data into the IVM from a file (which may already be known) """ if fname is None: fname, _ = QtGui.QFileDialog.getOpenFileName( self, 'Open file', default_save_dir()) if not fname: return set_default_save_dir(os.path.dirname(fname)) # Data is not loaded at this point, however basic metadata is so we can tailor the # options we offer data = load(fname) # If we have apparently 3d data then we have the 'advanced' option of treating the # 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 = QtGui.QMessageBox(self) msg_box.setText("3D data was interpreted as multiple 2D volumes") msg_box.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) msg_box.setDefaultButton(QtGui.QMessageBox.Ok) if msg_box.exec_() != QtGui.QMessageBox.Ok: return data.set_2dt() self.ivm.add(data, make_main=options.make_main, make_current=not options.make_main)
def _load_clicked(self): filename, _ = QtGui.QFileDialog.getOpenFileName(dir=default_save_dir()) if filename: set_default_save_dir(os.path.dirname(filename)) self._load_file(filename)