From 92646555e3a9024349de81d01323902427553588 Mon Sep 17 00:00:00 2001 From: zkk <1007518571@qq.com> Date: Thu, 19 Sep 2024 17:29:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=A7=BB=E8=BD=B4=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2,=E5=AE=9E=E7=8E=B0Z=E8=BD=B4=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=E8=B4=9F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- panels/move.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/panels/move.py b/panels/move.py index 70b000cb..ffc9c79b 100644 --- a/panels/move.py +++ b/panels/move.py @@ -129,9 +129,9 @@ class Panel(ScreenPanel): # 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: - max_z_velocity = max(int(float(printer_cfg["max_z_velocity"])), 2) + self.max_z_velocity = max(int(float(printer_cfg["max_z_velocity"])), 2) else: - max_z_velocity = max_velocity + self.max_z_velocity = max_velocity configurable_options = [ { @@ -184,7 +184,7 @@ class Panel(ScreenPanel): "type": "scale", "tooltip": _("Only for the move panel"), "value": "10", - "range": [1, max_z_velocity], + "range": [1, self.max_z_velocity], "step": 1, } }, @@ -249,14 +249,22 @@ class Panel(ScreenPanel): direction = "-" if direction == "+" else "+" dist = f"{direction}{self.distance}" - config_key = "move_speed_z" if axis == "Z" else "move_speed_xy" + config_key = "move_speed_z" if axis == "z" else "move_speed_xy" + if axis == "z": + pos_z_text = self.labels["pos_z"].get_text() + pos_z_match = re.search(r"Z:\s*([-+]?\d*\.\d+|\d+)", pos_z_text) + if pos_z_match: + z_value = float(pos_z_match.group(1)) + if direction == "-" and z_value < float(self.distance): + self._screen.show_popup_message(_("Z axis cannot move to negative values")) + return speed = ( None if self.ks_printer_cfg is None else self.ks_printer_cfg.getint(config_key, None) ) if speed is None: - speed = self._config.get_config()["main"].getint(config_key, 20) + speed = self._config.get_config()["main"].getint(config_key, self.max_z_velocity) speed = 60 * max(1, speed) script = f"{KlippyGcodes.MOVE_RELATIVE}\nG0 {axis}{dist} F{speed}" self._screen._send_action(widget, "printer.gcode.script", {"script": script})