gcode_macro: Add a default parameter to load_template

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-06-07 10:51:30 -04:00
parent 9613cd2c8a
commit 27ca159285
3 changed files with 7 additions and 6 deletions

View File

@ -68,9 +68,12 @@ class PrinterGCodeMacro:
def __init__(self, config):
self.printer = config.get_printer()
self.env = jinja2.Environment('{%', '%}', '{', '}')
def load_template(self, config, option):
def load_template(self, config, option, default=None):
name = "%s:%s" % (config.get_name(), option)
script = config.get(option, '')
if default is None:
script = config.get(option)
else:
script = config.get(option, default)
return TemplateWrapper(self.printer, self.env, name, script)
def load_config(config):
@ -86,7 +89,6 @@ class GCodeMacro:
name = config.get_name().split()[1]
self.alias = name.upper()
printer = config.get_printer()
config.get('gcode')
gcode_macro = printer.try_load_module(config, 'gcode_macro')
self.template = gcode_macro.load_template(config, 'gcode')
self.gcode = printer.lookup_object('gcode')

View File

@ -10,7 +10,6 @@ class HomingOverride:
self.start_pos = [config.getfloat('set_position_' + a, None)
for a in 'xyz']
self.axes = config.get('axes', 'XYZ').upper()
config.get('gcode')
gcode_macro = self.printer.try_load_module(config, 'gcode_macro')
self.template = gcode_macro.load_template(config, 'gcode')
self.in_script = False

View File

@ -198,9 +198,9 @@ class ProbeEndstopWrapper:
self.position_endstop = config.getfloat('z_offset')
gcode_macro = self.printer.try_load_module(config, 'gcode_macro')
self.activate_gcode = gcode_macro.load_template(
config, 'activate_gcode')
config, 'activate_gcode', '')
self.deactivate_gcode = gcode_macro.load_template(
config, 'deactivate_gcode')
config, 'deactivate_gcode', '')
# Create an "endstop" object to handle the probe pin
ppins = self.printer.lookup_object('pins')
pin = config.get('pin')