Layout
Module¶
Map (x, y)
coordinates to instructions
-
class
knittingpattern.convert.Layout.
GridLayout
(pattern)[source]¶ Bases:
object
This class places the instructions at
(x, y)
positions.-
__init__
(pattern)[source]¶ Parameters: pattern¶ (knittingpattern.KnittingPattern.KnittingPattern) – the pattern to layout
-
__weakref__
¶ list of weak references to the object (if defined)
-
bounding_box
¶ The minimum and maximum bounds of this layout.
Returns: (min_x, min_y, max_x, max_y)
the bounding box of this layoutReturn type: tuple
-
row_in_grid
(row)[source]¶ The a RowInGrid for the row with position information.
Returns: a row in the grid Return type: RowInGrid
-
walk_connections
(mapping=<function identity>)[source]¶ Iterate over connections between instructions.
Returns: an iterator over connections
betweeninstructions in grid
Parameters: mapping¶ – funcion to map the result, see walk_instructions()
for an example usage
-
walk_instructions
(mapping=<function identity>)[source]¶ Iterate over instructions.
Returns: an iterator over instructions in grid
Parameters: mapping¶ – funcion to map the result for pos, c in layout.walk_instructions(lambda i: (i.xy, i.color)): print("color {} at {}".format(c, pos))
-
walk_rows
(mapping=<function identity>)[source]¶ Iterate over rows.
Returns: an iterator over rows
Parameters: mapping¶ – funcion to map the result, see walk_instructions()
for an example usage
-
-
class
knittingpattern.convert.Layout.
InstructionInGrid
(instruction, position)[source]¶ Bases:
knittingpattern.convert.Layout.InGrid
Holder of an instruction in the GridLayout.
-
__init__
(instruction, position)[source]¶ Parameters: - instruction¶ – an
instruction
- position¶ (Point) – the position of the
instruction
- instruction¶ – an
-
color
¶ The color of the instruction.
Returns: the color of the instruction
-
instruction
¶ The instruction.
Returns: instruction that is placed on the grid Return type: knittingpattern.Instruction.InstructionInRow
-
-
class
knittingpattern.convert.Layout.
Connection
(start, stop)[source]¶ Bases:
object
a connection between two
InstructionInGrid
objects-
__init__
(start, stop)[source]¶ Parameters: - start¶ (InstructionInGrid) – the start of the connection
- stop¶ (InstructionInGrid) – the end of the connection
-
__weakref__
¶ list of weak references to the object (if defined)
-
is_visible
()[source]¶ Returns: is this connection is visible Return type: bool A connection is visible if it is longer that 0.
-
start
¶ Returns: the start of the connection Return type: InstructionInGrid
-
stop
¶ Returns: the end of the connection Return type: InstructionInGrid
-
-
class
knittingpattern.convert.Layout.
Point
(x, y)¶ Bases:
tuple
-
__getnewargs__
()¶ Return self as a plain tuple. Used by copy and pickle.
-
static
__new__
(_cls, x, y)¶ Create new instance of Point(x, y)
-
__repr__
()¶ Return a nicely formatted representation string
-
x
¶ Alias for field number 0
-
y
¶ Alias for field number 1
-
-
knittingpattern.convert.Layout.
INSTRUCTION_HEIGHT
= 1¶ the default height of an instruction in the grid
-
class
knittingpattern.convert.Layout.
InGrid
(position)[source]¶ Bases:
object
Base class for things in a grid
-
__weakref__
¶ list of weak references to the object (if defined)
-
bounding_box
¶ The bounding box of this object.
Returns: (min x, min y, max x, max y) Return type: tuple
-
id
¶ The id of this object.
-
row
¶ Returns: row of the object on the grid Return type: knittingpattern.Row.Row
-
-
class
knittingpattern.convert.Layout.
RowInGrid
(row, position)[source]¶ Bases:
knittingpattern.convert.Layout.InGrid
Assign x and y coordinates to rows.
-
instructions
¶ The instructions in a grid.
Returns: the instructions in a grid
of this rowReturn type: list
-