svgen.attribute package — docs

Skip to main content
`Ctrl`+`K`

# svgen.attribute package

## Submodules

## svgen.attribute.style module

svgen - A module for the ‘style’ attribute.

class svgen.attribute.style.CssProperty(key: str, value: str)

  Bases: `NamedTuple`

  A class for interacting with css properties.

  static color(color: str | Hsl | Rgb | Color, prop: str = 'fill', **kwargs) → CssProperty

    Get a CSS property for a color.

  static decode(value: str) → list[CssProperty]

    Create css properties from a string.

  static encode(props: list[CssProperty]) → str

    Encode a list of css properties to a string.

  property encoded: str

    Convert this css property to a string.

  static from_dict(data: dict[str, str | int | float]) → list[CssProperty]

    Get a list of attributes from dictionary data.

  key: str

    Alias for field number 0

  value: str

    Alias for field number 1

class svgen.attribute.style.Style(props: dict[str, str | int | float] | list[CssProperty] | CssProperty = None)

  Bases: `Attribute`

  An interface for style attributes.

  add(props: dict[str, str | int | float] | list[CssProperty] | CssProperty) → None

    Add CSS properties to this style instance.

  add_color(color: str | Hsl | Rgb | Color, prop: str = 'fill', **kwargs) → Style

    Set a style property to a color.

  classmethod decode(key: str, value: str) → Style

    Create this attribute from a string.

  properties: list[CssProperty]
  property value: str

    Get the string value for this attribute.

svgen.attribute.style.properties(data: dict[str, str | int | float] | list[CssProperty] | CssProperty = None) → list[CssProperty]

  Get properties from either an existing list of properties, or dictionary data.

## svgen.attribute.viewbox module

svgen - A module for the ‘viewBox’ attribute.

class svgen.attribute.viewbox.ViewBox(min_x: int, min_y: int, width: int, height: int)

  Bases: `Attribute`

  An interface for viewBox attributes.

  property center: Point

    Get the center point for this viewBox.

  classmethod decode(key: str, value: str) → ViewBox

    Create this attribute from a string.

  property dimensions: Dimensions

    Get this viewBox’s dimensions.

  static from_dict(data: dict[str, Any]) → ViewBox

    Create a viewBox from dictionary data.

  property height: int

    Get the height of this viewbox.

  property key: str

    Get the string key for this attribute.

  new_grid(rect: Rectangle = None, columns: int = None, rows: int = None) → RectangleGrid

    Create a grid from this viewBox.

  property origin: Point

    Get this viewBox’s origin.

  translate(dx: Translation | float, *args, **kwargs) → None

    Apply a translation to this viewBox.

  property value: str

    Get the string value for this attribute.

  property width: int

    Get the width of this viewbox.

class svgen.attribute.viewbox.ViewBoxData(min_x: int, min_y: int, width: int, height: int)

  Bases: `NamedTuple`

  Primitive data for a viewBox attribute.

  property center: Point

    Get the center point for this viewBox.

  static from_dict(data: dict[str, Any]) → ViewBoxData

    Create viewBox data from a dictionary.

  height: int

    Alias for field number 3

  min_x: int

    Alias for field number 0

  min_y: int

    Alias for field number 1

  property origin: Point

    Get the origin for this viewBox.

  translate(dx: int, dy: int) → ViewBoxData

    Translate this viewBox.

  width: int

    Alias for field number 2

## Module contents

svgen - A module for XML-style attribute interfaces.

class svgen.attribute.Attribute

  Bases: `ABC`

  An interface for an XML-style attribute.

  abstractmethod classmethod decode(key: str, value: str) → T

    Create this attribute from a string.

  encode(quote: str = '"', force: bool = False) → str

    Convert this attribute to a string.

  property key: str

    Get the string key for this attribute.

  abstract property value: str

    Get the string value for this attribute.

class svgen.attribute.SimpleAttribute(name: str, value: str | int | float | bool)

  Bases: `Attribute`

  A simple, concrete implementation for attribute.

  classmethod decode(key: str, value: str) → SimpleAttribute

    Create this attribute from a string.

  static from_dict(data: dict[str, str | int | float]) → list[Attribute]

    Get a list of attributes from dictionary data.

  property value: str

    Get the string value for this attribute.

svgen.attribute.attributes(data: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None) → list[Attribute]

  Get attributes from either an existing list of attributes, or dictionary data.