diff --git a/fsl/fslview/controls/locationpanel.py b/fsl/fslview/controls/locationpanel.py index 2029d76c1dde139dd22059771a8e4b3d86e67a94..5f505c6bb7ca6c8d65d17b541d9b880bdbdfaf0e 100644 --- a/fsl/fslview/controls/locationpanel.py +++ b/fsl/fslview/controls/locationpanel.py @@ -26,6 +26,7 @@ import props import fsl.utils.transform as transform import fsl.data.image as fslimage +import fsl.data.constants as constants import fsl.data.strings as strings import fsl.fslview.panel as fslpanel @@ -159,8 +160,6 @@ class LocationPanel(fslpanel.FSLViewPanel): self.column1.SetSizer(self.column1Sizer) self.column2.SetSizer(self.column2Sizer) self .SetSizer(self.sizer) - - self.Layout() self._overlayList.addListener('overlays', self._name, @@ -183,9 +182,57 @@ class LocationPanel(fslpanel.FSLViewPanel): self._selectedOverlayChanged() + self.worldLabel.SetMinSize(self.__calcWorldLabelMinSize()) + self.info .SetMinSize((150, 100)) + self.Layout() self.SetMinSize(self.sizer.GetMinSize()) + def __calcWorldLabelMinSize(self): + """Calculates the minimum size that the world label (the label which + shows the coordinate space of the currently selected overlay) needs. + + The world label displays different things depending on the currently + selected overlay. But we want it to be a fixed size. So this method + calculates the size of all possible values that the world label will + display, and returns the maximum size. This is then used as the + minimum size for the world label. + """ + + dc = wx.ClientDC(self.worldLabel) + + width, height = 0, 0 + + labelPref = strings.labels[self, 'worldLocation'] + labelSufs = [ + strings.anatomy[fslimage.Image, + 'space', + constants.NIFTI_XFORM_UNKNOWN], + strings.anatomy[fslimage.Image, + 'space', + constants.NIFTI_XFORM_SCANNER_ANAT], + strings.anatomy[fslimage.Image, + 'space', + constants.NIFTI_XFORM_ALIGNED_ANAT], + strings.anatomy[fslimage.Image, + 'space', + constants.NIFTI_XFORM_TALAIRACH], + strings.anatomy[fslimage.Image, + 'space', + constants.NIFTI_XFORM_MNI_152], + strings.labels[self, 'worldLocation', 'unknown'] + ] + + for labelSuf in labelSufs: + + w, h = dc.GetTextExtent(labelPref + labelSuf) + + if w > width: width = w + if h > height: height = h + + return width + 5, height + 5 + + def destroy(self): """Deregisters property listeners.""" diff --git a/fsl/fslview/controls/lookuptablepanel.py b/fsl/fslview/controls/lookuptablepanel.py index f4eb0da21315cd347c32724185c323be11ea4a41..1b17e7f739f45724e987a3caa6265cdbfc9049f7 100644 --- a/fsl/fslview/controls/lookuptablepanel.py +++ b/fsl/fslview/controls/lookuptablepanel.py @@ -6,6 +6,7 @@ # import os +import copy import logging import wx @@ -17,7 +18,7 @@ import props import pwidgets.elistbox as elistbox import fsl.fslview.panel as fslpanel -import fsl.fslview.displaycontext as fsldisplay +import fsl.fslview.displaycontext as displayctx import fsl.fslview.colourmaps as fslcmaps import fsl.data.strings as strings @@ -163,8 +164,47 @@ class LookupTablePanel(fslpanel.FSLViewPanel): self._name, self.__selectedOverlayChanged) + self.__disabledLabel.Show(False) + self.__controlRowSizer.SetMinSize(self.__calcControlRowMinSize()) + self.Layout() + self.SetMinSize(self.__sizer.GetMinSize()) + self.__selectedOverlayChanged() + + def __calcControlRowMinSize(self): + """This method calculates and returns a minimum width and height + for the control row. + + When the LookupTable is first created, there is no LUT widget - it is + created when an appropriate overlay is selected (see + :meth:`__overlayTypeChanged`). Here, we create a dummy LUT widget, and + use its best size, along with the control row button sizes, to + calculate the minimum size needed to lay out the control row. + """ + + class DummyLut(props.HasProperties): + lut = copy.copy(displayctx.LabelOpts.lut) + + dl = DummyLut() + dummyLutWidget = props.makeWidget(self, dl, 'lut') + width, height = dummyLutWidget.GetBestSize().Get() + + for btn in [self.__newLutButton, + self.__copyLutButton, + self.__saveLutButton, + self.__loadLutButton]: + + w, h = btn.GetBestSize().Get() + width += w + + if h > height: + height = h + + dummyLutWidget.Destroy() + + return width, height + def destroy(self): @@ -252,7 +292,7 @@ class LookupTablePanel(fslpanel.FSLViewPanel): if overlay is not None: opts = self._displayCtx.getOpts(overlay) - if isinstance(opts, fsldisplay.LabelOpts): + if isinstance(opts, displayctx.LabelOpts): enabled = True self.__overlayNameLabel.Show( enabled)