diff --git a/config/main_menu.conf b/config/main_menu.conf index ec599d39..ad9a637d 100644 --- a/config/main_menu.conf +++ b/config/main_menu.conf @@ -106,6 +106,11 @@ name: {{ gettext('More') }} icon: more-settings panel: settings +[menu __main more advanced] +name: {{ gettext('Advanced') }} +icon: advanced_setting +panel: advanced + [menu __main more network] name: {{ gettext('Network') }} icon: network diff --git a/ks_includes/KlippyGcodes.py b/ks_includes/KlippyGcodes.py index b66bcc06..98f22cc7 100644 --- a/ks_includes/KlippyGcodes.py +++ b/ks_includes/KlippyGcodes.py @@ -47,3 +47,9 @@ class KlippyGcodes: f'RED={color[0]} GREEN={color[1]} BLUE={color[2]} WHITE={color[3]} ' f'SYNC=0 TRANSMIT=1' ) + + @staticmethod + def set_save_variables(name, value): + if isinstance(value, str): + value = f"'{value}'" + return f'SAVE_VARIABLE VARIABLE={name} VALUE=\"{value}\"' diff --git a/panels/advanced.py b/panels/advanced.py new file mode 100644 index 00000000..ea1ec5a0 --- /dev/null +++ b/panels/advanced.py @@ -0,0 +1,43 @@ +import logging +import gi + +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk +from ks_includes.KlippyGcodes import KlippyGcodes +from ks_includes.screen_panel import ScreenPanel + +class Panel(ScreenPanel): + def __init__(self, screen, title): + title = title or _("Advanced") + super().__init__(screen, title) + self.advanced = {} + self.menu_list ={} + self.advanced_options = [ + {"adaptive_leveling": {"section": "main", "name": _("Adaptive Bed Leveling"), "type": "binary", + "tooltip": _("Leveling Only in the Actual Print Area"), + "value": "True", "callback": self.set_adaptive_leveling}}, + ] + options = self.advanced_options + self.labels['advanced_menu'] = self._gtk.ScrolledWindow() + self.labels['advanced'] = Gtk.Grid() + self.labels['advanced_menu'].add(self.labels['advanced']) + for option in options: + name = list(option)[0] + res = self.add_option('advanced', self.advanced, name, option[name]) + self.menu_list.update(res) + self.content.add(self.labels['advanced_menu']) + + def set_adaptive_leveling(self, *args): + enable_adaptive_leveling = any(args) + script_value = True if enable_adaptive_leveling else False + script = KlippyGcodes.set_save_variables("adaptive_meshing", script_value) + self._screen._send_action(None, "printer.gcode.script", {"script": script}) + logging.info(f"Set adaptive leveling: {script_value}") + + def process_update(self, action, data): + if action != "notify_status_update": + return + if 'save_variables' in data and 'variables' in data['save_variables']: + variables = data['save_variables']['variables'] + if 'adaptive_meshing' in variables: + self.menu_list['adaptive_leveling'].set_active(variables['adaptive_meshing']) diff --git a/screen.py b/screen.py index 2f92113a..7e1ce1a4 100755 --- a/screen.py +++ b/screen.py @@ -273,6 +273,7 @@ class KlipperScreen(Gtk.Window): "exclude_object": ["current_object", "objects", "excluded_objects"], "manual_probe": ['is_active'], "screws_tilt_adjust": ['results', 'error'], + "save_variables": ['variables'], } } for extruder in self.printer.get_tools(): @@ -1072,6 +1073,7 @@ class KlipperScreen(Gtk.Window): 'firmware_retraction', 'exclude_object', 'manual_probe', + 'save_variables', *self.printer.get_tools(), *self.printer.get_heaters(), *self.printer.get_temp_sensors(), diff --git a/styles/dark/images/advanced_setting.svg b/styles/dark/images/advanced_setting.svg new file mode 100644 index 00000000..9eba0be0 --- /dev/null +++ b/styles/dark/images/advanced_setting.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/styles/light/images/advanced_setting.svg b/styles/light/images/advanced_setting.svg new file mode 100644 index 00000000..534e46d4 --- /dev/null +++ b/styles/light/images/advanced_setting.svg @@ -0,0 +1,9 @@ + + + + + + + + +