def restoreSettings(self): """Restore the settings of all the application""" settings = self.__settings if settings is None: return parent = self.__parent() parent.restoreSettings(settings) settings.beginGroup("colormap") byteArray = settings.value("default", None) if byteArray is not None: try: colormap = Colormap() colormap.restoreState(byteArray) self.__defaultColormap = colormap except Exception: _logger.debug("Backtrace", exc_info=True) settings.endGroup() self.__recentFiles = [] settings.beginGroup("recent-files") for index in range(1, 10 + 1): if not settings.contains("path%d" % index): break filePath = settings.value("path%d" % index) self.__recentFiles.append(filePath) settings.endGroup()
def testStorageV1(self): state = b'\x00\x00\x00\x10\x00C\x00o\x00l\x00o\x00r\x00m\x00a\x00p\x00\x00'\ b'\x00\x01\x00\x00\x00\x0E\x00v\x00i\x00r\x00i\x00d\x00i\x00s\x00'\ b'\x00\x00\x00\x06\x00?\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ b'\x00\x06\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00'\ b'l\x00o\x00g' state = qt.QByteArray(state) colormap = Colormap() colormap.restoreState(state) expected = Colormap(name="viridis", vmin=1, vmax=2, normalization=Colormap.LOGARITHM) self.assertEqual(colormap, expected)
def testStorageV2(self): state = b'\x00\x00\x00\x10\x00C\x00o\x00l\x00o\x00r\x00m\x00a\x00p\x00'\ b'\x00\x00\x02\x00\x00\x00\x0e\x00v\x00i\x00r\x00i\x00d\x00i\x00'\ b's\x00\x00\x00\x00\x06\x00?\xf0\x00\x00\x00\x00\x00\x00\x00\x00'\ b'\x00\x00\x06\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06'\ b'\x00l\x00o\x00g\x00\x00\x00\x0c\x00m\x00i\x00n\x00m\x00a\x00x' state = qt.QByteArray(state) colormap = Colormap() colormap.restoreState(state) expected = Colormap(name="viridis", vmin=1, vmax=2, normalization=Colormap.LOGARITHM) expected.setGammaNormalizationParameter(1.5) self.assertEqual(colormap, expected)
def testStoreRestore(self): colormaps = [ Colormap(name="viridis"), Colormap(normalization=Colormap.SQRT) ] cmap = Colormap(normalization=Colormap.GAMMA) cmap.setGammaNormalizationParameter(1.2) cmap.setNaNColor('red') colormaps.append(cmap) for expected in colormaps: with self.subTest(colormap=expected): state = expected.saveState() result = Colormap() result.restoreState(state) self.assertEqual(expected, result)
def testEditableMode(self): """Make sure the colormap will raise NotEditableError when try to change a colormap not editable""" colormap = Colormap() colormap.setEditable(False) with self.assertRaises(NotEditableError): colormap.setVRange(0., 1.) with self.assertRaises(NotEditableError): colormap.setVMin(1.) with self.assertRaises(NotEditableError): colormap.setVMax(1.) with self.assertRaises(NotEditableError): colormap.setNormalization(Colormap.LOGARITHM) with self.assertRaises(NotEditableError): colormap.setName('magma') with self.assertRaises(NotEditableError): colormap.setColormapLUT([[0., 0., 0.], [1., 1., 1.]]) with self.assertRaises(NotEditableError): colormap._setFromDict(colormap._toDict()) state = colormap.saveState() with self.assertRaises(NotEditableError): colormap.restoreState(state)
def testEditableMode(self): """Make sure the colormap will raise NotEditableError when try to change a colormap not editable""" colormap = Colormap() colormap.setEditable(False) with self.assertRaises(NotEditableError): colormap.setVRange(0., 1.) with self.assertRaises(NotEditableError): colormap.setVMin(1.) with self.assertRaises(NotEditableError): colormap.setVMax(1.) with self.assertRaises(NotEditableError): colormap.setNormalization(Colormap.LOGARITHM) with self.assertRaises(NotEditableError): colormap.setName('magma') with self.assertRaises(NotEditableError): colormap.setColormapLUT(numpy.array([0, 1])) with self.assertRaises(NotEditableError): colormap._setFromDict(colormap._toDict()) state = colormap.saveState() with self.assertRaises(NotEditableError): colormap.restoreState(state)