From 01b3a6a8e4f015ef02bb0cb79c1ef425cea88613 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 18 Sep 2025 12:31:30 -0400 Subject: [PATCH] gcode: Replace Coord named tuple with custom tuple class Replace the existing Coord() class with one that supports more than 4 coordinates. Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/klippy/gcode.py b/klippy/gcode.py index 93ef38a1e..ca815b4d7 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -1,15 +1,26 @@ # Parse gcode commands # -# Copyright (C) 2016-2024 Kevin O'Connor +# Copyright (C) 2016-2025 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. -import os, re, logging, collections, shlex +import os, re, logging, collections, shlex, operator class CommandError(Exception): pass -Coord = collections.namedtuple('Coord', ('x', 'y', 'z', 'e')) +# Custom "tuple" class for coordinates - add easy access to x, y, z components +class Coord(tuple): + __slots__ = () + def __new__(cls, x, y, z, e, *args): + return tuple.__new__(cls, (x, y, z, e) + args) + def __getnewargs__(self): + return tuple(self) + x = property(operator.itemgetter(0)) + y = property(operator.itemgetter(1)) + z = property(operator.itemgetter(2)) + e = property(operator.itemgetter(3)) +# Class for handling gcode command parameters (gcmd) class GCodeCommand: error = CommandError def __init__(self, gcode, command, commandline, params, need_ack):