virtual_knitting_machine.machine_components.Needle_Bed_Snapshot module
A module containing the Needle_Bed_Snapshot class.
- class Needle_Bed_Snapshot(needle_bed, machine_snapshot)[source]
Bases:
Needle_Bed_State[Machine_LoopT]A snapshot of the state of a knitting machine at the time an instance is created.
- property knitting_machine: Knitting_Machine_Snapshot[Machine_LoopT]
Returns: Knitting_Machine_Snapshot: The knitting machine this bed belongs to.
- property is_front: bool
Returns: bool: True if this snapshot is the front bed of the knitting machine, False otherwise.
- property needles: list[Needle[Machine_LoopT]]
Returns: list[Needle]: The active needles ordered by their position on the knitting machine
- property sliders: list[Slider_Needle[Machine_LoopT]]
Returns: list[Slider_Needle]: The active slider needles ordered by their position on the knitting machine”
- property loop_holding_needles: list[Needle[Machine_LoopT]]
Returns: list[Needle]: List of needles on bed that actively hold loops.
- property loop_holding_sliders: list[Slider_Needle[Machine_LoopT]]
Returns: list[Slider_Needle]: List of sliders on bed that actively hold loops.
- get_needle_of_loop(loop)[source]
- Parameters:
loop (Machine_Knit_Loop) – The loop being searched for.
- Returns:
None if the bed does not hold the loop, otherwise the needle position that holds it.
- Return type:
Needle | None
- slider_is_active(slider)[source]
- Parameters:
slider (int | Needle_Specification) – The slider or index of a slider on this needle bed.
- Returns:
True if the given slider is on this bed and holds at least one loop, False otherwise.
- Return type:
- needle_is_active(needle)[source]
- Parameters:
needle (int | Needle_Specification) – THe needle or index of a needl on this needle bed.
- Returns:
True if the given needle is on this bed and holds at least one loop, False otherwise.
- Return type:
- __contains__(item)[source]
- Parameters:
item (Machine_Knit_Loop | Needle | int) – The active loop or needle to find in this snapshot. If item is an integer, the position is assumed to be a needle index, not a slider index or loop_id.
- Returns:
True if the given needle, needle position, or loop was active at the time of the snapshot, False otherwise.
- Return type:
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- __iter__()
Iterate over the needles in this bed.
- Returns:
Iterator over the needles on this bed.
- Return type:
Iterator[Needle]
- property active_loops: set[Machine_LoopT]
Returns: set[Machine_Knit_Loop]: The set of loops held on needles on the needle bed.
- property active_slider_loops: set[Machine_LoopT]
Returns: set[Machine_Knit_Loop]: The set of loops held on slider needles on the needle bed.
- handle_violations(response_policy=None, handler=None)
Context manager that catches exceptions and routes them through the violation policy.
- Parameters:
response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.
handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.
- loop_is_active(loop)
- Parameters:
loop (Machine_Knit_Loop) – The loop to check if it is held by this bed.
- Returns:
True if the given loop is on held on a needle or slider needle, False otherwise.
- Return type:
- loop_on_needle(loop)
- Parameters:
loop (Machine_Knit_Loop) – The loop to check if it is actively held by a needle
- Returns:
True if the loop is held by a needle. False, otherwise.
- Return type:
- loop_on_slider(loop)
- Parameters:
loop (Machine_Knit_Loop) – The loop to check if it is actively on a slider needle
- Returns:
True if the loop is on held on a slider needle. False, otherwise.
- Return type:
- set_response_for(violation, response=None)
Sets the response for the given violation to the given response.
- Parameters:
violation (Violation) – The violation to set the response for.
response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.
- property sliders_are_clear: bool
Check if no loops are on any slider needle.
- Returns:
True if no loops are on a slider needle, False otherwise.
- Return type:
- property violation_policy: Knitting_Machine_Error_Policy
Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.
- __getitem__(item: Machine_Knit_Loop) Needle[Machine_LoopT] | None[source]
- __getitem__(item: Needle_Specification | int) Needle[Machine_LoopT]
- __getitem__(item: slice) list[Needle[Machine_LoopT]]
- Parameters:
item (Machine_Knit_Loop | Needle_Specification | slice | int) – The active needle or loop to find in this snapshot. If item is an integer, the position is assumed to be a needle index, not a slider index or loop id.
- Returns:
The list of loops on the given needle at the time of the snapshot or the needle that held the given loop.
- Return type:
- Raises:
KeyError – If the given item is not an active needle, slider needle, or loop at the time of the snapshot.