diff --git a/panels/move.py b/panels/move.py index c3b53b9e..d6fa890f 100644 --- a/panels/move.py +++ b/panels/move.py @@ -54,7 +54,7 @@ class Panel(ScreenPanel): adjust = self._gtk.Button( "settings", None, "color2", 1, Gtk.PositionType.LEFT, 1 ) - adjust.connect("clicked", self.load_menu, "options", _("Settings")) + adjust.connect("clicked", self.menu_item_clicked, {"panel": "move_setting"}) adjust.set_hexpand(False) grid = Gtk.Grid(row_homogeneous=True, column_homogeneous=True) if self._screen.vertical_mode: @@ -118,58 +118,10 @@ class Panel(ScreenPanel): self.content.add(self.labels["move_menu"]) - printer_cfg = self._printer.get_config_section("printer") - # The max_velocity parameter is not optional in klipper config. - # The minimum is 1, but least 2 values are needed to create a scale - max_velocity = max(int(float(printer_cfg["max_velocity"])), 2) - if "max_z_velocity" in printer_cfg: - self.max_z_velocity = max(int(float(printer_cfg["max_z_velocity"])), 2) - else: - self.max_z_velocity = max_velocity - - configurable_options = [ - { - "move_speed_xy": { - "section": "main", - "name": _("XY Speed (mm/s)"), - "type": "scale", - "tooltip": _("Only for the move panel"), - "value": "50", - "range": [1, max_velocity], - "step": 1, - } - }, - { - "move_speed_z": { - "section": "main", - "name": _("Z Speed (mm/s)"), - "type": "scale", - "tooltip": _("Only for the move panel"), - "value": "10", - "range": [1, self.max_z_velocity], - "step": 1, - } - }, - ] - - self.labels["options_menu"] = self._gtk.ScrolledWindow() - self.labels["options"] = Gtk.Grid() - self.labels["options_menu"].add(self.labels["options"]) - self.options = {} - for option in configurable_options: - name = list(option)[0] - self.options.update( - self.add_option("options", self.settings, name, option[name]) - ) - - def process_update(self, action, data): if action != "notify_status_update": return - if "toolhead" in data and "max_velocity" in data["toolhead"]: - max_vel = max(int(float(data["toolhead"]["max_velocity"])), 2) - adj = self.options["move_speed_xy"].get_adjustment() - adj.set_upper(max_vel) + if ( "gcode_move" in data or "toolhead" in data diff --git a/panels/move_setting.py b/panels/move_setting.py new file mode 100644 index 00000000..ee330451 --- /dev/null +++ b/panels/move_setting.py @@ -0,0 +1,64 @@ +import gi + +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk +from ks_includes.screen_panel import ScreenPanel + + +class Panel(ScreenPanel): + def __init__(self, screen, title): + title = title or _("Move setting") + super().__init__(screen, title) + printer_cfg = self._printer.get_config_section("printer") + max_velocity = max(int(float(printer_cfg["max_velocity"])), 2) + if "max_z_velocity" in printer_cfg: + self.max_z_velocity = max(int(float(printer_cfg["max_z_velocity"])), 2) + else: + self.max_z_velocity = max_velocity + + self.settings = {} + configurable_options = [ + { + "move_speed_xy": { + "section": "main", + "name": _("XY Speed (mm/s)"), + "type": "scale", + "tooltip": _("Only for the move panel"), + "value": "50", + "range": [1, max_velocity], + "step": 1, + } + }, + { + "move_speed_z": { + "section": "main", + "name": _("Z Speed (mm/s)"), + "type": "scale", + "tooltip": _("Only for the move panel"), + "value": "10", + "range": [1, self.max_z_velocity], + "step": 1, + } + }, + ] + + self.labels["options_menu"] = self._gtk.ScrolledWindow() + self.labels["options"] = Gtk.Grid() + self.labels["options_menu"].add(self.labels["options"]) + self.options = {} + for option in configurable_options: + name = list(option)[0] + self.options.update(self.add_option("options", self.settings, name, option[name])) + + self.content.add(self.labels["options_menu"]) + self.content.show_all() + + +def process_update(self, action, data): + if action != "notify_status_update": + return + + if "toolhead" in data and "max_velocity" in data["toolhead"]: + max_vel = max(int(float(data["toolhead"]["max_velocity"])), 2) + adj = self.options["move_speed_xy"].get_adjustment() + adj.set_upper(max_vel)