From 9ba8d0486118556b4900b6be6b20a6e721bd23eb Mon Sep 17 00:00:00 2001 From: alfrix Date: Sun, 6 Aug 2023 18:20:32 -0300 Subject: [PATCH] printer: save and use available commands --- ks_includes/KlippyRest.py | 3 +++ ks_includes/printer.py | 2 ++ panels/job_status.py | 11 ++--------- panels/zcalibrate.py | 10 +++++----- screen.py | 1 + 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ks_includes/KlippyRest.py b/ks_includes/KlippyRest.py index 54a244cb..822a9886 100644 --- a/ks_includes/KlippyRest.py +++ b/ks_includes/KlippyRest.py @@ -29,6 +29,9 @@ class KlippyRest: def get_printer_info(self): return self.send_request("printer/info") + def get_gcode_help(self): + return self.send_request("printer/gcode/help") + def get_thumbnail_stream(self, thumbnail): return self.send_request(f"server/files/gcodes/{thumbnail}", json=False) diff --git a/ks_includes/printer.py b/ks_includes/printer.py index ae42019b..4f171e01 100644 --- a/ks_includes/printer.py +++ b/ks_includes/printer.py @@ -25,6 +25,7 @@ class Printer: self.busy = False self.tempstore_size = 1200 self.cameras = [] + self.available_commands = {} def reinit(self, printer_info, data): self.config = data['configfile']['config'] @@ -40,6 +41,7 @@ class Printer: if not self.store_timeout: self.store_timeout = GLib.timeout_add_seconds(1, self._update_temp_store) self.tempstore_size = 1200 + self.available_commands = {} for x in self.config.keys(): if x[:8] == "extruder": diff --git a/panels/job_status.py b/panels/job_status.py index 5cd1fe90..16fd88fa 100644 --- a/panels/job_status.py +++ b/panels/job_status.py @@ -740,18 +740,11 @@ class Panel(ScreenPanel): offset = self._printer.get_stat("gcode_move", "homing_origin") self.zoffset = float(offset[2]) if offset else 0 if self.zoffset != 0: - endstop = ( - ( - self._printer.config_section_exists("stepper_z") - and not self._printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe") - ) - or "delta" in self._printer.get_config_section("printer")['kinematics'] - ) - if endstop: + if "Z_OFFSET_APPLY_ENDSTOP" in self._printer.available_commands: self.buttons['button_grid'].attach(self.buttons["save_offset_endstop"], 0, 0, 1, 1) else: self.buttons['button_grid'].attach(Gtk.Label(), 0, 0, 1, 1) - if self._printer.get_probe(): + if "Z_OFFSET_APPLY_PROBE" in self._printer.available_commands: self.buttons['button_grid'].attach(self.buttons["save_offset_probe"], 1, 0, 1, 1) else: self.buttons['button_grid'].attach(Gtk.Label(), 1, 0, 1, 1) diff --git a/panels/zcalibrate.py b/panels/zcalibrate.py index 9adca227..a4086b11 100644 --- a/panels/zcalibrate.py +++ b/panels/zcalibrate.py @@ -44,18 +44,18 @@ class Panel(ScreenPanel): functions = [] pobox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - if self._printer.config_section_exists("stepper_z") \ - and not self._printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"): + + if "Z_ENDSTOP_CALIBRATE" in self._printer.available_commands: self._add_button("Endstop", "endstop", pobox) functions.append("endstop") - if self.probe: + if "PROBE_CALIBRATE" in self._printer.available_commands: self._add_button("Probe", "probe", pobox) functions.append("probe") - if self._printer.config_section_exists("bed_mesh") and "probe" not in functions: + if "BED_MESH_CALIBRATE" in self._printer.available_commands and "probe" not in functions: # This is used to do a manual bed mesh if there is no probe self._add_button("Bed mesh", "mesh", pobox) functions.append("mesh") - if "delta" in self._printer.get_config_section("printer")['kinematics']: + if "DELTA_CALIBRATE" in self._printer.available_commands: if "probe" in functions: self._add_button("Delta Automatic", "delta", pobox) functions.append("delta") diff --git a/screen.py b/screen.py index 7a020514..4f992f19 100755 --- a/screen.py +++ b/screen.py @@ -869,6 +869,7 @@ class KlipperScreen(Gtk.Window): return self._init_printer("Error getting printer configuration") # Reinitialize printer, in case the printer was shut down and anything has changed. self.printer.reinit(printer_info['result'], config['result']['status']) + self.printer.available_commands = self.apiclient.get_gcode_help()['result'] self.ws_subscribe() extra_items = (self.printer.get_tools()