def __onCopyLut(self, ev): """Called when the user presses the *Copy LUT* button. Prompts the user to enter a name (via :func:`promptForLutName`), and then creates and registers a new :class:`.LookupTable` instance which is initialised with the same labels as the previously selected ``LookupTable``. Updates this ``LookupTablePanel`` via the :meth:`__updateLutChoices` and :meth:`__setLut` methods. """ oldKey = self.__selectedLut.key oldName = self.__selectedLut.name newKey, newName = promptForLutName('{} copy'.format(oldName)) if newKey is None: return log.debug('Creating and registering new ' 'LookupTable {} (copied from {})'.format(newKey, oldKey)) lut = fslcmaps.LookupTable(key=newKey, name=newName) for label in self.__selectedLut.labels(): lut.insert(label.value, name=label.name, colour=label.colour, enabled=label.enabled) fslcmaps.registerLookupTable(lut, self.overlayList, self.displayCtx) self.__updateLutChoices() self.__setLut(lut)
def __onLoadLut(self, ev): """Called when the user presses the *Load LUT* button. Does the following: - Prompts the user to select a LUT file with a ``wx.FileDialog`` - Prompts the user to enter a name for the LUT via the :func:`promptForLutName` function. - Creates and registers a new :class:`.LookupTable` instance, initialising it with the selected file. - Updates this ``LookupTablePanel`` via the :meth:`__updateLutChoices` and :meth:`__setLut` methods. """ parent = wx.GetApp().GetTopWindow() loadDir = fslsettings.read('fsleyes.loadlutdir', os.getcwd()) # Prompt the user to select a lut file fileDlg = wx.FileDialog(parent, defaultDir=loadDir, message=strings.titles[self, 'loadLut'], style=wx.FD_OPEN) if fileDlg.ShowModal() != wx.ID_OK: return lutFile = fileDlg.GetPath() lutDir = op.dirname(lutFile) lutName = op.splitext(op.basename(lutFile))[0] # Prompt the user to enter a name lutKey, lutName = promptForLutName(lutName) if lutKey is None: return # Register the lut errTitle = strings.titles[self, 'loadError'] errMsg = strings.messages[self, 'loadError'].format(lutFile) with status.reportIfError(errTitle, errMsg): lut = fslcmaps.registerLookupTable(lutFile, self.overlayList, self.displayCtx, key=lutKey, name=lutName) # Save the directory for next time fslsettings.write('fsleyes.loadlutdir', lutDir) # Select the lut in the panel self.__updateLutChoices() self.__setLut(lut)
def __onNewLut(self, ev): """Called when the user presses the *New LUT* button. Prompts the user to enter a name (via :func:`promptForLutName`), and then creates and registers a new :class:`.LookupTable` instance. Updates this ``LookupTablePanel`` via the :meth:`__updateLutChoices` and :meth:`__setLut` methods. """ key, name = promptForLutName() if key is None: return log.debug('Creating and registering new ' 'LookupTable: {}'.format(key)) lut = fslcmaps.LookupTable(key=key, name=name) fslcmaps.registerLookupTable(lut, self.overlayList, self.displayCtx) self.__updateLutChoices() self.__setLut(lut)
def test_register(): cmap = tw.dedent(""" 0 0 0 0 0 1 0 1 1 1 1 1 """).strip() lut = tw.dedent(""" 1 0 0 0 label 1 2 0 0 1 label 2 3 0 1 1 label 3 4 1 1 1 label 4 """).strip() with mockCmaps() as (assetDir, sdir): fslcm.init() with open('cmap.txt', 'wt') as f: f.write(cmap) with open('lut.txt', 'wt') as f: f.write(lut) assert not fslcm.isColourMapRegistered('mycmap') fslcm.registerColourMap('cmap.txt', key='mycmap', name='My cmap') fslcm.getColourMap('mycmap') assert fslcm.isColourMapRegistered('mycmap') assert not fslcm.isColourMapInstalled( 'mycmap') assert fslcm.getColourMapLabel('mycmap') == 'My cmap' fslcm.installColourMap('mycmap') assert fslcm.isColourMapInstalled( 'mycmap') assert not fslcm.isLookupTableRegistered('mylut') fslcm.registerLookupTable('lut.txt', key='mylut', name='My lut') assert fslcm.isLookupTableRegistered('mylut') assert not fslcm.isLookupTableInstalled( 'mylut') assert fslcm.getLookupTable('mylut').name == 'My lut' fslcm.installLookupTable('mylut') assert fslcm.isLookupTableInstalled( 'mylut')