layerview.gcode.commands module

G-code commands and command parsing logic.

class layerview.gcode.commands.ArcMove(x: float | None = None, y: float | None = None, i: float | None = None, j: float | None = None, e: float | None = None, f: float | None = None, line_number: int | None = None)[source]

Bases: Move

Generic Arc Move.

_abc_impl = <_abc_data object>
e: float | None
f: float | None
line_number: int
param_letters = ['x', 'y', 'i', 'j', 'e', 'f']
x: float | None
y: float | None
class layerview.gcode.commands.Command(line_number: int | None = None)[source]

Bases: ABC

Generic G-code command.

_abc_impl = <_abc_data object>
line_number: int
exception layerview.gcode.commands.CommandInvalidParamError[source]

Bases: CommandParseError

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception layerview.gcode.commands.CommandMissingParamError[source]

Bases: CommandParseError

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception layerview.gcode.commands.CommandParseError[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class layerview.gcode.commands.CommandParser(skip_unknown: bool | None = False)[source]

Bases: object

static _create_from_float_params(tokens: List[Tuple[str, str]], command_type: Type) Any[source]
static _create_g0(tokens: List[Tuple[str, str]]) G0[source]
static _create_g1(tokens: List[Tuple[str, str]]) G1[source]
static _create_g2(tokens: List[Tuple[str, str]]) G2[source]
static _create_g20(_: List[Tuple[str, str]]) G20[source]
static _create_g21(_: List[Tuple[str, str]]) G21[source]
static _create_g28(tokens: List[Tuple[str, str]]) G28[source]
static _create_g3(tokens: List[Tuple[str, str]]) G3[source]
static _create_g90(_: List[Tuple[str, str]]) G90[source]
static _create_g91(_: List[Tuple[str, str]]) G91[source]
static _create_g92(tokens: List[Tuple[str, str]]) G92[source]
static _create_m104(tokens: List[Tuple[str, str]]) M104[source]
static _create_m109(tokens: List[Tuple[str, str]]) M109[source]
static _create_m82(_: List[Tuple[str, str]]) M82[source]
static _create_m83(_: List[Tuple[str, str]]) M83[source]
_get_handler(command_token: Tuple[str, str]) Callable[source]

Get factory method for G-code command.

Parameters:

command_token (GcodeToken) – Command GcodeToken for which the factory method is to be returned.

Returns:

Factory method for specific G-code command.

Return type:

Callable

static _group_tokens_by_command(tokens: List[Tuple[str, str]]) List[List[Tuple[str, str]]][source]

Groups tokens by the command they correspond to.

Parameters:

tokens (List[GcodeToken]) – List of G-code tokens to group by the command they correspond to.

Returns:

groups – List of lists of G-code tokens.

Return type:

List[List[GcodeToken]]

parse(tokens: List[Tuple[str, str]]) List[Command][source]
Parameters:

tokens (List[GcodeToken]) – List of G-code tokens, representing G-code fields. Expecting [(param, value), (param, value)]. E.g. [(‘g’, ‘1’), (‘x’, ‘10.25’), (‘y’, ‘22’)].

Returns:

commands – Parsed commands. May be empty if no tokens are present.

Return type:

List[Command]

Raises:

CommandParseError – If tokens contain unknown commands and skip_unknown is False.

exception layerview.gcode.commands.CommandTokenError[source]

Bases: CommandParseError

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class layerview.gcode.commands.CommandWithParams(line_number: int | None = None)[source]

Bases: Command, ABC

Generic G-code command with params.

_abc_impl = <_abc_data object>
line_number: int
abstract property param_letters: List[str]
class layerview.gcode.commands.CommandWithoutParams(line_number: int | None = None)[source]

Bases: Command

Generic G-code command without params.

_abc_impl = <_abc_data object>
line_number: int
class layerview.gcode.commands.G0(x: float | None = None, y: float | None = None, z: float | None = None, e: float | None = None, f: float | None = None, h: float | None = None, r: float | None = None, s: float | None = None, line_number: int | None = None)[source]

Bases: LineMove

Rapid Move.

_abc_impl = <_abc_data object>
e: float | None
f: float | None
h
line_number: int
param_letters = ['x', 'y', 'z', 'e', 'f', 'h', 'r', 's']
r
s
x: float | None
y: float | None
z
class layerview.gcode.commands.G1(x: float | None = None, y: float | None = None, z: float | None = None, e: float | None = None, f: float | None = None, h: float | None = None, r: float | None = None, s: float | None = None, line_number: int | None = None)[source]

Bases: LineMove

Linear Move.

_abc_impl = <_abc_data object>
e: float | None
f: float | None
h
line_number: int
param_letters = ['x', 'y', 'z', 'e', 'f', 'h', 'r', 's']
r
s
x: float | None
y: float | None
z
class layerview.gcode.commands.G2(x: float | None = None, y: float | None = None, i: float | None = None, j: float | None = None, e: float | None = None, f: float | None = None, line_number: int | None = None)[source]

Bases: ArcMove

Clockwise Arc.

_abc_impl = <_abc_data object>
e: float | None
f: float | None
line_number: int
param_letters = ['x', 'y', 'i', 'j', 'e', 'f']
x: float | None
y: float | None
class layerview.gcode.commands.G20(line_number: int | None = None)[source]

Bases: CommandWithoutParams

Set units to inches.

_abc_impl = <_abc_data object>
line_number: int
class layerview.gcode.commands.G21(line_number: int | None = None)[source]

Bases: CommandWithoutParams

Set units to millis.

_abc_impl = <_abc_data object>
line_number: int
class layerview.gcode.commands.G28(x: bool, y: bool, z: bool, line_number: int | None = None)[source]

Bases: CommandWithParams

Move to origin (home).

_abc_impl = <_abc_data object>
line_number: int
param_letters = ['x', 'y', 'z']
class layerview.gcode.commands.G3(x: float | None = None, y: float | None = None, i: float | None = None, j: float | None = None, e: float | None = None, f: float | None = None, line_number: int | None = None)[source]

Bases: ArcMove

Counter-Clockwise Arc.

_abc_impl = <_abc_data object>
e: float | None
f: float | None
line_number: int
param_letters = ['x', 'y', 'i', 'j', 'e', 'f']
x: float | None
y: float | None
class layerview.gcode.commands.G90(line_number: int | None = None)[source]

Bases: CommandWithoutParams

Set absolute positioning.

_abc_impl = <_abc_data object>
line_number: int
class layerview.gcode.commands.G91(line_number: int | None = None)[source]

Bases: CommandWithoutParams

Set relative positioning.

_abc_impl = <_abc_data object>
line_number: int
class layerview.gcode.commands.G92(x: float | None = None, y: float | None = None, z: float | None = None, e: float | None = None, line_number: int | None = None)[source]

Bases: CommandWithParams

Set position.

_abc_impl = <_abc_data object>
line_number: int
param_letters = ['x', 'y', 'z', 'e']
class layerview.gcode.commands.LineMove(x: float | None = None, y: float | None = None, z: float | None = None, e: float | None = None, f: float | None = None, h: float | None = None, r: float | None = None, s: float | None = None, line_number: int | None = None)[source]

Bases: Move

Generic Line Move

_abc_impl = <_abc_data object>
e: float | None
f: float | None
h
line_number: int
param_letters = ['x', 'y', 'z', 'e', 'f', 'h', 'r', 's']
r
s
x: float | None
y: float | None
z
class layerview.gcode.commands.M104(s: float, r: float | None = None, d: float | None = None, line_number: int | None = None)[source]

Bases: SetTemperatureExtruder

Set Extruder Temperature

_abc_impl = <_abc_data object>
line_number: int
param_letters = ['s', 'r', 'd']
class layerview.gcode.commands.M109(s: float, r: float | None = None, t: int | None = None, line_number: int | None = None)[source]

Bases: SetTemperatureExtruder

Set Extruder Temperature and Wait

_abc_impl = <_abc_data object>
line_number: int
param_letters = ['s', 'r', 't']
class layerview.gcode.commands.M82(line_number: int | None = None)[source]

Bases: CommandWithoutParams

Set extruder absolute mode.

_abc_impl = <_abc_data object>
line_number: int
class layerview.gcode.commands.M83(line_number: int | None = None)[source]

Bases: CommandWithoutParams

Set extruder relative mode.

_abc_impl = <_abc_data object>
line_number: int
class layerview.gcode.commands.Move(x: float | None = None, y: float | None = None, e: float | None = None, f: float | None = None, line_number: int | None = None)[source]

Bases: CommandWithParams, ABC

Move command base class.

_abc_impl = <_abc_data object>
e: float | None
f: float | None
line_number: int
abstract property param_letters: List[str]
x: float | None
y: float | None
class layerview.gcode.commands.SetTemperatureExtruder(s: float, r: float | None = None, line_number: int | None = None)[source]

Bases: CommandWithParams, ABC

Generic set temperature command.

_abc_impl = <_abc_data object>
line_number: int
abstract property param_letters: List[str]