Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Trying to append to Style (css) #105

@Neon22

Description

@Neon22

I have successfully made an initial style and added it under defs. but cannot append a new css style to this.

def create_CSS_styles(self):
        bg = (100,220,200)
        css = ".background { fill:"+svgwrite.rgb(*bg)+"; }\n"
        c = ["whitesquare", (200,200,0), (50,200,200)]
        css += "."+c[0]+" {fill:"+svgwrite.rgb(*c[1])+"; stroke:"+svgwrite.rgb(*c[2])+"}\n"
        self.dwg.defs.add(self.dwg.style(css))

This style is accessible and works as expected. Thanks.

The docs say I can append to this style element but I cant get it to work.

I can't find any code exercising this append() yet.
I've tried numerous variations. Including this:

def add_style(self, name, attributes):
        "use self.dwg.style.append() "
        c = ["blacksquare", (200,90,90), (50,200,200)]
        css = "."+c[0]+" {fill:"+svgwrite.rgb(*c[1])+"; stroke:"+svgwrite.rgb(*c[2])+"}\n"
        s = self.dwg.defs.get_xml().find("style")
        print(s)
        print(dir(s))
        #s.append(css)
        s.append(self.dwg.style(css))#.get_xml())

Any help on the right way to add a new css style to the existing style section under defs is greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions