def __init__(self, overlayList, displayCtx): """Adds a few listeners to the properties of this object, to update the colour bar when they change. """ self.__tex = None self.__name = '{}_{}'.format(self.__class__.__name__, id(self)) self.__cbar = cbar.ColourBar(overlayList, displayCtx) self.__cbar.register(self.__name, self.updateColourBarTexture) self.addListener('barSize', self.__name, self.updateColourBarTexture) self.addListener('highDpi', self.__name, self.__highDpiChanged)
def buildColourBarBitmap(overlayList, displayCtx, width, height, sceneOpts): """If the currently selected overlay has a display range, creates and returns a bitmap containing a colour bar. Returns ``None`` otherwise. :arg overlayList: The :class:`.OverlayList`. :arg displayCtx: The :class:`.DisplayContext`. :arg width: Colour bar width in pixels. :arg height: Colour bar height in pixels. :arg sceneOpts: :class:`.SceneOpts` instance containing display settings. """ overlay = displayCtx.getSelectedOverlay() display = displayCtx.getDisplay(overlay) opts = display.opts cbarLocation = sceneOpts.colourBarLocation cbarSize = sceneOpts.colourBarSize if cbarLocation in ('top', 'bottom'): width = width * cbarSize / 100.0 elif cbarLocation in ('left', 'right'): height = height * cbarSize / 100.0 if not isinstance(opts, displaycontext.ColourMapOpts): return None if cbarLocation in ('top', 'bottom'): orient = 'horizontal' elif cbarLocation in ('left', 'right'): orient = 'vertical' cb = cbar.ColourBar(overlayList, displayCtx) cb.orientation = orient cb.labelSide = sceneOpts.colourBarLabelSide cb.bgColour = sceneOpts.bgColour cb.textColour = sceneOpts.fgColour cb.fontSize = sceneOpts.labelSize cbarBmp = cb.colourBar(width, height) # The colourBarBitmap function returns a w*h*4 # array, but the fsleyes_widgets.utils.layout.Bitmap # (see the next function) assumes a h*w*4 array cbarBmp = cbarBmp.transpose((1, 0, 2)) return cbarBmp
def _ColourMapOpts_ColourMapWidget(target, parent, panel, overlayList, displayCtx, threedee): """Builds a panel which contains widgets for controlling the :attr:`.ColourMapOpts.cmap`, :attr:`.ColourMapOpts.negativeCmap`, and :attr:`.ColourMapOpts.useNegativeCmap`. :returns: A ``wx.Sizer`` containing all of the widgets, and a list containing the extra widgets that were added. """ # Button to load a new # colour map from file loadAction = loadcmap.LoadColourMapAction(overlayList, displayCtx) loadButton = wx.Button(parent) loadButton.SetLabel(strings.labels[panel, 'loadCmap']) loadAction.bindToWidget(panel, wx.EVT_BUTTON, loadButton) cmap = getWidgetSpecs(target, threedee)['cmap'] negCmap = getWidgetSpecs(target, threedee)['negativeCmap'] useNegCmap = getWidgetSpecs(target, threedee)['useNegativeCmap'] cbpanel = imagepanel.ImagePanel(parent) cbpanel.SetMinSize((-1, 30)) colourbar = cbar.ColourBar(overlayList, displayCtx) colourbar.bgColour = (0, 0, 0, 0) colourbar.showLabel = False colourbar.showTicks = False def cbarUpdate(*a): w, h = cbpanel.GetSize().Get() if w < 20 or h < 20: return bmp = colourbar.colourBar(w, h) if bmp is None: return if fwidgets.wxversion() == fwidgets.WX_PHOENIX: bmp = wx.Bitmap.FromBufferRGBA(w, h, bmp.transpose(1, 0, 2)) else: bmp = wx.BitmapFromBufferRGBA(w, h, bmp.transpose(1, 0, 2)) cbpanel.SetImage(bmp.ConvertToImage()) lname = 'ColourBarWidget_{}'.format(colourbar) def onDestroy(ev): colourbar.deregister(lname) colourbar.destroy() colourbar.register(lname, cbarUpdate) cbpanel.Bind(wx.EVT_SIZE, cbarUpdate) cbpanel.Bind(wx.EVT_WINDOW_DESTROY, onDestroy) cbarUpdate() cmap = props.buildGUI(parent, target, cmap) negCmap = props.buildGUI(parent, target, negCmap) useNegCmap = props.buildGUI(parent, target, useNegCmap) useNegCmap.SetLabel(strings.properties[target, 'useNegativeCmap']) sizer = wx.GridBagSizer() sizer.AddGrowableCol(0) sizer.Add(cbpanel, (0, 0), (1, 2), flag=wx.EXPAND) sizer.Add(cmap, (1, 0), (1, 1), flag=wx.EXPAND) sizer.Add(loadButton, (1, 1), (1, 1), flag=wx.EXPAND) sizer.Add(negCmap, (2, 0), (1, 1), flag=wx.EXPAND) sizer.Add(useNegCmap, (2, 1), (1, 1), flag=wx.EXPAND) return sizer, [cmap, negCmap, useNegCmap]