Skip to content
Snippets Groups Projects
Commit bb7918e0 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Warning message shown for large files.

parent 4d45dc12
No related branches found
No related tags found
No related merge requests found
...@@ -551,26 +551,28 @@ def loadImage(filename): ...@@ -551,26 +551,28 @@ def loadImage(filename):
import wx import wx
if wx.GetApp() is not None: if wx.GetApp() is not None:
haveGui = True haveGui = True
import fsl.utils.dialog as fsldlg
except: except:
pass pass
realFilename = filename realFilename = filename
mbytes = op.getsize(filename) / 1048576.0 mbytes = op.getsize(filename) / 1048576.0
# The mbytes limit is arbitrary # The mbytes limit is arbitrary
if filename.endswith('.nii.gz') and mbytes > 512: if filename.endswith('.gz') and mbytes > 512:
unzipped, filename = tempfile.mkstemp(suffix='.nii') unzipped, filename = tempfile.mkstemp(suffix='.nii')
unzipped = os.fdopen(unzipped) unzipped = os.fdopen(unzipped)
msg = strings.messages['image.loadImage.decompress'] msg = strings.messages['image.loadImage.decompress']
msg = msg.format(realFilename, mbytes, filename) msg = msg.format(op.basename(realFilename), mbytes, filename)
if not haveGui: if not haveGui:
log.info(msg) log.info(msg)
else: else:
busyDlg = wx.BusyInfo(msg, wx.GetTopLevelWindows()[0]) busyDlg = fsldlg.SimpleMessageDialog(message=msg)
busyDlg.Show()
gzip = ['gzip', '-d', '-c', realFilename] gzip = ['gzip', '-d', '-c', realFilename]
log.debug('Running {} > {}'.format(' '.join(gzip), filename)) log.debug('Running {} > {}'.format(' '.join(gzip), filename))
...@@ -594,7 +596,19 @@ def loadImage(filename): ...@@ -594,7 +596,19 @@ def loadImage(filename):
log.debug('Loading image from {}'.format(filename)) log.debug('Loading image from {}'.format(filename))
import nibabel as nib import nibabel as nib
return nib.load(filename), filename
if haveGui and (mbytes > 512):
msg = strings.messages['image.loadImage.largeFile']
msg = msg.format(op.basename(filename), mbytes)
busyDlg = fsldlg.SimpleMessageDialog(message=msg)
busyDlg.Show()
image = nib.load(filename)
if haveGui and (mbytes > 512):
busyDlg.Destroy()
return image, filename
def saveImage(image, fromDir=None): def saveImage(image, fromDir=None):
......
...@@ -47,9 +47,11 @@ messages = TypeDict({ ...@@ -47,9 +47,11 @@ messages = TypeDict({
'image.saveImage.error' : 'An error occurred saving the file. ' 'image.saveImage.error' : 'An error occurred saving the file. '
'Details: {}', 'Details: {}',
'image.loadImage.decompress' : '{} is a large file ({} MB) - ' 'image.loadImage.decompress' : '{} is a large file ({:0.0f} MB) - '
'decompressing to {}, to allow memory ' 'decompressing to {}, to allow memory '
'mapping...', 'mapping...',
'image.loadImage.largeFile' : '{} is a large file ({:0.0f}) MB) - '
'loading it may take some time...',
'ProcessingDialog.error' : 'An error has occurred: {}' 'ProcessingDialog.error' : 'An error has occurred: {}'
'\n\nDetails: {}', '\n\nDetails: {}',
......
...@@ -103,6 +103,14 @@ class SimpleMessageDialog(wx.Dialog): ...@@ -103,6 +103,14 @@ class SimpleMessageDialog(wx.Dialog):
self.SetMessage(message) self.SetMessage(message)
def Show(self):
"""Overrides ``wx.Dialog.Show``. Calls that method, and calls
``wx.Yield``.
"""
wx.Dialog.Show(self)
wx.Yield()
def SetMessage(self, msg): def SetMessage(self, msg):
"""Updates the message shown on this ``SimpleMessageDialog``. """Updates the message shown on this ``SimpleMessageDialog``.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment