diff --git a/invesalius/control.py b/invesalius/control.py index 201a2b7..a3bf95f 100644 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -207,21 +207,8 @@ class Controller(): if id_type == const.ID_ANALYZE_IMPORT: dialog.ImportAnalyzeWarning() - # Import project treating compressed nifti exception - suptype = ('hdr', 'nii', 'nii.gz', 'par') filepath = dialog.ShowImportOtherFilesDialog(id_type) - if filepath is not None: - name = filepath.rpartition('\\')[-1].split('.') - - if name[-1] == 'gz': - name[1] = 'nii.gz' - - filetype = name[1].lower() - - if filetype in suptype: - Publisher.sendMessage("Open other files", filepath) - else: - dialog.ImportInvalidFiles() + Publisher.sendMessage("Open other files", filepath) def ShowDialogOpenProject(self): # Offer to save current project if necessary @@ -749,23 +736,18 @@ class Controller(): def OnOpenOtherFiles(self, pubsub_evt): filepath = pubsub_evt.data - name = filepath.rpartition('\\')[-1].split('.') - - if name[-1] == 'gz': - name[1] = 'nii.gz' - - suptype = ('hdr', 'nii', 'nii.gz', 'par') - filetype = name[1].lower() + if not(filepath) == None: + name = filepath.rpartition('\\')[-1].split('.') - if filetype in suptype: group = oth.ReadOthers(filepath) - else: - dialog.ImportInvalidFiles() - - matrix, matrix_filename = self.OpenOtherFiles(group) - self.CreateOtherProject(str(name[0]), matrix, matrix_filename) - self.LoadProject() - Publisher.sendMessage("Enable state project", True) + + if group: + matrix, matrix_filename = self.OpenOtherFiles(group) + self.CreateOtherProject(str(name[0]), matrix, matrix_filename) + self.LoadProject() + Publisher.sendMessage("Enable state project", True) + else: + dialog.ImportInvalidFiles(ftype="Others") def OpenDicomGroup(self, dicom_group, interval, file_range, gui=True): # Retrieve general DICOM headers diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 08ff27a..4742f89 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -213,14 +213,15 @@ class ProgressDialog(object): WILDCARD_OPEN = "InVesalius 3 project (*.inv3)|*.inv3|" \ "All files (*.*)|*.*" -WILDCARD_ANALYZE = "Analyze 7.5 (*.hdr)|*.hdr|" \ +WILDCARD_ANALYZE = "Analyze 7.5 (*.hdr)|*.[hH][dD][rR]|" \ "All files (*.*)|*.*" WILDCARD_NIFTI = "NIfTI 1 (*.nii)|*.nii|" \ "Compressed NIfTI (*.nii.gz)|*.nii.gz|" \ + "HDR NIfTI (*.hdr)|*.[hH][dD][rR]|" \ "All files (*.*)|*.*" - -WILDCARD_PARREC = "PAR/REC (*.par)|*.par|" \ +#".[jJ][pP][gG]" +WILDCARD_PARREC = "PAR/REC (*.par)|*.[pP][aA][rR]|" \ "All files (*.*)|*.*" WILDCARD_MESH_FILES = "STL File format (*.stl)|*.stl|" \ @@ -636,8 +637,10 @@ def ImportEmptyDirectory(dirpath): def ImportInvalidFiles(ftype="DICOM"): if ftype == "Bitmap": msg = _("There are no Bitmap, JPEG, PNG or TIFF files in the selected folder.") - else: + elif ftype == "DICOM": msg = _("There are no DICOM files in the selected folder.") + else: + msg = _("Invalid file.") if sys.platform == 'darwin': dlg = wx.MessageDialog(None, "", msg, diff --git a/invesalius/reader/others_reader.py b/invesalius/reader/others_reader.py index 9059e67..fa6407f 100644 --- a/invesalius/reader/others_reader.py +++ b/invesalius/reader/others_reader.py @@ -44,8 +44,11 @@ def ReadOthers(dir_): ow = vtk.vtkOutputWindow() ow.SetInstance(fow) - imagedata = nib.squeeze_image(nib.load(dir_)) - imagedata = nib.as_closest_canonical(imagedata) - imagedata.update_header() - - return imagedata \ No newline at end of file + try: + imagedata = nib.squeeze_image(nib.load(dir_)) + imagedata = nib.as_closest_canonical(imagedata) + imagedata.update_header() + except(nib.filebasedimages.ImageFileError): + return False + + return imagedata -- libgit2 0.21.2