示例#1
0
    def __init__(self, overlay, *args, **kwargs):
        """Create a ``LabelOpts`` instance for the specified ``overlay``.
        All arguments are passed through to the :class:`.NiftiOpts`
        constructor.
        """

        # Some FSL tools will set the nifti aux_file
        # field to the name of a colour map - Check
        # to see if this is the case (again, before
        # calling __init__, so we don't clobber any
        # existing values).
        aux_file = overlay.strval('aux_file').lower()

        if aux_file.startswith('mgh'):
            aux_file = 'freesurfercolorlut'

        # Check to see if any registered lookup table
        # has an ID that starts with the aux_file value.
        # Default to random lut if aux_file is empty,
        # or does not correspond to a registered lut.
        lut = 'random'

        if aux_file != '':
            luts = colourmaps.getLookupTables()
            luts = [l.key for l in luts if l.key.startswith(aux_file)]

            if len(luts) == 1:
                lut = luts[0]

        self.lut = lut

        niftiopts.NiftiOpts.__init__(self, overlay, *args, **kwargs)
示例#2
0
def test_init():

    with mockCmaps() as (assetDir, sdir):
        fslcm.init()

        cmap1 = op.join(assetDir, 'colourmaps', 'cmap1.cmap')
        cmap2 = op.join(sdir,     'colourmaps', 'cmap2.cmap')
        lut1  = op.join(assetDir, 'luts',       'lut1.lut')
        lut2  = op.join(sdir,     'luts',       'lut2.lut')

        assert fslcm.getColourMaps() == ['cmap1', 'cmap2']
        assert fslcm.getColourMapLabel( 'cmap1') == 'cmap1'
        assert fslcm.getColourMapLabel( 'cmap2') == 'cmap2'
        assert fslcm.getColourMapFile(  'cmap1') == cmap1
        assert fslcm.getColourMapFile(  'cmap2') == cmap2
        assert fslcm.getLookupTableFile('lut1')  == lut1
        assert fslcm.getLookupTableFile('lut2')  == lut2

        assert fslcm.isColourMapInstalled(   'cmap1')
        assert fslcm.isColourMapInstalled(   'cmap2')
        assert fslcm.isColourMapRegistered(  'cmap1')
        assert fslcm.isColourMapRegistered(  'cmap2')
        assert fslcm.isLookupTableInstalled( 'lut1')
        assert fslcm.isLookupTableInstalled( 'lut2')
        assert fslcm.isLookupTableRegistered('lut1')
        assert fslcm.isLookupTableRegistered('lut2')

        luts = fslcm.getLookupTables()
        assert len(luts)              == 2
        assert luts[0].key            == 'lut1'
        assert luts[1].key            == 'lut2'
示例#3
0
    def __setLut(self, lut):
        """Updates this ``LookupTablePanel`` to display the labels for the
        given ``lut`` (assumed to be a :class:`.LookupTable` instance).

        If the currently selected overlay is associated with a
        :class:`.LabelOpts` instance, its :attr:`.LabelOpts.lut` property is
        set to the new ``LookupTable``.
        """

        if self.__selectedLut == lut:
            return

        log.debug('Selecting lut: {}'.format(lut))

        if self.__selectedLut is not None:
            self.__selectedLut.deregister(self.name, 'saved')
            self.__selectedLut.deregister(self.name, 'added')
            self.__selectedLut.deregister(self.name, 'removed')

        self.__selectedLut = lut

        if lut is not None:
            lut.register(self.name, self.__lutSaveStateChanged, 'saved')
            lut.register(self.name, self.__lutLabelAdded, 'added')
            lut.register(self.name, self.__lutLabelRemoved, 'removed')

        if lut is not None and self.__selectedOpts is not None:
            with props.skip(self.__selectedOpts, 'lut', self.name):
                self.__selectedOpts.lut = lut

        allLuts = fslcmaps.getLookupTables()

        self.__lutChoice.SetSelection(allLuts.index(lut))

        self.__lutSaveStateChanged()
        self.__createLabelList()
示例#4
0
    def __updateLutChoices(self):
        """Refreshes the contents of the lookup table drop down box,
        using the :class:`.LookupTable` instances returned by the
        :func:`.colourmaps.getLookupTables` function.
        """

        log.debug('Updating lookup table choices')

        oldNames = self.__lutChoice.GetItems()
        oldSelection = self.__lutChoice.GetSelection()

        luts = fslcmaps.getLookupTables()
        newNames = [l.name for l in luts]

        try:
            newSelection = oldNames.index(oldNames[oldSelection])
        except Exception:
            newSelection = 0

        self.__lutChoice.SetItems(newNames)
        self.__lutChoice.SetSelection(newSelection)

        for i, lut in enumerate(luts):
            self.__lutChoice.SetClientData(i, lut)
示例#5
0
    def __init__(self, parent, overlayList, displayCtx, frame):
        """Create a ``LookupTablePanel``.

        :arg parent:      The :mod:`wx` parent object.
        :arg overlayList: The :class:`.OverlayList` instance.
        :arg displayCtx:  The :class:`.DisplayContext` instance.
        :arg frame:       The :class:`.FSLeyesFrame` instance.
        """

        ctrlpanel.ControlPanel.__init__(self, parent, overlayList, displayCtx,
                                        frame)

        self.__controlCol = wx.Panel(self)
        self.__labelList = elistbox.EditableListBox(
            self,
            style=(elistbox.ELB_NO_MOVE | elistbox.ELB_NO_ADD
                   | elistbox.ELB_NO_REMOVE | elistbox.ELB_WIDGET_RIGHT))

        self.__lutChoice = wx.Choice(self.__controlCol)
        self.__selAllButton = wx.Button(self.__controlCol)
        self.__selNoneButton = wx.Button(self.__controlCol)
        self.__addLabelButton = wx.Button(self.__controlCol)
        self.__rmLabelButton = wx.Button(self.__controlCol)
        self.__newLutButton = wx.Button(self.__controlCol)
        self.__copyLutButton = wx.Button(self.__controlCol)
        self.__saveLutButton = wx.Button(self.__controlCol)
        self.__loadLutButton = wx.Button(self.__controlCol)

        self.__controlColSizer = wx.BoxSizer(wx.VERTICAL)
        self.__sizer = wx.BoxSizer(wx.VERTICAL)

        self.__controlCol.SetSizer(self.__controlColSizer)
        self.SetSizer(self.__sizer)

        self.__controlColSizer.Add(self.__lutChoice, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__selAllButton, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__selNoneButton, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__addLabelButton, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__rmLabelButton, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__newLutButton, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__copyLutButton, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__loadLutButton, flag=wx.EXPAND)
        self.__controlColSizer.Add(self.__saveLutButton, flag=wx.EXPAND)

        self.__sizer.Add(self.__controlCol, flag=wx.EXPAND)
        self.__sizer.Add(self.__labelList, flag=wx.EXPAND, proportion=1)

        # Label the buttons
        self.__selAllButton.SetLabel(strings.labels[self, 'selectAll'])
        self.__selNoneButton.SetLabel(strings.labels[self, 'selectNone'])
        self.__addLabelButton.SetLabel(strings.labels[self, 'addLabel'])
        self.__rmLabelButton.SetLabel(strings.labels[self, 'removeLabel'])
        self.__newLutButton.SetLabel(strings.labels[self, 'newLut'])
        self.__copyLutButton.SetLabel(strings.labels[self, 'copyLut'])
        self.__loadLutButton.SetLabel(strings.labels[self, 'loadLut'])
        self.__saveLutButton.SetLabel(strings.labels[self, 'saveLut'])

        self.__lutChoice.Bind(wx.EVT_CHOICE, self.__onLutChoice)
        self.__selAllButton.Bind(wx.EVT_BUTTON, self.__onSelectAll)
        self.__selNoneButton.Bind(wx.EVT_BUTTON, self.__onSelectNone)
        self.__addLabelButton.Bind(wx.EVT_BUTTON, self.__onLabelAdd)
        self.__rmLabelButton.Bind(wx.EVT_BUTTON, self.__onLabelRemove)
        self.__newLutButton.Bind(wx.EVT_BUTTON, self.__onNewLut)
        self.__copyLutButton.Bind(wx.EVT_BUTTON, self.__onCopyLut)
        self.__loadLutButton.Bind(wx.EVT_BUTTON, self.__onLoadLut)
        self.__saveLutButton.Bind(wx.EVT_BUTTON, self.__onSaveLut)

        # The selected overlay / DisplayOpts
        # are tracked if they use an LUT
        # (e.g. LabelOpts). And the currently
        # selected/displayed LUT is always
        # tracked.
        self.__selectedOverlay = None
        self.__selectedOpts = None
        self.__selectedLut = None

        # See the __createLabelList method
        self.__labelListCreateKey = 0

        overlayList.addListener('overlays', self.name,
                                self.__selectedOverlayChanged)
        displayCtx.addListener('selectedOverlay', self.name,
                               self.__selectedOverlayChanged)

        self.__updateLutChoices()
        self.__selectedOverlayChanged()

        # If the selected lut was not set
        # via the selectedOverlayChanged
        # call, we'll manually set it here
        if self.__selectedLut is None:
            self.__setLut(fslcmaps.getLookupTables()[0])

        self.Layout()

        # The label values (used as labels in the
        # EditableListBox) seem to get squashed
        # easily. So we're adding a bit of padding
        # to force this panel to have a minimum
        # size, to ensure that the labels are
        # visible.
        dc = wx.ClientDC(self.__labelList)
        w, h = dc.GetTextExtent('9999')
        minSize = self.__sizer.GetMinSize()
        self.SetMinSize((minSize[0] + w, minSize[1]))