From e16d56345d398f7283cd210f216991b0420cfc40 Mon Sep 17 00:00:00 2001 From: sokolovjek Date: Thu, 28 Dec 2023 13:44:06 +0000 Subject: [PATCH] STEAPP-841: added dynamic loading of button templates and slider options --- klippy/extras/wizard/wizard_step_button.py | 11 ++++--- klippy/extras/wizard/wizard_step_slider.py | 36 ++++++++++++++-------- stereotech_config/wizards/wizards.cfg | 18 +++++------ 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/klippy/extras/wizard/wizard_step_button.py b/klippy/extras/wizard/wizard_step_button.py index 7bf925983e4e..6c76416fe19c 100644 --- a/klippy/extras/wizard/wizard_step_button.py +++ b/klippy/extras/wizard/wizard_step_button.py @@ -6,11 +6,12 @@ def __init__(self, config): WizardStep.__init__(self, config) # create template for buttons self.templates = {} - buttons = config.get_prefix_options('button') - for button in buttons: + options_name = config.get_prefix_options('button_') + for option in options_name: template_button = self.gcode_macro.load_template( - config, button) - self.templates.update({button: template_button}) + config, option) + button_name = '_'.join(option.split('_')[1:-1]) + self.templates.update({button_name: template_button}) # register commands self.gcode.register_mux_command("WIZARD_STEP_BUTTON", 'STEP', self.name, self.cmd_WIZARD_STEP_BUTTON, @@ -24,7 +25,7 @@ def cmd_WIZARD_STEP_BUTTON(self, gcmd): "2054: Macro %s called recursively" % (self.name,)) wizard_name = gcmd.get('WIZARD').upper() wizard_obj = self.printer.lookup_object('wizard %s' % wizard_name) - button = gcmd.get('BUTTON') + button = gcmd.get('BUTTON', '').lower() template_button = self.templates.get(button, None) if template_button is None: raise gcmd.error( diff --git a/klippy/extras/wizard/wizard_step_slider.py b/klippy/extras/wizard/wizard_step_slider.py index 8deb82fd3507..d21e365246c1 100644 --- a/klippy/extras/wizard/wizard_step_slider.py +++ b/klippy/extras/wizard/wizard_step_slider.py @@ -1,31 +1,43 @@ from wizard_step import WizardStep +OPTIONS = { + 'min': 0, + 'max': 100, + 'step': 1, + 'default': 20, +} + class WizardStepSlider(WizardStep): def __init__(self, config): WizardStep.__init__(self, config) - # get options from config + # get slider options from config self.slider_data = {} - options = config.get_prefix_options('slider') - for option in options: - self.slider_data.update({option: config.getint(option)}) - # register gcode commands - self.gcode.register_mux_command("WIZARD_STEP_SLIDER", 'SLIDER', + options = config.get_prefix_options('slider_') + sliders = {'_'.join(option.split('_')[1:-1]) for option in options} + for slider in sliders: + self.slider_data.update({slider: {}}) + for key, value in OPTIONS.items(): + option_name = 'slider_%s_%s' % (slider, key) + config_value = config.getfloat(option_name, value) + self.slider_data[slider].update({option_name: config_value}) + if 'default' in option_name: + self.slider_data[slider].update({'current_value': config_value}) + self.gcode.register_mux_command("WIZARD_STEP_SLIDER", 'STEP', self.name, self.cmd_WIZARD_STEP_SLIDER, desc=self.cmd_WIZARD_STEP_SLIDER_help) cmd_WIZARD_STEP_SLIDER_help = "update value to the slider data" def cmd_WIZARD_STEP_SLIDER(self, gcmd): - variable = gcmd.get('VARIABLE').lower() + slider = gcmd.get('SLIDER') value = gcmd.get_float('VALUE') - if variable not in self.slider_data: - raise gcmd.error("2055: Failure set value:%s to variable:%s in the slider %s" % ( - value, variable, self.name)) - self.slider_data.update({variable: value}) + if slider not in self.slider_data: + raise gcmd.error("2055: Failure set value:%s to slider:%s" % (value, slider)) + self.slider_data[slider].update({'current_value': value}) def get_status(self, eventtime): - return self.slider_data + return {slider: value['current_value'] for slider, value in self.slider_data.items()} def load_config_prefix(config): diff --git a/stereotech_config/wizards/wizards.cfg b/stereotech_config/wizards/wizards.cfg index 5e6b983c6e7f..50f03b071f3f 100644 --- a/stereotech_config/wizards/wizards.cfg +++ b/stereotech_config/wizards/wizards.cfg @@ -12,7 +12,7 @@ # CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_BUTTON_1 # EXECUTE_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_BUTTON_1 # WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=button_button_1_gcode -# WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=button_button_2_gcode +# WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=button_button2_gcode # wizard_step_wizards # CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_WIZARDS_1 @@ -26,8 +26,8 @@ # wizard_step_slider # CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_SLIDER_1 # EXECUTE_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_SLIDER_1 -# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=STEP_SLIDER_1 VARIABLE=slider_slider1_min VALUE=12 -# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=STEP_SLIDER_1 VARIABLE=slider_slider2_min VALUE=40 +# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=slider1 VALUE=12 +# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=slider_2 VALUE=40 # wizard_step_jog # CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_JOG_1 @@ -65,8 +65,8 @@ countdown: 20 info: info about STEP_BUTTON_1 button_button_1_gcode: {action_respond_info('-------------------button_button_1_gcode')} -button_button_2_gcode: - {action_respond_info('-------------------button_button_2_gcode')} +button_button2_gcode: + {action_respond_info('-------------------button_button2_gcode')} action_gcode: {action_respond_info('-------------------action_gcode STEP_BUTTON_1')} SET_WIZARD_STEP WIZARD={wizard.name} STEP={wizard.wizard_step_name} @@ -118,10 +118,10 @@ slider_slider1_min: 0 slider_slider1_max: 100 slider_slider1_step: 1 slider_slider1_default: 20 -slider_slider2_min: 4 -slider_slider2_max: 30 -slider_slider2_step: 23 -slider_slider2_default: 20 +slider_slider_2_min: 4 +slider_slider_2_max: 30 +slider_slider_2_step: 23 +slider_slider_2_default: 20 action_gcode: {action_respond_info('-------------------action_gcode STEP_SELECTOR_1')} SET_WIZARD_STEP WIZARD={wizard.name} STEP={wizard.wizard_step_name}