Skip to content

Commit

Permalink
显示gcodemacro的原始模板,当前变量和渲染后的结果
Browse files Browse the repository at this point in the history
  • Loading branch information
GuoGeTiertime committed Nov 7, 2024
1 parent 2c6a71e commit b988c58
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion klippy/extras/gcode_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, printer, env, name, script):
self.gcode = self.printer.lookup_object('gcode')
gcode_macro = self.printer.lookup_object('gcode_macro')
self.create_template_context = gcode_macro.create_template_context
self.source = script
try:
self.template = env.from_string(script)
except Exception as e:
Expand Down Expand Up @@ -183,9 +184,16 @@ def cmd_SET_GCODE_VARIABLE(self, gcmd):
cmd_SHOW_MACRO_help = "Show the source code of a G-Code macro"
def cmd_SHOW_MACRO(self, gcmd):
# show the source code of the macro
self.gcode.respond_info(self.template.template.source)
self.gcode.respond_info(self.template.source)
v = dict(self.variables)
self.gcode.respond_info("Variables: %s" % (v,))
kwparams = dict(self.variables)
kwparams.update(self.template.create_template_context())
kwparams['params'] = gcmd.get_command_parameters()
kwparams['rawparams'] = gcmd.get_raw_command_parameters()
renderstring = self.template.render(kwparams)
self.gcode.respond_info("after render: %s" %(renderstring,))

def cmd(self, gcmd):
if self.in_script:
raise gcmd.error("Macro %s called recursively" % (self.alias,))
Expand Down

0 comments on commit b988c58

Please sign in to comment.