gscrib.formatters
G-code syntax and number formatting utilities.
This module provides utilities for formatting G-code output, including commands, parameters, comments, and numbers. It defines standard interfaces and implementations for consistent G-code generation.
- class gscrib.formatters.BaseFormatter
Bases:
ABCAbstract base class for G-code formatting.
Defines the interface that all G-code formatters must implement.
- abstractmethod command(command, params=None, comment=None)
Format a G-code command with optional parameters.
- abstractmethod comment(text)
Format text as a G-code comment.
- abstractmethod line(statement)
Format a single G-code statement for output.
- abstractmethod number(number)
Format a number with specified decimal places.
- abstractmethod parameters(params)
Format G-code statement parameters.
- Parameters:
params – Statement parameters
- Returns:
Formatted parameters string
- Return type:
- abstractmethod set_axis_label(axis, label)
Set a custom label for an axis.
- abstractmethod set_comment_symbols(value)
Set the comment symbols for G-code comments.
- Parameters:
value (str) – Comment symbols to use
- Return type:
None
- class gscrib.formatters.DefaultFormatter
Bases:
BaseFormatterFormats G-code output.
- command(command, params=None, comment=None)
Format a G-code command with optional parameters.
- comment(text)
Format text as a G-code comment.
- line(statement)
Format a single G-code statement for output.
- number(number)
Format a number with specified decimal places.
- Parameters:
number (Number) – The number to format
- Returns:
Formatted number string
- Raises:
ValueError – If value is not finite
TypeError – If value is a complex number
typeguard.TypeCheckError – If value is not a number
- Return type:
- parameters(params)
Format G-code statement parameters.
- set_axis_label(axis, label)
Set a custom label for an axis.
- Parameters:
- Raises:
ValueError – If axis is invalid or label is empty
- set_comment_symbols(value)
Set the comment symbols for G-code comments.
- Parameters:
value (str) – Comment symbols to use (non-empty string)
- Raises:
ValueError – If value is empty or not a string
- Return type:
None
- set_decimal_places(value)
Set the maximum number of decimal places for number formatting.
- Parameters:
value (int) – Number of decimal places (non-negative integer)
- Raises:
ValueError – If value is negative
- Return type:
None