knit_script.knit_script_interpreter.scope.machine_scope module
Scope of machine variables.
This module provides the Machine_Scope class, which manages machine state and configuration within different execution scopes of a knit script program. It tracks machine settings like carriage direction, active carriers, racking position, gauge configuration, and active sheets while automatically generating appropriate knitout instructions when these settings change. The machine scope integrates with the broader scoping system to provide proper inheritance and isolation of machine state across different program contexts.
- class Machine_Scope(context, prior_settings=None)[source]
Bases:
object
Keeps track of the machine state within different scopes.
The Machine_Scope class manages knitting machine configuration and state within a specific execution scope. It tracks essential machine parameters including carriage direction, active yarn carriers, racking position, gauge settings, and active sheet configuration. When these parameters are modified, the class automatically generates the appropriate knitout instructions to implement the changes on the physical machine.
This class provides scope-aware machine state management, allowing different parts of a knit script program to have different machine configurations while maintaining proper inheritance and isolation. It integrates with the gauged sheet system to handle complex multi-sheet knitting operations and ensures that machine state changes are properly reflected in the generated knitout code.
- _context
The execution context for this machine scope.
- Type:
_Context_Base
- _direction
Current carriage movement direction.
- Type:
Carriage_Pass_Direction
- _working_carrier
Currently active yarn carrier set.
- Type:
Yarn_Carrier_Set | None
- _sheet
Currently active sheet identifier.
- Type:
- _gauged_sheet_record
Record tracking sheet organization and loop positions.
- Type:
- Parameters:
context (<module ‘knit_script.knit_script_interpreter._Context_Base’ from ‘/home/runner/work/knit_script/knit_script/src/knit_script/knit_script_interpreter/_Context_Base.py’>)
prior_settings (
Machine_Scope
|None
)
- __init__(context, prior_settings=None)[source]
Initialize the machine scope with default settings or inherited from prior scope.
Creates a new machine scope with default machine settings, then optionally inherits settings from a parent scope. This allows child scopes to start with the same machine configuration as their parent while maintaining the ability to make local changes.
- Parameters:
context (_Context_Base) – The execution context that this machine scope operates within.
prior_settings (Machine_Scope | None, optional) – A parent machine scope to inherit settings from. If provided, all machine settings will be copied from this scope. Defaults to None.
- inherit_from_scope(scope, inherit_raw_values=False)[source]
Set the machine scope values based on the given scope.
Copies all machine configuration settings from the specified scope to this scope, including direction, carrier, racking, gauge, sheet, and gauged sheet record. This method is used to establish initial settings when creating child scopes.
- Parameters:
inherit_raw_values (bool) – If true, don’t use the property setters which may modify the knitout.
scope (Machine_Scope) – The machine scope to inherit the values from.
- Return type:
- update_parent_machine_scope(parent_scope)[source]
Passes machine status values up to the given parent scope. :type parent_scope:
Machine_Scope
:param parent_scope: The parent machine scope to pass values up to. :type parent_scope: Machine_Scope- Return type:
- property machine_state: Knitting_Machine
Get the current machine state in the current context.
- Returns:
The current machine state in the current context.
- Return type:
Knitting_Machine
- property direction: Carriage_Pass_Direction
Get the current direction the carriage will take.
- Returns:
The current direction the carriage will take.
- Return type:
Carriage_Pass_Direction
- property Carrier: Yarn_Carrier_Set | None
Get the current carrier being used by the machine.
- Returns:
The current carrier being used by the machine, or None if no carrier is active.
- Return type:
Yarn_Carrier_Set | None
- property Rack: float
Get current racking of the machine.
- Returns:
Current racking of the machine as a floating-point value.
- Return type:
- property Racking: float
Get current racking of the machine.
- Returns:
Current racking of the machine as a floating-point value.
- Return type:
- property gauged_sheet_record: Gauged_Sheet_Record
Get the gauged sheet record associated with this machine scope.
- Returns:
The gauged sheet record associated with this machine scope, which tracks loop positions and sheet organization.
- Return type:
- property Gauge: int
Get the current number of sheets on the machine.
- Returns:
The current number of sheets on the machine.
- Return type:
- property Sheet: Sheet_Identifier
Get the current sheet being worked on the machine.
- Returns:
The current sheet being worked on the machine.
- Return type: