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

Using Figure.savefig method to save screenshots, instead of manually

creating RGB array - this allows us to save as PDF/SVG/etc/etc.
parent 3915fc47
No related branches found
No related tags found
No related merge requests found
......@@ -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',
......
......@@ -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):
......
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