diff --git a/fsl/data/strings.py b/fsl/data/strings.py index 9da50b15f5991aa9600edbf728dcc7c68ee063ad..3e1ad44b323ebb8b762d0eb0fe42b5bb76a447cd 100644 --- a/fsl/data/strings.py +++ b/fsl/data/strings.py @@ -63,10 +63,12 @@ messages = TypeDict({ 'PlotPanel.screenshot' : 'Save screenshot', + 'PlotPanel.screenshot.error' : 'An error occurred while saving the ' + 'screenshot.\n\n' + 'Details: {}', + 'HistogramPanel.calcHist' : 'Calculating histogram for {} ...', - 'SpacePanel.nonVolumetric' : 'Non-volumetric overlays ' - 'are not supported', 'LookupTablePanel.notLutOverlay' : 'Choose an overlay which ' 'uses a lookup table', @@ -99,6 +101,8 @@ titles = TypeDict({ 'CanvasPanel.screenshot.notSaved' : 'Save overlay before continuing', 'CanvasPanel.screenshot.error' : 'Error saving screenshot', + 'PlotPanel.screenshot.error' : 'Error saving screenshot', + 'AtlasInfoPanel' : 'Atlas information', 'AtlasOverlayPanel' : 'Atlas overlays', diff --git a/fsl/fslview/views/plotpanel.py b/fsl/fslview/views/plotpanel.py index 96ad49602f4ae5aa633aaf354547133bce2d53b5..e95d0c2b6f39e48609501697529f4f4b50b971f9 100644 --- a/fsl/fslview/views/plotpanel.py +++ b/fsl/fslview/views/plotpanel.py @@ -18,7 +18,6 @@ mpl.use('WxAgg') import matplotlib.pyplot as plt -import matplotlib.image as mplimg from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx @@ -410,8 +409,14 @@ class PlotPanel(viewpanel.ViewPanel): def screenshot(self, *a): + formats = self.__canvas.get_supported_filetypes().items() + + wildcard = ['{}|*.{}'.format(desc, fmt) for fmt, desc in formats] + wildcard = '|'.join(wildcard) + dlg = wx.FileDialog(self, message=strings.messages[self, 'screenshot'], + wildcard=wildcard, style=wx.FD_SAVE) if dlg.ShowModal() != wx.ID_OK: @@ -419,17 +424,13 @@ class PlotPanel(viewpanel.ViewPanel): path = dlg.GetPath() - buf = self.__canvas.tostring_argb() - ncols, nrows = self.__canvas.get_width_height() - - bitmap = np.fromstring(buf, dtype=np.uint8) - bitmap = bitmap.reshape(nrows, ncols, 4) - - rgb = bitmap[:, :, 1:] - a = bitmap[:, :, 0] - bitmap = np.dstack((rgb, a)) - - mplimg.imsave(path, bitmap) + try: + self.__figure.savefig(path) + except Exception as e: + wx.MessageBox( + strings.messages[self, 'screenshot', 'error'].format(str(e)), + strings.titles[ self, 'screenshot', 'error'], + wx.ICON_ERROR) def message(self, msg):