macros: fix list not loading when there are extra spaces fixes #909

This commit is contained in:
alfrix 2023-03-10 19:57:44 -06:00
parent be473bf626
commit dfe1ac8d2c
2 changed files with 14 additions and 2 deletions

View File

@ -153,7 +153,14 @@ class Printer:
return [] return []
def get_config_section(self, section): def get_config_section(self, section):
return self.config[section] if section in self.config else False return next(
(
self.config[key]
for key in self.config.keys()
if key.find(section) > -1
),
False,
)
def get_fans(self): def get_fans(self):
fans = [] fans = []

View File

@ -83,7 +83,12 @@ class MacroPanel(ScreenPanel):
"params": {}, "params": {},
} }
pattern = r'params\.(?P<param>..*)\|default\((?P<default>..*)\).*' pattern = r'params\.(?P<param>..*)\|default\((?P<default>..*)\).*'
gcode = self._printer.get_config_section(f"gcode_macro {macro}")["gcode"].split("\n") gcode = self._printer.get_config_section(macro)
if gcode and "gcode" in gcode:
gcode = gcode["gcode"].split("\n")
else:
logging.debug(f"Couldn't load {macro}\n{gcode}")
return
i = 0 i = 0
for line in gcode: for line in gcode:
if line.startswith("{") and "params." in line: if line.startswith("{") and "params." in line: