def restore_layers(self, layers, context): """ Restore a list of glue-serialized layer dicts """ for layer in layers: c = lookup_class(layer.pop('_type')) props = dict((k, v if k == 'stretch' else context.object(v)) for k, v in layer.items()) l = props['layer'] if issubclass(c, ScatterLayerBase): l = self.add_scatter_layer(l) elif issubclass(c, RGBImageLayerBase): r = props.pop('r') g = props.pop('g') b = props.pop('b') self.display_data = l self.display_attribute = r l = self.rgb_mode(True) l.r = r l.g = g l.b = b elif issubclass(c, (ImageLayerBase, SubsetImageLayerBase)): if isinstance(l, Data): self.set_data(l) l = self.add_layer(l) else: raise ValueError("Cannot restore layer of type %s" % l) l.properties = props
def lookup_class_with_patches(name): """ A wrapper to lookup_class that also patches paths to ensure backward-compatibility when functions/classes are moved around. """ while name in PATH_PATCHES: name = PATH_PATCHES[name] return lookup_class(name)
def restore_layers(self, layers, context): for layer in layers: lcls = lookup_class(layer.pop('_type')) if lcls != HistogramLayerArtist: raise ValueError("Cannot restore layers of type %s" % lcls) data_or_subset = context.object(layer.pop('layer')) result = self.add_layer(data_or_subset) result.properties = layer
def restore_layers(self, layers, context): """ Re-generate a list of plot layers from a glue-serialized list""" for l in layers: cls = lookup_class(l.pop('_type')) if cls != ScatterLayerArtist: raise ValueError("Scatter client cannot restore layer of type " "%s" % cls) props = dict((k, context.object(v)) for k, v in l.items()) layer = self.add_layer(props['layer']) layer.properties = props