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

Plot panel supports screenshots

parent 21129814
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,7 @@ messages = TypeDict({ ...@@ -64,6 +64,7 @@ messages = TypeDict({
'not four dimensional', 'not four dimensional',
'TimeSeriesPanel.outOfBounds' : 'Selected overlay has no data ' 'TimeSeriesPanel.outOfBounds' : 'Selected overlay has no data '
'at the current coordinates', 'at the current coordinates',
'TimeSeriesPanel.screenshot' : 'Save screenshot',
'SpacePanel.nonVolumetric' : 'Non-volumetric overlays ' 'SpacePanel.nonVolumetric' : 'Non-volumetric overlays '
'are not supported', 'are not supported',
......
...@@ -7,16 +7,23 @@ ...@@ -7,16 +7,23 @@
import logging import logging
import wx
import matplotlib as mpl import matplotlib as mpl
import numpy as np
mpl.use('WxAgg') mpl.use('WxAgg')
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.image as mplimg
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d import Axes3D
import viewpanel import viewpanel
import fsl.data.strings as strings
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -41,7 +48,7 @@ class PlotPanel(viewpanel.ViewPanel): ...@@ -41,7 +48,7 @@ class PlotPanel(viewpanel.ViewPanel):
# There is currently no screenshot functionality # There is currently no screenshot functionality
# because I haven't gotten around to implementing # because I haven't gotten around to implementing
# it ... # it ...
self.disable('screenshot') # self.disable('screenshot')
self.__figure = plt.Figure() self.__figure = plt.Figure()
self.__axis = self.__figure.add_subplot(111, projection=proj) self.__axis = self.__figure.add_subplot(111, projection=proj)
...@@ -67,7 +74,27 @@ class PlotPanel(viewpanel.ViewPanel): ...@@ -67,7 +74,27 @@ class PlotPanel(viewpanel.ViewPanel):
def screenshot(self, *a): def screenshot(self, *a):
pass
dlg = wx.FileDialog(self,
message=strings.messages[self, 'screenshot'],
style=wx.FD_SAVE)
if dlg.ShowModal() != wx.ID_OK:
return
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)
def message(self, msg): 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