InstructionToSVG Module

This module maps instructions to SVG.

Use default_instructions_to_svg() to load the svg files provided by this package.

class knittingpattern.convert.InstructionToSVG.InstructionToSVG[source]

Bases: object

This class maps instructions to SVGs.

__init__()[source]

create a InstructionToSVG object without arguments.

__weakref__

list of weak references to the object (if defined)

default_instruction_to_svg(instruction)[source]

As instruction_to_svg() but it only takes the default.svg file into account.

In case no file is found for an instruction in instruction_to_svg(), this method is used to determine the default svg for it.

The content is created by replacing the text {instruction.type} in the whole svg file named default.svg.

If no file default.svg was loaded, an empty string is returned.

default_instruction_to_svg_dict(instruction)[source]

Returns an xml-dictionary with the same content as default_instruction_to_svg()

If no file default.svg was loaded, an empty svg-dict is returned.

has_svg_for_instruction(instruction)[source]
Returns:whether there is an image for the instruction
Return type:bool

This can be used before instruction_to_svg() as it determines whether

  • the default value is used (False)
  • or there is a dedicated svg representation (True).
instruction_to_svg(instruction)[source]
Returns:an SVG representing the instruction.

The SVG file is determined by the type attribute of the instruction. An instruction of type "knit" is looked for in a file named "knit.svg".

Every element inside a group labeled "color" of mode "layer" that has a "fill" style gets this fill replaced by the color of the instruction. Example of a recangle that gets filled like the instruction:

<g inkscape:label="color" inkscape:groupmode="layer">
    <rect style="fill:#ff0000;fill-opacity:1;fill-rule:nonzero"
          id="rectangle1" width="10" height="10" x="0" y="0" />
</g>

If nothing was loaded to display this instruction, a default image is be generated by default_instruction_to_svg().

instruction_to_svg_dict(instruction)[source]
Returns:an xml-dictionary with the same content as instruction_to_svg().
load
Returns:a loader object that allows loading SVG files from various sources such as files and folders.
Return type:knittingpattern.Loader.PathLoader

Examples:

  • instruction_to_svg.load.path(path) loads an SVG from a file named path
  • instruction_to_svg.load.folder(path) loads all SVG files for instructions in the folder recursively. If multiple files have the same name, the last occurrence is used.
knittingpattern.convert.InstructionToSVG.default_instructions_to_svg()[source]

load the default set of svg files for instructions

Returns:the default svg files for the instructions in this package
Return type:knittingpattern.InstructionToSVG.InstructionToSVG
knittingpattern.convert.InstructionToSVG.DEFAULT_SVG_FOLDER = 'instruction-svgs'

The name of the folder containing the svg files for the default instructions.