knit_script.knit_script_interpreter.scope.gauged_sheet_schema.Sheet module

Module containing the Sheet class.

This module provides the Sheet class, which represents a single sheet in a gauged knitting configuration. A sheet maintains records of loop positions and provides access to needles that belong to the sheet based on the gauge spacing.

The Sheet class is fundamental to multi-sheet knitting operations, where different parts of the knitting process are organized across multiple virtual sheets that correspond to different needle positions in a gauged pattern.

class Sheet(sheet_number, gauge, knitting_machine)[source]

Bases: object

Record of the position of loops on a sheet defined by the current gauging schema.

A Sheet represents one layer in a multi-sheet knitting configuration, where needles are organized according to a gauge pattern. Each sheet maintains a record of which needles currently hold loops and provides methods to access needles that belong to this particular sheet.

The sheet system allows for complex knitting patterns where different operations are performed on different subsets of needles in a structured, repeating pattern based on the gauge value.

knitting_machine

The knitting machine that this sheet operates on.

Type:

Knitting_Machine

gauge

The gauge value that determines needle spacing and sheet count.

Type:

int

sheet_number

The index of this sheet within the gauge configuration.

Type:

int

loop_record

Dictionary mapping in-sheet needle positions to tuples indicating whether loops are recorded on the front and back needles at that position.

Type:

dict[int, tuple[bool, bool]]

Parameters:
  • sheet_number (int)

  • gauge (int)

  • knitting_machine (Knitting_Machine)

__init__(sheet_number, gauge, knitting_machine)[source]

Initialize a sheet with the specified number, gauge, and knitting machine.

Creates a new sheet that will manage a subset of needles on the knitting machine according to the gauge pattern. The sheet records the initial state of all needles that belong to it.

Parameters:
  • sheet_number (int) – The index of this sheet within the gauge configuration. Must be non-negative and less than the gauge value.

  • gauge (int) – The gauge value that determines the spacing pattern for needle organization. Must be positive.

  • knitting_machine (Knitting_Machine) – The knitting machine instance that this sheet will manage needles for.

Raises:

Sheet_Value_Exception – If sheet_number is negative or greater than or equal to the gauge value.

record_needle(sheet_needle)[source]

Record the state of the given sheet needle and its opposite needle.

Updates the loop record for the specified sheet needle position by recording the current loop state of both the front and back needles at that position.

Parameters:

sheet_needle (Sheet_Needle) – The sheet needle to record the state of. Must be a valid sheet needle that belongs to this sheet.

Return type:

None

Note

This method records the state of both the specified needle and its opposite bed counterpart, maintaining consistency in the loop record.

record_sheet()[source]

Record the loop locations for needles in the sheet given the current state of the knitting machine.

Updates the entire loop record for this sheet by examining the current state of all needles that belong to the sheet. This method provides a way to synchronize the sheet’s record with the actual machine state.

Note

This operation examines all needle positions in the sheet and updates the loop record accordingly. It’s useful after operations that may have changed the loop distribution across the sheet.

Return type:

None

sheet_needle(is_front, in_sheet_position, is_slider=False)[source]

Get a Sheet_Needle from this sheet set with the given parameters.

Creates a sheet needle object that belongs to this sheet with the specified characteristics. The needle will be positioned according to the sheet’s gauge configuration.

Parameters:
  • is_front (bool) – If True, return a needle on the front bed. Otherwise, return a back-bed needle.

  • in_sheet_position (int) – The position of the needle relative to the sheet (not the actual needle bed position). This is the index within this sheet’s needle sequence.

  • is_slider (bool, optional) – If True, return a slider needle. Otherwise, return a standard needle. Defaults to False.

Returns:

A Sheet_Needle from this sheet with the specified parameters, properly configured for the sheet’s gauge and position.

Return type:

Sheet_Needle

get_matching_sheet_needle(other_sheet_needle)[source]

Get a sheet needle belonging to this sheet at the same sheet position as a given sheet needle.

Creates a needle that belongs to this sheet but has the same relative position and characteristics as the provided needle from another sheet. This is useful for operations that need to work with corresponding needles across different sheets.

Parameters:

other_sheet_needle (Sheet_Needle) – The sheet needle to find a match for in this sheet. The returned needle will have the same bed position, sheet position, and slider status.

Returns:

A sheet needle belonging to this sheet at the same sheet position as the given sheet needle, with matching characteristics.

Return type:

Sheet_Needle

__eq__(other)[source]

Check equality with another Sheet or integer.

Parameters:

other (Sheet | int) – The object to compare with. Can be another Sheet or an integer representing a sheet number.

Returns:

True if the objects are equal, False otherwise.

Return type:

bool

Note

When comparing with another Sheet, both sheet_number and gauge must match. When comparing with an integer, only the sheet_number is compared.

front_needles()[source]

Get the set of front bed needles on the machine that belong to this sheet.

Returns all front bed needles that are part of this sheet according to the gauge configuration. Needles are selected using the gauge spacing pattern starting from this sheet’s offset.

Returns:

The set of front bed needles on the machine that belong to this sheet, ordered by position.

Return type:

list[Needle]

back_needles()[source]

Get the set of back bed needles on the machine that belong to this sheet.

Returns all back bed needles that are part of this sheet according to the gauge configuration. Needles are selected using the gauge spacing pattern starting from this sheet’s offset.

Returns:

The set of back bed needles on the machine that belong to this sheet, ordered by position.

Return type:

list[Needle]

front_sliders()[source]

Get the set of front bed slider needles on the machine that belong to this sheet.

Returns all front bed slider needles that are part of this sheet according to the gauge configuration. Slider needles are selected using the gauge spacing pattern starting from this sheet’s offset.

Returns:

The set of front bed slider needles on the machine that belong to this sheet, ordered by position.

Return type:

list[Slider_Needle]

back_sliders()[source]

Get the set of back bed slider needles on the machine that belong to this sheet.

Returns all back bed slider needles that are part of this sheet according to the gauge configuration. Slider needles are selected using the gauge spacing pattern starting from this sheet’s offset.

Returns:

The set of back bed slider needles on the machine that belong to this sheet, ordered by position.

Return type:

list[Slider_Needle]

front_loops()[source]

Get the list of front bed needles that belong to this sheet and currently hold loops.

Filters the front bed needles of this sheet to return only those that currently have loops on them. This is useful for operations that need to work specifically with active needles.

Returns:

The list of front bed needles that belong to this sheet and currently hold loops, ordered by position.

Return type:

list[Needle]

back_loops()[source]

Get the list of back bed needles that belong to this sheet and currently hold loops.

Filters the back bed needles of this sheet to return only those that currently have loops on them. This is useful for operations that need to work specifically with active needles.

Returns:

The list of back bed needles that belong to this sheet and currently hold loops, ordered by position.

Return type:

list[Needle]

front_slider_loops()[source]

Get the list of front bed slider needles that belong to this sheet and currently hold loops.

Filters the front bed slider needles of this sheet to return only those that currently have loops on them. This is useful for operations that need to work specifically with active slider needles.

Returns:

The list of front bed slider needles that belong to this sheet and currently hold loops, ordered by position.

Return type:

list[Slider_Needle]

back_slider_loops()[source]

Get the list of back bed slider needles that belong to this sheet and currently hold loops.

Filters the back bed slider needles of this sheet to return only those that currently have loops on them. This is useful for operations that need to work specifically with active slider needles.

Returns:

The list of back bed slider needles that belong to this sheet and currently hold loops, ordered by position.

Return type:

list[Slider_Needle]

all_needles()[source]

Get list of all needles on the sheet with front bed needles given first.

Combines all needles (both front and back bed) that belong to this sheet into a single list. Front bed needles are listed first, followed by back bed needles.

Returns:

List of all needles on the sheet with front bed needles given first, followed by back bed needles, all ordered by position within their respective beds.

Return type:

list[Needle]

all_sliders()[source]

Get list of all slider needles on the sheet with front bed sliders given first.

Combines all slider needles (both front and back bed) that belong to this sheet into a single list. Front bed slider needles are listed first, followed by back bed slider needles.

Returns:

List of all slider needles on the sheet with front bed sliders given first, followed by back bed sliders, all ordered by position within their respective beds.

Return type:

list[Slider_Needle]

all_loops()[source]

Get list of all loop-holding needles on the sheet with front bed needles given first.

Combines all needles (both front and back bed) that belong to this sheet and currently hold loops into a single list. Front bed needles with loops are listed first, followed by back bed needles with loops.

Returns:

List of all loop-holding needles on the sheet with front bed needles given first, followed by back bed needles, all ordered by position within their respective beds.

Return type:

list[Needle]

all_slider_loops()[source]

Get list of all loop-holding slider needles on the sheet with front bed sliders given first.

Combines all slider needles (both front and back bed) that belong to this sheet and currently hold loops into a single list. Front bed slider needles with loops are listed first, followed by back bed slider needles with loops.

Returns:

List of all loop-holding slider needles on the sheet with front bed sliders given first, followed by back bed sliders,

all ordered by position within their respective beds.

Return type:

list[Slider_Needle]

class Sheet_Identifier(sheet, gauge)[source]

Bases: object

Used to convert needles given a defined sheet …

Parameters:
__init__(sheet, gauge)[source]
Parameters:
property sheet: int

The position of the sheet in the gauge

Type:

return

property gauge: int

The number of active sheets

Type:

return

get_needle(needle)[source]
Parameters:

needle (Needle) – Needle to access from sheet. Maybe a sheet needle which will be retargeted to this sheet

Return type:

Sheet_Needle

Returns:

the sheet needle at the given needle index and bed

needle(is_front, position)[source]

Gets a needle within the sheet with specified position :type is_front: bool :param is_front: True if needle is on front bed :type position: int :param position: position within the sheet :rtype: Sheet_Needle :return: the specified sheet needle