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

Little tweaks to OverlayInfoPanel. A 'wait' dialog is displayed while

screenshot taken.
parent 165b890f
No related branches found
No related tags found
No related merge requests found
......@@ -672,7 +672,7 @@ nifti = TypeDict({
feat = TypeDict({
'analysisName' : 'Analysis name',
'numPoints' : 'Number of time points',
'numPoints' : 'Number of volumes',
'numEVs' : 'Number of EVs',
'numContrasts' : 'Number of contrasts',
})
......@@ -10,8 +10,9 @@ import collections
import wx
import wx.html as wxhtml
import fsl.data.strings as strings
import fsl.fslview.panel as fslpanel
import fsl.data.strings as strings
import fsl.data.constants as constants
import fsl.fslview.panel as fslpanel
class OverlayInfo(object):
......@@ -138,6 +139,8 @@ class OverlayInfoPanel(fslpanel.FSLViewPanel):
hdr = img.get_header()
voxUnits, timeUnits = hdr.get_xyzt_units()
qformCode = int(hdr['qform_code'])
sformCode = int(hdr['sform_code'])
dimSect = strings.labels[self, overlay, 'dimensions']
xformSect = strings.labels[self, overlay, 'transform']
......@@ -177,21 +180,21 @@ class OverlayInfoPanel(fslpanel.FSLViewPanel):
section=dimSect)
info.addInfo(strings.nifti['qform_code'],
strings.anatomy['Image', 'space', int(hdr['qform_code'])],
strings.anatomy['Image', 'space', qformCode],
section=xformSect)
info.addInfo(strings.nifti['sform_code'],
strings.anatomy['Image', 'space', int(hdr['sform_code'])],
strings.anatomy['Image', 'space', sformCode],
section=xformSect)
# TODO matrix formatting (you'll need to use
# HTML, or maybe get the formatOverlayInfo
# method to support different types)
info.addInfo(strings.nifti['qform'],
self.__formatArray(img.get_qform()),
section=xformSect)
info.addInfo(strings.nifti['sform'],
self.__formatArray(img.get_sform()),
section=xformSect)
if qformCode != constants.NIFTI_XFORM_UNKNOWN:
info.addInfo(strings.nifti['qform'],
self.__formatArray(img.get_qform()),
section=xformSect)
if sformCode != constants.NIFTI_XFORM_UNKNOWN:
info.addInfo(strings.nifti['sform'],
self.__formatArray(img.get_sform()),
section=xformSect)
for i in range(3):
orient = overlay.getVoxelOrientation(i)
......
......@@ -398,77 +398,87 @@ def _screenshot(overlayList, displayCtx, canvasPanel):
dlg.Destroy()
wx.Yield()
# The typical way to get a screen grab of a wx
# Window is to use a wx.WindowDC, and a wx.MemoryDC,
# and to 'blit' a region from the window DC into
# the memory DC.
#
# This is precisely what we're doing here, but
# the process is complicated by the fact that,
# under OSX, the contents of wx.glcanvas.GLCanvas
# instances are not captured by WindowDCs.
#
# So I'm grabbing a screenshot of the canvas
# panel in the standard wxWidgets way, and then
# manually patching in bitmaps of each GLCanvas
# that is displayed in the canvas panel.
# Get all the wx GLCanvas instances
# which are displayed in the panel,
# including the colour bar canvas
glCanvases = canvasPanel.getGLCanvases()
glCanvases.append(canvasPanel.getColourBarCanvas())
# The canvas panel container is the
# direct parent of the colour bar
# canvas, and an ancestor of the
# other GL canvases
parent = canvasPanel.getCanvasContainer()
width, height = parent.GetClientSize().Get()
windowDC = wx.WindowDC(parent)
memoryDC = wx.MemoryDC()
bmp = wx.EmptyBitmap(width, height)
# Copy the contents of the canvas container
# to the bitmap
memoryDC.SelectObject(bmp)
memoryDC.Blit(
0,
0,
width,
height,
windowDC,
0,
0)
memoryDC.SelectObject(wx.NullBitmap)
# Make a H*W*4 bitmap array
data = np.zeros((height, width, 4), dtype=np.uint8)
rgb = bmp.ConvertToImage().GetData()
rgb = np.fromstring(rgb, dtype=np.uint8)
data[:, :, :3] = rgb.reshape(height, width, 3)
# Patch in bitmaps for every GL canvas
for glCanvas in glCanvases:
# If the colour bar is not displayed,
# the colour bar canvas will be None
if glCanvas is None:
continue
pos = relativePosition(glCanvas, parent)
size = glCanvas.GetSize().Get()
xstart = pos[0]
ystart = pos[1]
xend = xstart + size[0]
yend = ystart + size[1]
data[ystart:yend, xstart:xend] = glCanvas.getBitmap()
data[:, :, 3] = 255
mplimg.imsave(filename, data)
def doScreenshot():
# The typical way to get a screen grab of a wx
# Window is to use a wx.WindowDC, and a wx.MemoryDC,
# and to 'blit' a region from the window DC into
# the memory DC.
#
# This is precisely what we're doing here, but
# the process is complicated by the fact that,
# under OSX, the contents of wx.glcanvas.GLCanvas
# instances are not captured by WindowDCs.
#
# So I'm grabbing a screenshot of the canvas
# panel in the standard wxWidgets way, and then
# manually patching in bitmaps of each GLCanvas
# that is displayed in the canvas panel.
# Get all the wx GLCanvas instances
# which are displayed in the panel,
# including the colour bar canvas
glCanvases = canvasPanel.getGLCanvases()
glCanvases.append(canvasPanel.getColourBarCanvas())
# The canvas panel container is the
# direct parent of the colour bar
# canvas, and an ancestor of the
# other GL canvases
parent = canvasPanel.getCanvasContainer()
width, height = parent.GetClientSize().Get()
windowDC = wx.WindowDC(parent)
memoryDC = wx.MemoryDC()
bmp = wx.EmptyBitmap(width, height)
wx.Yield()
# Copy the contents of the canvas container
# to the bitmap
memoryDC.SelectObject(bmp)
memoryDC.Blit(
0,
0,
width,
height,
windowDC,
0,
0)
memoryDC.SelectObject(wx.NullBitmap)
# Make a H*W*4 bitmap array
data = np.zeros((height, width, 4), dtype=np.uint8)
rgb = bmp.ConvertToImage().GetData()
rgb = np.fromstring(rgb, dtype=np.uint8)
data[:, :, :3] = rgb.reshape(height, width, 3)
# Patch in bitmaps for every GL canvas
for glCanvas in glCanvases:
# If the colour bar is not displayed,
# the colour bar canvas will be None
if glCanvas is None:
continue
pos = relativePosition(glCanvas, parent)
size = glCanvas.GetSize().Get()
xstart = pos[0]
ystart = pos[1]
xend = xstart + size[0]
yend = ystart + size[1]
data[ystart:yend, xstart:xend] = glCanvas.getBitmap()
data[:, :, 3] = 255
mplimg.imsave(filename, data)
fsldlg.ProcessingDialog(
canvasPanel.GetTopLevelParent(),
strings.messages['CanvasPanel.screenshot.pleaseWait'],
doScreenshot).Run(mainThread=True)
fslsettings.write('canvasPanelScreenshotLastDir', op.dirname(filename))
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