init
StrategyContext()
Context class for drawing strategies.
This class is responsible for selecting the correct drawing strategy.
Attributes:
| Name | Type | Description |
|---|---|---|
_strategies |
dict
|
A dictionary of strategies with shape type as key and strategy as value. |
Source code in src/layerforge/svg/drawing/strategy_context.py
23 24 | |
draw(dwg, shape, **attribs)
Draws a shape using the appropriate drawing strategy.
The strategy makes the element and this method styles it, so the strokes of every shape are set in one place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dwg
|
Drawing
|
The SVG drawing to draw the shape on. |
required |
shape
|
BaseShape
|
The shape to draw. |
required |
**attribs
|
str
|
SVG attributes for the element, for example |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no strategy is found for the shape type. |
Source code in src/layerforge/svg/drawing/strategy_context.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
register_strategy(shape_type, strategy)
Registers a drawing strategy for a specific shape type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape_type
|
str
|
The type of shape to register the strategy for. |
required |
strategy
|
ShapeDrawingStrategy
|
The drawing strategy to register. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/layerforge/svg/drawing/strategy_context.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |