(self, name, pngdata=None, add_path=True)
Adds projected data for defining a new ROI to the saved overlays.svg file in a new layer
Adds projected data for defining a new ROI to the saved overlays.svg file in a new layer
Adds projected data for defining a new ROI to the saved overlays . svg file in a new layer
def add_shape(self, name, pngdata=None, add_path=True):
        """Adds projected data for defining a new ROI to the saved overlays.svg file in a new layer"""
        # self.svg deletes the images -- we want to save those, so let's load it again
        svg = etree.parse(self.svgobject.svgfile, parser=parser)
        imglayer = _find_layer(svg, "data")
        if add_path:
            layer = _find_layer(svg, self.name)
            _make_layer(_find_layer(layer, "shapes"), name)

        # Hide all the other layers in the image
        for layer in imglayer.findall(".//{%s}g"%svgns):
            layer.attrib["style"] = "display:hidden;"

        layer = _make_layer(imglayer, "img_%s"%name)
        layer.append(E.image(
            {"{http://www.w3.org/1999/xlink}href":"data:image/png;base64,%s"%pngdata},
            id="image_%s"%name, x="0", y="0",
            width=str(self.svgobject.svgshape[0]),
            height=str(self.svgobject.svgshape[1]),
        ))

        with open(self.svgobject.svgfile, "wb") as xml:
            #try:
            xml.write(etree.tostring(svg, pretty_print=True))
def add_shape ( self , name , pngdata = None , add_path = True ) : # self.svg deletes the images -- we want to save those, so let's load it again svg = etree . parse ( self . svgobject . svgfile , parser = parser ) imglayer = _find_layer ( svg , "data" ) if add_path : layer = _find_layer ( svg , self . name ) _make_layer ( _find_layer ( layer , "shapes" ) , name ) # Hide all the other layers in the image for layer in imglayer . findall ( ".//{%s}g" % svgns ) : layer . attrib [ "style" ] = "display:hidden;" layer = _make_layer ( imglayer , "img_%s" % name ) layer . append ( E . image ( { "{http://www.w3.org/1999/xlink}href" : "data:image/png;base64,%s" % pngdata } , id = "image_%s" % name , x = "0" , y = "0" , width = str ( self . svgobject . svgshape [ 0 ] ) , height = str ( self . svgobject . svgshape [ 1 ] ) , ) ) with open ( self . svgobject . svgfile , "wb" ) as xml : #try: xml . write ( etree . tostring ( svg , pretty_print = True ) )