From f8cde7bfe1d2634198665b3560bff9bf490ba5db Mon Sep 17 00:00:00 2001 From: alfrix Date: Fri, 25 Nov 2022 08:37:59 -0300 Subject: [PATCH] Add busy state, and disable buttons that usually take time during the state --- ks_includes/printer.py | 20 +++++- panels/bed_level.py | 151 ++++++++++++++++++++++------------------- panels/bed_mesh.py | 49 ++++++++----- panels/extrude.py | 55 +++++++++------ panels/move.py | 117 ++++++++++++++++--------------- panels/zcalibrate.py | 95 ++++++++++++++------------ screen.py | 9 ++- 7 files changed, 282 insertions(+), 214 deletions(-) diff --git a/ks_includes/printer.py b/ks_includes/printer.py index 03ff10b0..86b7e3aa 100644 --- a/ks_includes/printer.py +++ b/ks_includes/printer.py @@ -22,6 +22,8 @@ class Printer: self.output_pin_count = 0 self.store_timeout = None self.tempstore = {} + self.busy_cb = None + self.busy = None def reset(self): self.config = None @@ -38,6 +40,8 @@ class Printer: self.output_pin_count = None self.store_timeout = None self.tempstore = None + self.busy_cb = None + self.busy = None def reinit(self, printer_info, data): self.config = data['configfile']['config'] @@ -49,6 +53,7 @@ class Printer: self.fancount = 0 self.output_pin_count = 0 self.tempstore = {} + self.busy = False if not self.store_timeout: self.store_timeout = GLib.timeout_add_seconds(1, self._update_temp_store) @@ -106,21 +111,30 @@ class Printer: self.data[x] = {} self.data[x].update(data[x]) - if "webhooks" in data or "print_stats" in data: + if "webhooks" in data or "print_stats" in data or "idle_timeout" in data: self.process_status_update() def evaluate_state(self): # webhooks states: startup, ready, shutdown, error # print_stats: standby, printing, paused, error, complete + # idle_timeout: Idle, Printing, Ready if self.data['webhooks']['state'] == "ready" and self.data['print_stats']: if self.data['print_stats']['state'] == 'paused' or self.data.get('pause_resume').get('is_paused'): return "paused" if self.data['print_stats']['state'] == 'printing': return "printing" + if self.data['idle_timeout'] and self.data['idle_timeout']['state'].lower() == "printing": + return "busy" return self.data['webhooks']['state'] def process_status_update(self): state = self.evaluate_state() + if state == "busy": + self.busy = True + return GLib.idle_add(self.busy_cb, True) + if self.busy: + self.busy = False + GLib.idle_add(self.busy_cb, False) if state != self.state: self.change_state(state) @@ -129,8 +143,8 @@ class Printer: self.power_devices[data['device']]['status'] = data['status'] def change_state(self, state): - if state not in list(self.state_callbacks): # disconnected, startup, ready, shutdown, error, paused, printing - return + if state not in list(self.state_callbacks): + return # disconnected, startup, ready, shutdown, error, paused, printing if state != self.state: logging.debug(f"Changing state from '{self.state}' to '{state}'") self.state = state diff --git a/panels/bed_level.py b/panels/bed_level.py index 4f405021..3e938439 100644 --- a/panels/bed_level.py +++ b/panels/bed_level.py @@ -25,18 +25,18 @@ class BedLevelPanel(ScreenPanel): self.x_cnt = 0 self.x_offset = 0 self.y_offset = 0 - self.labels['dm'] = self._gtk.Button("motor-off", _("Disable XY"), "color3") - self.labels['dm'].connect("clicked", self.disable_motors) + self.buttons = {'dm': self._gtk.Button("motor-off", _("Disable XY"), "color3")} + self.buttons['dm'].connect("clicked", self.disable_motors) screw_positions = [] rotation = None grid = self._gtk.HomogeneousGrid() - grid.attach(self.labels['dm'], 0, 0, 1, 1) + grid.attach(self.buttons['dm'], 0, 0, 1, 1) if "screws_tilt_adjust" in self._screen.printer.get_config_section_list(): - self.labels['screws'] = self._gtk.Button("refresh", _("Screws Adjust"), "color4") - self.labels['screws'].connect("clicked", self.screws_tilt_calculate) - grid.attach(self.labels['screws'], 0, 1, 1, 1) + self.buttons['screws'] = self._gtk.Button("refresh", _("Screws Adjust"), "color4") + self.buttons['screws'].connect("clicked", self.screws_tilt_calculate) + grid.attach(self.buttons['screws'], 0, 1, 1, 1) self.screws = self._get_screws("screws_tilt_adjust") logging.info(f"screws_tilt_adjust: {self.screws}") @@ -93,14 +93,14 @@ class BedLevelPanel(ScreenPanel): logging.debug(f"Using {len(self.screws)}-screw locations [x,y] [{self.x_cnt}x{self.y_cnt}]") - self.labels['bl'] = self._gtk.Button("bed-level-t-l", scale=2.5) - self.labels['br'] = self._gtk.Button("bed-level-t-r", scale=2.5) - self.labels['fl'] = self._gtk.Button("bed-level-b-l", scale=2.5) - self.labels['fr'] = self._gtk.Button("bed-level-b-r", scale=2.5) - self.labels['lm'] = self._gtk.Button("bed-level-l-m", scale=2.5) - self.labels['rm'] = self._gtk.Button("bed-level-r-m", scale=2.5) - self.labels['fm'] = self._gtk.Button("bed-level-b-m", scale=2.5) - self.labels['bm'] = self._gtk.Button("bed-level-t-m", scale=2.5) + self.buttons['bl'] = self._gtk.Button("bed-level-t-l", scale=2.5) + self.buttons['br'] = self._gtk.Button("bed-level-t-r", scale=2.5) + self.buttons['fl'] = self._gtk.Button("bed-level-b-l", scale=2.5) + self.buttons['fr'] = self._gtk.Button("bed-level-b-r", scale=2.5) + self.buttons['lm'] = self._gtk.Button("bed-level-l-m", scale=2.5) + self.buttons['rm'] = self._gtk.Button("bed-level-r-m", scale=2.5) + self.buttons['fm'] = self._gtk.Button("bed-level-b-m", scale=2.5) + self.buttons['bm'] = self._gtk.Button("bed-level-t-m", scale=2.5) valid_positions = True if self.ks_printer_cfg is not None: @@ -127,32 +127,32 @@ class BedLevelPanel(ScreenPanel): if valid_positions: if "bl" in screw_positions: - bedgrid.attach(self.labels['bl'], 1, 0, 1, 1) + bedgrid.attach(self.buttons['bl'], 1, 0, 1, 1) if "fl" in screw_positions: - bedgrid.attach(self.labels['fl'], 1, 2, 1, 1) + bedgrid.attach(self.buttons['fl'], 1, 2, 1, 1) if "fr" in screw_positions: - bedgrid.attach(self.labels['fr'], 3, 2, 1, 1) + bedgrid.attach(self.buttons['fr'], 3, 2, 1, 1) if "br" in screw_positions: - bedgrid.attach(self.labels['br'], 3, 0, 1, 1) + bedgrid.attach(self.buttons['br'], 3, 0, 1, 1) if "bm" in screw_positions: - bedgrid.attach(self.labels['bm'], 2, 0, 1, 1) + bedgrid.attach(self.buttons['bm'], 2, 0, 1, 1) if "fm" in screw_positions: - bedgrid.attach(self.labels['fm'], 2, 2, 1, 1) + bedgrid.attach(self.buttons['fm'], 2, 2, 1, 1) if "lm" in screw_positions: - bedgrid.attach(self.labels['lm'], 1, 1, 1, 1) + bedgrid.attach(self.buttons['lm'], 1, 1, 1, 1) if "rm" in screw_positions: - bedgrid.attach(self.labels['rm'], 3, 1, 1, 1) + bedgrid.attach(self.buttons['rm'], 3, 1, 1, 1) elif nscrews in {4, 6, 8}: - bedgrid.attach(self.labels['bl'], 1, 0, 1, 1) - bedgrid.attach(self.labels['fl'], 1, 2, 1, 1) - bedgrid.attach(self.labels['fr'], 3, 2, 1, 1) - bedgrid.attach(self.labels['br'], 3, 0, 1, 1) + bedgrid.attach(self.buttons['bl'], 1, 0, 1, 1) + bedgrid.attach(self.buttons['fl'], 1, 2, 1, 1) + bedgrid.attach(self.buttons['fr'], 3, 2, 1, 1) + bedgrid.attach(self.buttons['br'], 3, 0, 1, 1) if self.x_cnt == 3: - bedgrid.attach(self.labels['bm'], 2, 0, 1, 1) - bedgrid.attach(self.labels['fm'], 2, 2, 1, 1) + bedgrid.attach(self.buttons['bm'], 2, 0, 1, 1) + bedgrid.attach(self.buttons['fm'], 2, 2, 1, 1) if self.y_cnt == 3: - bedgrid.attach(self.labels['lm'], 1, 1, 1, 1) - bedgrid.attach(self.labels['rm'], 3, 1, 1, 1) + bedgrid.attach(self.buttons['lm'], 1, 1, 1, 1) + bedgrid.attach(self.buttons['rm'], 3, 1, 1, 1) else: label = Gtk.Label( _("Bed screw configuration:") + f" {nscrews}\n\n" @@ -169,14 +169,14 @@ class BedLevelPanel(ScreenPanel): # fm bm # fr rm br - self.labels['bl'].connect("clicked", self.go_to_position, fl) - self.labels['bm'].connect("clicked", self.go_to_position, lm) - self.labels['br'].connect("clicked", self.go_to_position, bl) - self.labels['rm'].connect("clicked", self.go_to_position, bm) - self.labels['fr'].connect("clicked", self.go_to_position, br) - self.labels['fm'].connect("clicked", self.go_to_position, rm) - self.labels['fl'].connect("clicked", self.go_to_position, fr) - self.labels['lm'].connect("clicked", self.go_to_position, fm) + self.buttons['bl'].connect("clicked", self.go_to_position, fl) + self.buttons['bm'].connect("clicked", self.go_to_position, lm) + self.buttons['br'].connect("clicked", self.go_to_position, bl) + self.buttons['rm'].connect("clicked", self.go_to_position, bm) + self.buttons['fr'].connect("clicked", self.go_to_position, br) + self.buttons['fm'].connect("clicked", self.go_to_position, rm) + self.buttons['fl'].connect("clicked", self.go_to_position, fr) + self.buttons['lm'].connect("clicked", self.go_to_position, fm) self.screw_dict = { 'bl': fl, 'bm': lm, @@ -191,14 +191,14 @@ class BedLevelPanel(ScreenPanel): # fr fm fl # rm lm # br bm bl - self.labels['bl'].connect("clicked", self.go_to_position, fr) - self.labels['bm'].connect("clicked", self.go_to_position, fm) - self.labels['br'].connect("clicked", self.go_to_position, fl) - self.labels['rm'].connect("clicked", self.go_to_position, lm) - self.labels['fr'].connect("clicked", self.go_to_position, bl) - self.labels['fm'].connect("clicked", self.go_to_position, bm) - self.labels['fl'].connect("clicked", self.go_to_position, br) - self.labels['lm'].connect("clicked", self.go_to_position, rm) + self.buttons['bl'].connect("clicked", self.go_to_position, fr) + self.buttons['bm'].connect("clicked", self.go_to_position, fm) + self.buttons['br'].connect("clicked", self.go_to_position, fl) + self.buttons['rm'].connect("clicked", self.go_to_position, lm) + self.buttons['fr'].connect("clicked", self.go_to_position, bl) + self.buttons['fm'].connect("clicked", self.go_to_position, bm) + self.buttons['fl'].connect("clicked", self.go_to_position, br) + self.buttons['lm'].connect("clicked", self.go_to_position, rm) self.screw_dict = { 'bl': fr, 'bm': fm, @@ -213,14 +213,14 @@ class BedLevelPanel(ScreenPanel): # br rm fr # bm fm # bl lm fl - self.labels['bl'].connect("clicked", self.go_to_position, br) - self.labels['bm'].connect("clicked", self.go_to_position, rm) - self.labels['br'].connect("clicked", self.go_to_position, fr) - self.labels['rm'].connect("clicked", self.go_to_position, fm) - self.labels['fr'].connect("clicked", self.go_to_position, fl) - self.labels['fm'].connect("clicked", self.go_to_position, lm) - self.labels['fl'].connect("clicked", self.go_to_position, bl) - self.labels['lm'].connect("clicked", self.go_to_position, bm) + self.buttons['bl'].connect("clicked", self.go_to_position, br) + self.buttons['bm'].connect("clicked", self.go_to_position, rm) + self.buttons['br'].connect("clicked", self.go_to_position, fr) + self.buttons['rm'].connect("clicked", self.go_to_position, fm) + self.buttons['fr'].connect("clicked", self.go_to_position, fl) + self.buttons['fm'].connect("clicked", self.go_to_position, lm) + self.buttons['fl'].connect("clicked", self.go_to_position, bl) + self.buttons['lm'].connect("clicked", self.go_to_position, bm) self.screw_dict = { 'bl': br, 'bm': rm, @@ -235,14 +235,14 @@ class BedLevelPanel(ScreenPanel): # bl bm br # lm rm # fl fm fr - self.labels['bl'].connect("clicked", self.go_to_position, bl) - self.labels['bm'].connect("clicked", self.go_to_position, bm) - self.labels['br'].connect("clicked", self.go_to_position, br) - self.labels['rm'].connect("clicked", self.go_to_position, rm) - self.labels['fr'].connect("clicked", self.go_to_position, fr) - self.labels['fm'].connect("clicked", self.go_to_position, fm) - self.labels['fl'].connect("clicked", self.go_to_position, fl) - self.labels['lm'].connect("clicked", self.go_to_position, lm) + self.buttons['bl'].connect("clicked", self.go_to_position, bl) + self.buttons['bm'].connect("clicked", self.go_to_position, bm) + self.buttons['br'].connect("clicked", self.go_to_position, br) + self.buttons['rm'].connect("clicked", self.go_to_position, rm) + self.buttons['fr'].connect("clicked", self.go_to_position, fr) + self.buttons['fm'].connect("clicked", self.go_to_position, fm) + self.buttons['fl'].connect("clicked", self.go_to_position, fl) + self.buttons['lm'].connect("clicked", self.go_to_position, lm) self.screw_dict = { 'bl': bl, 'bm': bm, @@ -259,9 +259,8 @@ class BedLevelPanel(ScreenPanel): def activate(self): for key, value in self.screw_dict.items(): - self.labels[key].set_label(f"{value}") - if self._printer.config_section_exists("screws_tilt_adjust"): - self.labels['screws'].set_sensitive(True) + self.buttons[key].set_label(f"{value}") + self.process_busy(self._printer.busy) def go_to_position(self, widget, position): if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": @@ -283,13 +282,23 @@ class BedLevelPanel(ScreenPanel): "M18" # Disable motors ) - def process_update(self, action, data): + def process_busy(self, busy): + for button in self.buttons: + if button == "screws": + self.buttons[button].set_sensitive(self._printer.config_section_exists("screws_tilt_adjust") + and (not busy)) + continue + self.buttons[button].set_sensitive((not busy)) + def process_update(self, action, data): + if action == "notify_busy": + self.process_busy(data) + return if action != "notify_gcode_response": return if data.startswith('!!'): self.response_count = 0 - self.labels['screws'].set_sensitive(True) + self.buttons['screws'].set_sensitive(True) return result = re.match( "^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]+ :" + @@ -304,11 +313,11 @@ class BedLevelPanel(ScreenPanel): for key, value in self.screw_dict.items(): if value and x == value[0] and y == value[1]: logging.debug(f"X: {x} Y: {y} Adjust: {result[5]} Pos: {key}") - self.labels[key].set_label(result[5]) + self.buttons[key].set_label(result[5]) break self.response_count += 1 if self.response_count >= len(self.screws) - 1: - self.labels['screws'].set_sensitive(True) + self.buttons['screws'].set_sensitive(True) else: result = re.match( "^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]", @@ -323,7 +332,7 @@ class BedLevelPanel(ScreenPanel): for key, value in self.screw_dict.items(): if value and x == value[0] and y == value[1]: logging.debug(f"X: {x} Y: {y} Pos: {key}") - self.labels[key].set_label(_("Reference")) + self.buttons[key].set_label(_("Reference")) def _get_screws(self, config_section_name): screws = [] @@ -342,5 +351,5 @@ class BedLevelPanel(ScreenPanel): if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME) self.response_count = 0 - self.labels['screws'].set_sensitive(False) + self.buttons['screws'].set_sensitive(False) self._screen._ws.klippy.gcode_script("SCREWS_TILT_CALCULATE") diff --git a/panels/bed_mesh.py b/panels/bed_mesh.py index a562d92e..d3f49689 100644 --- a/panels/bed_mesh.py +++ b/panels/bed_mesh.py @@ -19,26 +19,27 @@ class BedMeshPanel(ScreenPanel): def __init__(self, screen, title): super().__init__(screen, title) - self.clear = None - self.profiles = {} self.show_create = False self.active_mesh = None - addprofile = self._gtk.Button("increase", " " + _("Add profile"), "color1", .66, Gtk.PositionType.LEFT, 1) - addprofile.connect("clicked", self.show_create_profile) - addprofile.set_hexpand(True) - self.clear = self._gtk.Button("cancel", " " + _("Clear"), "color2", .66, Gtk.PositionType.LEFT, 1) - self.clear.connect("clicked", self.send_clear_mesh) - self.clear.set_hexpand(True) - calibrate = self._gtk.Button("refresh", " " + _("Calibrate"), "color3", .66, Gtk.PositionType.LEFT, 1) - calibrate.connect("clicked", self.calibrate_mesh) - calibrate.set_hexpand(True) + self.profiles = {} + self.buttons = { + 'add': self._gtk.Button("increase", " " + _("Add profile"), "color1", .66, Gtk.PositionType.LEFT, 1), + 'calib': self._gtk.Button("refresh", " " + _("Calibrate"), "color3", .66, Gtk.PositionType.LEFT, 1), + 'clear': self._gtk.Button("cancel", " " + _("Clear"), "color2", .66, Gtk.PositionType.LEFT, 1), + } + self.buttons['add'].connect("clicked", self.show_create_profile) + self.buttons['add'].set_hexpand(True) + self.buttons['clear'].connect("clicked", self.send_clear_mesh) + self.buttons['clear'].set_hexpand(True) + self.buttons['calib'].connect("clicked", self.calibrate_mesh) + self.buttons['calib'].set_hexpand(True) topbar = Gtk.Box(spacing=5) topbar.set_hexpand(True) topbar.set_vexpand(False) - topbar.add(addprofile) - topbar.add(self.clear) - topbar.add(calibrate) + topbar.add(self.buttons['add']) + topbar.add(self.buttons['clear']) + topbar.add(self.buttons['calib']) # Create a grid for all profiles self.labels['profiles'] = Gtk.Grid() @@ -69,6 +70,7 @@ class BedMeshPanel(ScreenPanel): self.load_meshes() with contextlib.suppress(KeyError): self.activate_mesh(self._screen.printer.get_stat("bed_mesh", "profile_name")) + self.process_busy(self._printer.busy) def activate_mesh(self, profile): if self.active_mesh is not None: @@ -78,7 +80,7 @@ class BedMeshPanel(ScreenPanel): logging.info("Clearing active profile") self.active_mesh = None self.update_graph() - self.clear.set_sensitive(False) + self.buttons['clear'].set_sensitive(False) return if profile not in self.profiles: self.add_profile(profile) @@ -89,7 +91,7 @@ class BedMeshPanel(ScreenPanel): self.profiles[profile]['name'].get_style_context().add_class("button_active") self.active_mesh = profile self.update_graph(profile=profile) - self.clear.set_sensitive(True) + self.buttons['clear'].set_sensitive(True) def retrieve_bm(self, profile): if profile is None: @@ -182,7 +184,20 @@ class BedMeshPanel(ScreenPanel): if prof not in bm_profiles: self.remove_profile(prof) + def process_busy(self, busy): + for button in self.buttons: + if button == 'clear': + self.buttons[button].set_sensitive(self.active_mesh is not None) + continue + self.buttons[button].set_sensitive((not busy)) + for profile in self.profiles: + self.profiles[profile]["save"].set_sensitive((not busy)) + self.profiles[profile]["delete"].set_sensitive((not busy)) + def process_update(self, action, data): + if action == "notify_busy": + self.process_busy(data) + return if action == "notify_status_update": with contextlib.suppress(KeyError): self.activate_mesh(data['bed_mesh']['profile_name']) @@ -213,7 +228,7 @@ class BedMeshPanel(ScreenPanel): if not self.profiles: self.active_mesh = None self.update_graph() - self.clear.set_sensitive(False) + self.buttons['clear'].set_sensitive(False) def show_create_profile(self, widget): diff --git a/panels/extrude.py b/panels/extrude.py index f412d2d7..c45abfa4 100644 --- a/panels/extrude.py +++ b/panels/extrude.py @@ -39,18 +39,18 @@ class ExtrudePanel(ScreenPanel): self.distance = int(self.distances[1]) self.speed = int(self.speeds[1]) - self.labels['extrude'] = self._gtk.Button("extrude", _("Extrude"), "color4") - self.labels['extrude'].connect("clicked", self.extrude, "+") - self.labels['load'] = self._gtk.Button("arrow-down", _("Load"), "color3") - - self.labels['load'].connect("clicked", self.load_unload, "+") - self.labels['unload'] = self._gtk.Button("arrow-up", _("Unload"), "color2") - - self.labels['unload'].connect("clicked", self.load_unload, "-") - self.labels['retract'] = self._gtk.Button("retract", _("Retract"), "color1") - self.labels['retract'].connect("clicked", self.extrude, "-") - self.labels['temperature'] = self._gtk.Button("heat-up", _("Temperature"), "color4") - self.labels['temperature'].connect("clicked", self.menu_item_clicked, "temperature", { + self.buttons = { + 'extrude': self._gtk.Button("extrude", _("Extrude"), "color4"), + 'load': self._gtk.Button("arrow-down", _("Load"), "color3"), + 'unload': self._gtk.Button("arrow-up", _("Unload"), "color2"), + 'retract': self._gtk.Button("retract", _("Retract"), "color1"), + 'temperature': self._gtk.Button("heat-up", _("Temperature"), "color4"), + } + self.buttons['extrude'].connect("clicked", self.extrude, "+") + self.buttons['load'].connect("clicked", self.load_unload, "+") + self.buttons['unload'].connect("clicked", self.load_unload, "-") + self.buttons['retract'].connect("clicked", self.extrude, "-") + self.buttons['temperature'].connect("clicked", self.menu_item_clicked, "temperature", { "name": "Temperature", "panel": "temperature" }) @@ -70,7 +70,7 @@ class ExtrudePanel(ScreenPanel): extgrid.attach(self.labels[extruder], i, 0, 1, 1) i += 1 if i < (limit - 1): - extgrid.attach(self.labels['temperature'], i + 1, 0, 1, 1) + extgrid.attach(self.buttons['temperature'], i + 1, 0, 1, 1) distgrid = Gtk.Grid() for j, i in enumerate(self.distances): @@ -152,28 +152,39 @@ class ExtrudePanel(ScreenPanel): grid.attach(extgrid, 0, 0, 4, 1) if self._screen.vertical_mode: - grid.attach(self.labels['extrude'], 0, 1, 2, 1) - grid.attach(self.labels['retract'], 2, 1, 2, 1) - grid.attach(self.labels['load'], 0, 2, 2, 1) - grid.attach(self.labels['unload'], 2, 2, 2, 1) + grid.attach(self.buttons['extrude'], 0, 1, 2, 1) + grid.attach(self.buttons['retract'], 2, 1, 2, 1) + grid.attach(self.buttons['load'], 0, 2, 2, 1) + grid.attach(self.buttons['unload'], 2, 2, 2, 1) grid.attach(distbox, 0, 3, 4, 1) grid.attach(speedbox, 0, 4, 4, 1) grid.attach(sensors, 0, 5, 4, 1) else: - grid.attach(self.labels['extrude'], 0, 2, 1, 1) - grid.attach(self.labels['load'], 1, 2, 1, 1) - grid.attach(self.labels['unload'], 2, 2, 1, 1) - grid.attach(self.labels['retract'], 3, 2, 1, 1) + grid.attach(self.buttons['extrude'], 0, 2, 1, 1) + grid.attach(self.buttons['load'], 1, 2, 1, 1) + grid.attach(self.buttons['unload'], 2, 2, 1, 1) + grid.attach(self.buttons['retract'], 3, 2, 1, 1) grid.attach(distbox, 0, 3, 2, 1) grid.attach(speedbox, 2, 3, 2, 1) grid.attach(sensors, 0, 4, 4, 1) self.content.add(grid) + def activate(self): + self.process_busy(self._printer.busy) + + def process_busy(self, busy): + for button in self.buttons: + if button == "temperature": + continue + self.buttons[button].set_sensitive((not busy)) + def process_update(self, action, data): + if action == "notify_busy": + self.process_busy(data) + return if action != "notify_status_update": return - for x in self._printer.get_tools(): self.update_temp( x, diff --git a/panels/move.py b/panels/move.py index 8101e1ea..38da1686 100644 --- a/panels/move.py +++ b/panels/move.py @@ -21,77 +21,71 @@ class MovePanel(ScreenPanel): super().__init__(screen, title) self.settings = {} self.menu = ['move_menu'] - - self.labels['x+'] = self._gtk.Button("arrow-right", "X+", "color1") - self.labels['x+'].connect("clicked", self.move, "X", "+") - self.labels['x-'] = self._gtk.Button("arrow-left", "X-", "color1") - self.labels['x-'].connect("clicked", self.move, "X", "-") - - self.labels['y+'] = self._gtk.Button("arrow-up", "Y+", "color2") - self.labels['y+'].connect("clicked", self.move, "Y", "+") - self.labels['y-'] = self._gtk.Button("arrow-down", "Y-", "color2") - self.labels['y-'].connect("clicked", self.move, "Y", "-") - - self.labels['z+'] = self._gtk.Button("z-farther", "Z+", "color3") - self.labels['z+'].connect("clicked", self.move, "Z", "+") - self.labels['z-'] = self._gtk.Button("z-closer", "Z-", "color3") - self.labels['z-'].connect("clicked", self.move, "Z", "-") - - self.labels['home'] = self._gtk.Button("home", _("Home All"), "color4") - self.labels['home'].connect("clicked", self.home) - - self.labels['home-xy'] = self._gtk.Button("home", _("Home XY"), "color4") - self.labels['home-xy'].connect("clicked", self.homexy) - - self.labels['z_tilt'] = self._gtk.Button("z-tilt", _("Z Tilt"), "color4") - self.labels['z_tilt'].connect("clicked", self.z_tilt) - - self.labels['quad_gantry_level'] = self._gtk.Button("z-tilt", _("Quad Gantry Level"), "color4") - self.labels['quad_gantry_level'].connect("clicked", self.quad_gantry_level) - - self.labels['motors-off'] = self._gtk.Button("motor-off", _("Disable Motors"), "color4") + self.buttons = { + 'x+': self._gtk.Button("arrow-right", "X+", "color1"), + 'x-': self._gtk.Button("arrow-left", "X-", "color1"), + 'y+': self._gtk.Button("arrow-up", "Y+", "color2"), + 'y-': self._gtk.Button("arrow-down", "Y-", "color2"), + 'z+': self._gtk.Button("z-farther", "Z+", "color3"), + 'z-': self._gtk.Button("z-closer", "Z-", "color3"), + 'home': self._gtk.Button("home", _("Home All"), "color4"), + 'home_xy': self._gtk.Button("home", _("Home XY"), "color4"), + 'z_tilt': self._gtk.Button("z-tilt", _("Z Tilt"), "color4"), + 'quad_gantry_level': self._gtk.Button("z-tilt", _("Quad Gantry Level"), "color4"), + 'motors_off': self._gtk.Button("motor-off", _("Disable Motors"), "color4"), + } + self.buttons['x+'].connect("clicked", self.move, "X", "+") + self.buttons['x-'].connect("clicked", self.move, "X", "-") + self.buttons['y+'].connect("clicked", self.move, "Y", "+") + self.buttons['y-'].connect("clicked", self.move, "Y", "-") + self.buttons['z+'].connect("clicked", self.move, "Z", "+") + self.buttons['z-'].connect("clicked", self.move, "Z", "-") + self.buttons['home'].connect("clicked", self.home) + self.buttons['home_xy'].connect("clicked", self.homexy) + self.buttons['z_tilt'].connect("clicked", self.z_tilt) + self.buttons['quad_gantry_level'].connect("clicked", self.quad_gantry_level) script = {"script": "M18"} - self.labels['motors-off'].connect("clicked", self._screen._confirm_send_action, - _("Are you sure you wish to disable motors?"), - "printer.gcode.script", script) + self.buttons['motors_off'].connect("clicked", self._screen._confirm_send_action, + _("Are you sure you wish to disable motors?"), + "printer.gcode.script", script) grid = self._gtk.HomogeneousGrid() if self._screen.vertical_mode: if self._screen.lang_ltr: - grid.attach(self.labels['x+'], 2, 1, 1, 1) - grid.attach(self.labels['x-'], 0, 1, 1, 1) - grid.attach(self.labels['z+'], 2, 2, 1, 1) - grid.attach(self.labels['z-'], 0, 2, 1, 1) + grid.attach(self.buttons['x+'], 2, 1, 1, 1) + grid.attach(self.buttons['x-'], 0, 1, 1, 1) + grid.attach(self.buttons['z+'], 2, 2, 1, 1) + grid.attach(self.buttons['z-'], 0, 2, 1, 1) else: - grid.attach(self.labels['x+'], 0, 1, 1, 1) - grid.attach(self.labels['x-'], 2, 1, 1, 1) - grid.attach(self.labels['z+'], 0, 2, 1, 1) - grid.attach(self.labels['z-'], 2, 2, 1, 1) - grid.attach(self.labels['y+'], 1, 0, 1, 1) - grid.attach(self.labels['y-'], 1, 1, 1, 1) + grid.attach(self.buttons['x+'], 0, 1, 1, 1) + grid.attach(self.buttons['x-'], 2, 1, 1, 1) + grid.attach(self.buttons['z+'], 0, 2, 1, 1) + grid.attach(self.buttons['z-'], 2, 2, 1, 1) + grid.attach(self.buttons['y+'], 1, 0, 1, 1) + grid.attach(self.buttons['y-'], 1, 1, 1, 1) else: if self._screen.lang_ltr: - grid.attach(self.labels['x+'], 2, 1, 1, 1) - grid.attach(self.labels['x-'], 0, 1, 1, 1) + grid.attach(self.buttons['x+'], 2, 1, 1, 1) + grid.attach(self.buttons['x-'], 0, 1, 1, 1) else: - grid.attach(self.labels['x+'], 0, 1, 1, 1) - grid.attach(self.labels['x-'], 2, 1, 1, 1) - grid.attach(self.labels['y+'], 1, 0, 1, 1) - grid.attach(self.labels['y-'], 1, 1, 1, 1) - grid.attach(self.labels['z+'], 3, 0, 1, 1) - grid.attach(self.labels['z-'], 3, 1, 1, 1) + grid.attach(self.buttons['x+'], 0, 1, 1, 1) + grid.attach(self.buttons['x-'], 2, 1, 1, 1) + grid.attach(self.buttons['y+'], 1, 0, 1, 1) + grid.attach(self.buttons['y-'], 1, 1, 1, 1) + grid.attach(self.buttons['z+'], 3, 0, 1, 1) + grid.attach(self.buttons['z-'], 3, 1, 1, 1) - grid.attach(self.labels['home'], 0, 0, 1, 1) + grid.attach(self.buttons['home'], 0, 0, 1, 1) if self._printer.config_section_exists("z_tilt"): - grid.attach(self.labels['z_tilt'], 2, 0, 1, 1) + grid.attach(self.buttons['z_tilt'], 2, 0, 1, 1) elif self._printer.config_section_exists("quad_gantry_level"): - grid.attach(self.labels['quad_gantry_level'], 2, 0, 1, 1) + grid.attach(self.buttons['quad_gantry_level'], 2, 0, 1, 1) elif "delta" in self._screen.printer.get_config_section("printer")['kinematics']: - grid.attach(self.labels['motors-off'], 2, 0, 1, 1) + grid.attach(self.buttons['motors_off'], 2, 0, 1, 1) else: - grid.attach(self.labels['home-xy'], 2, 0, 1, 1) + grid.attach(self.buttons['home_xy'], 2, 0, 1, 1) distgrid = Gtk.Grid() for j, i in enumerate(self.distances): @@ -160,10 +154,21 @@ class MovePanel(ScreenPanel): name = list(option)[0] self.add_option('options', self.settings, name, option[name]) + def activate(self): + self.process_busy(self._printer.busy) + + def process_busy(self, busy): + buttons = ("home", "home_xy", "z_tilt", "quad_gantry_level") + for button in buttons: + if button in self.buttons: + self.buttons[button].set_sensitive(not busy) + def process_update(self, action, data): + if action == "notify_busy": + self.process_busy(data) + return if action != "notify_status_update": return - homed_axes = self._screen.printer.get_stat("toolhead", "homed_axes") if homed_axes == "xyz": if "gcode_move" in data and "gcode_position" in data["gcode_move"]: diff --git a/panels/zcalibrate.py b/panels/zcalibrate.py index 0552ee3a..0044a2a9 100644 --- a/panels/zcalibrate.py +++ b/panels/zcalibrate.py @@ -36,16 +36,17 @@ class ZCalibratePanel(ScreenPanel): pos.attach(Gtk.Label(_("New")), 1, 3, 1, 1) pos.attach(Gtk.Label(f"{self.z_offset:.2f}"), 0, 4, 1, 1) pos.attach(self.widgets['zoffset'], 1, 4, 1, 1) - - self.widgets['zpos'] = self._gtk.Button('z-farther', _("Raise Nozzle"), 'color4') - self.widgets['zpos'].connect("clicked", self.move, "+") - self.widgets['zneg'] = self._gtk.Button('z-closer', _("Lower Nozzle"), 'color1') - self.widgets['zneg'].connect("clicked", self.move, "-") - self.widgets['start'] = self._gtk.Button('resume', _("Start"), 'color3') - self.widgets['complete'] = self._gtk.Button('complete', _('Accept'), 'color3') - self.widgets['complete'].connect("clicked", self.accept) - self.widgets['cancel'] = self._gtk.Button('cancel', _('Abort'), 'color2') - self.widgets['cancel'].connect("clicked", self.abort) + self.buttons = { + 'zpos': self._gtk.Button('z-farther', _("Raise Nozzle"), 'color4'), + 'zneg': self._gtk.Button('z-closer', _("Lower Nozzle"), 'color1'), + 'start': self._gtk.Button('resume', _("Start"), 'color3'), + 'complete': self._gtk.Button('complete', _('Accept'), 'color3'), + 'cancel': self._gtk.Button('cancel', _('Abort'), 'color2'), + } + self.buttons['zpos'].connect("clicked", self.move, "+") + self.buttons['zneg'].connect("clicked", self.move, "-") + self.buttons['complete'].connect("clicked", self.accept) + self.buttons['cancel'].connect("clicked", self.abort) functions = [] pobox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) @@ -75,9 +76,9 @@ class ZCalibratePanel(ScreenPanel): self.labels['popover'].set_position(Gtk.PositionType.BOTTOM) if len(functions) > 1: - self.widgets['start'].connect("clicked", self.on_popover_clicked) + self.buttons['start'].connect("clicked", self.on_popover_clicked) else: - self.widgets['start'].connect("clicked", self.start_calibration, functions[0]) + self.buttons['start'].connect("clicked", self.start_calibration, functions[0]) distgrid = Gtk.Grid() for j, i in enumerate(self.distances): @@ -103,22 +104,21 @@ class ZCalibratePanel(ScreenPanel): grid = Gtk.Grid() grid.set_column_homogeneous(True) if self._screen.vertical_mode: - grid.attach(self.widgets['zpos'], 0, 1, 1, 1) - grid.attach(self.widgets['zneg'], 0, 2, 1, 1) - grid.attach(self.widgets['start'], 0, 0, 1, 1) + grid.attach(self.buttons['zpos'], 0, 1, 1, 1) + grid.attach(self.buttons['zneg'], 0, 2, 1, 1) + grid.attach(self.buttons['start'], 0, 0, 1, 1) grid.attach(pos, 1, 0, 1, 1) - grid.attach(self.widgets['complete'], 1, 1, 1, 1) - grid.attach(self.widgets['cancel'], 1, 2, 1, 1) + grid.attach(self.buttons['complete'], 1, 1, 1, 1) + grid.attach(self.buttons['cancel'], 1, 2, 1, 1) grid.attach(distances, 0, 3, 2, 1) else: - grid.attach(self.widgets['zpos'], 0, 0, 1, 1) - grid.attach(self.widgets['zneg'], 0, 1, 1, 1) - grid.attach(self.widgets['start'], 1, 0, 1, 1) + grid.attach(self.buttons['zpos'], 0, 0, 1, 1) + grid.attach(self.buttons['zneg'], 0, 1, 1, 1) + grid.attach(self.buttons['start'], 1, 0, 1, 1) grid.attach(pos, 1, 1, 1, 1) - grid.attach(self.widgets['complete'], 2, 0, 1, 1) - grid.attach(self.widgets['cancel'], 2, 1, 1, 1) + grid.attach(self.buttons['complete'], 2, 0, 1, 1) + grid.attach(self.buttons['cancel'], 2, 1, 1, 1) grid.attach(distances, 0, 2, 3, 1) - self.buttons_not_calibrating() self.content.add(grid) def _add_button(self, label, method, pobox): @@ -222,8 +222,14 @@ class ZCalibratePanel(ScreenPanel): logging.info(f"Moving to X:{x_position} Y:{y_position}") self._screen._ws.klippy.gcode_script(f'G0 X{x_position} Y{y_position} F3000') - def process_update(self, action, data): + def process_busy(self, busy): + for button in self.buttons: + self.buttons[button].set_sensitive(not busy) + def process_update(self, action, data): + if action == "notify_busy": + self.process_busy(data) + return if action == "notify_status_update": if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": self.widgets['zposition'].set_text("Z: ?") @@ -274,31 +280,32 @@ class ZCalibratePanel(ScreenPanel): self._screen._ws.klippy.gcode_script(KlippyGcodes.ACCEPT) def buttons_calibrating(self): - self.widgets['start'].get_style_context().remove_class('color3') - self.widgets['start'].set_sensitive(False) + self.buttons['start'].get_style_context().remove_class('color3') + self.buttons['start'].set_sensitive(False) - self.widgets['zpos'].set_sensitive(True) - self.widgets['zpos'].get_style_context().add_class('color4') - self.widgets['zneg'].set_sensitive(True) - self.widgets['zneg'].get_style_context().add_class('color1') - self.widgets['complete'].set_sensitive(True) - self.widgets['complete'].get_style_context().add_class('color3') - self.widgets['cancel'].set_sensitive(True) - self.widgets['cancel'].get_style_context().add_class('color2') + self.buttons['zpos'].set_sensitive(True) + self.buttons['zpos'].get_style_context().add_class('color4') + self.buttons['zneg'].set_sensitive(True) + self.buttons['zneg'].get_style_context().add_class('color1') + self.buttons['complete'].set_sensitive(True) + self.buttons['complete'].get_style_context().add_class('color3') + self.buttons['cancel'].set_sensitive(True) + self.buttons['cancel'].get_style_context().add_class('color2') def buttons_not_calibrating(self): - self.widgets['start'].get_style_context().add_class('color3') - self.widgets['start'].set_sensitive(True) + self.buttons['start'].get_style_context().add_class('color3') + self.buttons['start'].set_sensitive(True) - self.widgets['zpos'].set_sensitive(False) - self.widgets['zpos'].get_style_context().remove_class('color4') - self.widgets['zneg'].set_sensitive(False) - self.widgets['zneg'].get_style_context().remove_class('color1') - self.widgets['complete'].set_sensitive(False) - self.widgets['complete'].get_style_context().remove_class('color3') - self.widgets['cancel'].set_sensitive(False) - self.widgets['cancel'].get_style_context().remove_class('color2') + self.buttons['zpos'].set_sensitive(False) + self.buttons['zpos'].get_style_context().remove_class('color4') + self.buttons['zneg'].set_sensitive(False) + self.buttons['zneg'].get_style_context().remove_class('color1') + self.buttons['complete'].set_sensitive(False) + self.buttons['complete'].get_style_context().remove_class('color3') + self.buttons['cancel'].set_sensitive(False) + self.buttons['cancel'].get_style_context().remove_class('color2') def activate(self): # This is only here because klipper doesn't provide a method to detect if it's calibrating + self.process_busy(self._printer.busy) self._screen._ws.klippy.gcode_script(KlippyGcodes.testz_move("+0.001")) diff --git a/screen.py b/screen.py index bef8ade1..993e646c 100755 --- a/screen.py +++ b/screen.py @@ -187,6 +187,7 @@ class KlipperScreen(Gtk.Window): "startup": self.state_startup, "shutdown": self.state_shutdown } + self.printer.busy_cb = self.process_busy_state self.printer_initializing(_("Connecting to %s") % name, remove=True) self._ws = KlippyWebsocket(self, @@ -511,7 +512,7 @@ class KlipperScreen(Gtk.Window): self.remove_keyboard() if self._config.get_main_config().getboolean('autoclose_popups', True): self.close_popup_message() - self._remove_current_panel() + self._remove_current_panel(True) def _menu_go_home(self, widget=None): logging.info("#### Menu go home") @@ -629,6 +630,9 @@ class KlipperScreen(Gtk.Window): self.base_panel.show_heaters(False) self.show_panel("printer_select", "printer_select", _("Printer Select"), 2) + def process_busy_state(self, busy): + self.process_update("notify_busy", busy) + def state_execute(self, callback): self.reinit_count = 0 self.init_printer() @@ -740,6 +744,9 @@ class KlipperScreen(Gtk.Window): "printer.gcode.script", script ) + self.process_update(action, data) + + def process_update(self, action, data): self.base_panel.process_update(action, data) for x in self.subscriptions: self.panels[x].process_update(action, data)