From 70d7564a7889cef6b2b004a5fe44dd5863592c1e Mon Sep 17 00:00:00 2001 From: alfrix Date: Thu, 8 Dec 2022 00:26:54 -0300 Subject: [PATCH] shorten _screen.printer to _printer --- panels/base_panel.py | 20 ++++++++++---------- panels/bed_level.py | 12 ++++++------ panels/bed_mesh.py | 6 +++--- panels/extrude.py | 2 +- panels/input_shaper.py | 2 +- panels/job_status.py | 22 +++++++++++----------- panels/move.py | 4 ++-- panels/power.py | 8 ++++---- panels/splash_screen.py | 6 +++--- panels/temperature.py | 2 +- panels/zcalibrate.py | 20 ++++++++++---------- 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/panels/base_panel.py b/panels/base_panel.py index a0eba4c1..1bae646d 100644 --- a/panels/base_panel.py +++ b/panels/base_panel.py @@ -113,11 +113,11 @@ class BasePanel(ScreenPanel): try: for child in self.control['temp_box'].get_children(): self.control['temp_box'].remove(child) - if not show or self._screen.printer.get_temp_store_devices() is None: + if not show or self._printer.get_temp_store_devices() is None: return img_size = self._gtk.img_scale * self.bts - for device in self._screen.printer.get_temp_store_devices(): + for device in self._printer.get_temp_store_devices(): self.labels[device] = Gtk.Label(label="100ยบ") self.labels[device].set_ellipsize(Pango.EllipsizeMode.START) @@ -131,18 +131,18 @@ class BasePanel(ScreenPanel): nlimit = int(round(log(self._screen.width, 10) * 5 - 10.5)) n = 0 - if self._screen.printer.get_tools(): - self.current_extruder = self._screen.printer.get_stat("toolhead", "extruder") + if self._printer.get_tools(): + self.current_extruder = self._printer.get_stat("toolhead", "extruder") if self.current_extruder and f"{self.current_extruder}_box" in self.labels: self.control['temp_box'].add(self.labels[f"{self.current_extruder}_box"]) n += 1 - if self._screen.printer.has_heated_bed(): + if self._printer.has_heated_bed(): self.control['temp_box'].add(self.labels['heater_bed_box']) n += 1 # Options in the config have priority - for device in self._screen.printer.get_temp_store_devices(): + for device in self._printer.get_temp_store_devices(): # Users can fill the bar if they want if n >= nlimit + 1: break @@ -154,7 +154,7 @@ class BasePanel(ScreenPanel): break # If there is enough space fill with heater_generic - for device in self._screen.printer.get_temp_store_devices(): + for device in self._printer.get_temp_store_devices(): if n >= nlimit: break if device.startswith("heater_generic"): @@ -166,7 +166,7 @@ class BasePanel(ScreenPanel): def get_icon(self, device, img_size): if device.startswith("extruder"): - if self._screen.printer.extrudercount > 1: + if self._printer.extrudercount > 1: if device == "extruder": device = "extruder0" return self._gtk.Image(f"extruder-{device[8:]}", img_size, img_size) @@ -227,10 +227,10 @@ class BasePanel(ScreenPanel): if action != "notify_status_update" or self._screen.printer is None: return - devices = self._screen.printer.get_temp_store_devices() + devices = self._printer.get_temp_store_devices() if devices is not None: for device in devices: - temp = self._screen.printer.get_dev_stat(device, "temperature") + temp = self._printer.get_dev_stat(device, "temperature") if temp is not None and device in self.labels: name = "" if not (device.startswith("extruder") or device.startswith("heater_bed")): diff --git a/panels/bed_level.py b/panels/bed_level.py index 67bb5448..5b4033ae 100644 --- a/panels/bed_level.py +++ b/panels/bed_level.py @@ -33,7 +33,7 @@ class BedLevelPanel(ScreenPanel): grid = self._gtk.HomogeneousGrid() grid.attach(self.buttons['dm'], 0, 0, 1, 1) - if "screws_tilt_adjust" in self._screen.printer.get_config_section_list(): + if "screws_tilt_adjust" in self._printer.get_config_section_list(): 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) @@ -41,7 +41,7 @@ class BedLevelPanel(ScreenPanel): self.screws = self._get_screws("screws_tilt_adjust") logging.info(f"screws_tilt_adjust: {self.screws}") - probe = self._screen.printer.get_probe() + probe = self._printer.get_probe() if probe: if "x_offset" in probe: self.x_offset = round(float(probe['x_offset']), 1) @@ -57,7 +57,7 @@ class BedLevelPanel(ScreenPanel): self.screws = new_screws logging.info(f"screws with offset: {self.screws}") - elif "bed_screws" in self._screen.printer.get_config_section_list(): + elif "bed_screws" in self._printer.get_config_section_list(): self.screws = self._get_screws("bed_screws") logging.info(f"bed_screws: {self.screws}") @@ -262,7 +262,7 @@ class BedLevelPanel(ScreenPanel): self.buttons[key].set_label(f"{value}") def go_to_position(self, widget, position): - if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": + if self._printer.get_stat("toolhead", "homed_axes") != "xyz": self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME) logging.debug(f"Going to position: {position}") script = [ @@ -335,7 +335,7 @@ class BedLevelPanel(ScreenPanel): def _get_screws(self, config_section_name): screws = [] - config_section = self._screen.printer.get_config_section(config_section_name) + config_section = self._printer.get_config_section(config_section_name) for item in config_section: logging.debug(f"{config_section_name}: {config_section[item]}") result = re.match(r"([\-0-9\.]+)\s*,\s*([\-0-9\.]+)", config_section[item]) @@ -347,7 +347,7 @@ class BedLevelPanel(ScreenPanel): return sorted(screws, key=lambda s: (float(s[1]), float(s[0]))) def screws_tilt_calculate(self, widget): - if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": + if self._printer.get_stat("toolhead", "homed_axes") != "xyz": self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME) self.response_count = 0 self.buttons['screws'].set_sensitive(False) diff --git a/panels/bed_mesh.py b/panels/bed_mesh.py index 66df3335..743ca31d 100644 --- a/panels/bed_mesh.py +++ b/panels/bed_mesh.py @@ -68,7 +68,7 @@ class BedMeshPanel(ScreenPanel): def activate(self): self.load_meshes() with contextlib.suppress(KeyError): - self.activate_mesh(self._screen.printer.get_stat("bed_mesh", "profile_name")) + self.activate_mesh(self._printer.get_stat("bed_mesh", "profile_name")) def activate_mesh(self, profile): if self.active_mesh is not None: @@ -268,13 +268,13 @@ class BedMeshPanel(ScreenPanel): def calibrate_mesh(self, widget): self._screen.show_popup_message(_("Calibrating"), level=1) - if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": + if self._printer.get_stat("toolhead", "homed_axes") != "xyz": self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME) self._screen._ws.klippy.gcode_script("BED_MESH_CALIBRATE") # Load zcalibrate to do a manual mesh - if not self._screen.printer.get_probe(): + if not self._printer.get_probe(): self.menu_item_clicked(widget, "refresh", {"name": _("Mesh calibrate"), "panel": "zcalibrate"}) def send_clear_mesh(self, widget): diff --git a/panels/extrude.py b/panels/extrude.py index 85bffea5..8c39fc81 100644 --- a/panels/extrude.py +++ b/panels/extrude.py @@ -19,7 +19,7 @@ class ExtrudePanel(ScreenPanel): def __init__(self, screen, title): super().__init__(screen, title) self.current_extruder = self._printer.get_stat("toolhead", "extruder") - macros = self._screen.printer.get_gcode_macros() + macros = self._printer.get_gcode_macros() self.load_filament = any("LOAD_FILAMENT" in macro.upper() for macro in macros) self.unload_filament = any("UNLOAD_FILAMENT" in macro.upper() for macro in macros) diff --git a/panels/input_shaper.py b/panels/input_shaper.py index 6368acdc..327130af 100644 --- a/panels/input_shaper.py +++ b/panels/input_shaper.py @@ -113,7 +113,7 @@ class InputShaperPanel(ScreenPanel): def start_calibration(self, widget, method): self.labels['popover'].popdown() - if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": + if self._printer.get_stat("toolhead", "homed_axes") != "xyz": self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME) self.calibrating_axis = method if method == "x": diff --git a/panels/job_status.py b/panels/job_status.py index de24c2f9..6c48e2d1 100644 --- a/panels/job_status.py +++ b/panels/job_status.py @@ -122,7 +122,7 @@ class JobStatusPanel(ScreenPanel): self.labels['thumbnail'] = self._gtk.Image("file", self._screen.width / 4, self._screen.height / 4) self.labels['info_grid'] = Gtk.Grid() self.labels['info_grid'].attach(self.labels['thumbnail'], 0, 0, 1, 1) - if self._screen.printer.get_tools(): + if self._printer.get_tools(): self.current_extruder = self._printer.get_stat("toolhead", "extruder") diameter = float(self._printer.get_config_section(self.current_extruder)['filament_diameter']) self.fila_section = pi * ((diameter / 2) ** 2) @@ -159,7 +159,7 @@ class JobStatusPanel(ScreenPanel): nlimit = 2 if self._screen.width <= 480 else 3 n = 0 self.buttons['extruder'] = {} - if self._screen.printer.get_tools(): + if self._printer.get_tools(): for i, extruder in enumerate(self._printer.get_tools()): self.labels[extruder] = Gtk.Label("-") self.buttons['extruder'][extruder] = self._gtk.Button(f"extruder-{i}", "", None, self.bts, @@ -183,7 +183,7 @@ class JobStatusPanel(ScreenPanel): self.buttons['heater']['heater_bed'].set_halign(Gtk.Align.START) self.labels['temp_grid'].attach(self.buttons['heater']['heater_bed'], n, 0, 1, 1) n += 1 - for dev in self._screen.printer.get_heaters(): + for dev in self._printer.get_heaters(): if n >= nlimit: break if dev.startswith("heater_generic"): @@ -201,7 +201,7 @@ class JobStatusPanel(ScreenPanel): if titlebar_items is not None: titlebar_items = [str(i.strip()) for i in titlebar_items.split(',')] logging.info(f"Titlebar items: {titlebar_items}") - for device in self._screen.printer.get_heaters(): + for device in self._printer.get_heaters(): if device.startswith("temperature_sensor"): name = " ".join(device.split(" ")[1:]) for item in titlebar_items: @@ -227,9 +227,9 @@ class JobStatusPanel(ScreenPanel): szfe.set_column_homogeneous(True) szfe.attach(self.buttons['speed'], 0, 0, 3, 1) szfe.attach(self.buttons['z'], 2, 0, 2, 1) - if self._screen.printer.get_tools(): + if self._printer.get_tools(): szfe.attach(self.buttons['extrusion'], 0, 1, 3, 1) - if self._screen.printer.get_fans(): + if self._printer.get_fans(): szfe.attach(self.buttons['fan'], 2, 1, 2, 1) info = Gtk.Grid() @@ -583,7 +583,7 @@ class JobStatusPanel(ScreenPanel): fan_label = "" for fan in self.fans: with contextlib.suppress(KeyError): - self.fans[fan]['speed'] = f"{self._screen.printer.get_fan_speed(fan) * 100:3.0f}%" + self.fans[fan]['speed'] = f"{self._printer.get_fan_speed(fan) * 100:3.0f}%" fan_label += f" {self.fans[fan]['name']}{self.fans[fan]['speed']}" if fan_label: self.buttons['fan'].set_label(fan_label[:12]) @@ -742,16 +742,16 @@ class JobStatusPanel(ScreenPanel): self.enable_button("resume", "cancel") self.can_close = False else: - offset = self._screen.printer.get_stat("gcode_move", "homing_origin") + offset = self._printer.get_stat("gcode_move", "homing_origin") self.zoffset = float(offset[2]) if offset else 0 if self.zoffset != 0: - endstop = (self._screen.printer.config_section_exists("stepper_z") and - not self._screen.printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe")) + endstop = (self._printer.config_section_exists("stepper_z") and + not self._printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe")) if endstop: 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._screen.printer.get_probe(): + if self._printer.get_probe(): 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/move.py b/panels/move.py index 659a33b5..70582486 100644 --- a/panels/move.py +++ b/panels/move.py @@ -82,7 +82,7 @@ class MovePanel(ScreenPanel): grid.attach(self.buttons['z_tilt'], 2, 0, 1, 1) elif self._printer.config_section_exists("quad_gantry_level"): grid.attach(self.buttons['quad_gantry_level'], 2, 0, 1, 1) - elif "delta" in self._screen.printer.get_config_section("printer")['kinematics']: + elif "delta" in self._printer.get_config_section("printer")['kinematics']: grid.attach(self.buttons['motors_off'], 2, 0, 1, 1) else: grid.attach(self.buttons['home_xy'], 2, 0, 1, 1) @@ -164,7 +164,7 @@ class MovePanel(ScreenPanel): return if action != "notify_status_update": return - homed_axes = self._screen.printer.get_stat("toolhead", "homed_axes") + homed_axes = self._printer.get_stat("toolhead", "homed_axes") if homed_axes == "xyz": if "gcode_move" in data and "gcode_position" in data["gcode_move"]: self.labels['pos_x'].set_text(f"X: {data['gcode_move']['gcode_position'][0]:.2f}") diff --git a/panels/power.py b/panels/power.py index 646ac492..f817337b 100644 --- a/panels/power.py +++ b/panels/power.py @@ -30,10 +30,10 @@ class PowerPanel(ScreenPanel): self.content.add(scroll) def activate(self): - devices = self._screen.printer.get_power_devices() + devices = self._printer.get_power_devices() for x in devices: self.devices[x]['switch'].disconnect_by_func(self.on_switch) - self.devices[x]['switch'].set_active(self._screen.printer.get_power_device_status(x) == "on") + self.devices[x]['switch'].set_active(self._printer.get_power_device_status(x) == "on") self.devices[x]['switch'].connect("notify::active", self.on_switch, x) @@ -49,7 +49,7 @@ class PowerPanel(ScreenPanel): switch = Gtk.Switch() switch.set_hexpand(False) - switch.set_active(self._screen.printer.get_power_device_status(device) == "on") + switch.set_active(self._printer.get_power_device_status(device) == "on") switch.connect("notify::active", self.on_switch, device) switch.set_property("width-request", round(self._gtk.font_size * 7)) switch.set_property("height-request", round(self._gtk.font_size * 3.5)) @@ -77,7 +77,7 @@ class PowerPanel(ScreenPanel): self.labels['devices'].show_all() def load_power_devices(self): - devices = self._screen.printer.get_power_devices() + devices = self._printer.get_power_devices() for x in devices: self.add_device(x) diff --git a/panels/splash_screen.py b/panels/splash_screen.py index 043ced35..297cd0fa 100644 --- a/panels/splash_screen.py +++ b/panels/splash_screen.py @@ -103,13 +103,13 @@ class SplashScreenPanel(ScreenPanel): def check_power_status(self): if 'power' in self.labels: - devices = self._screen.printer.get_power_devices() + devices = self._printer.get_power_devices() if devices is not None: for device in devices: - if self._screen.printer.get_power_device_status(device) == "off": + if self._printer.get_power_device_status(device) == "off": self.labels['power'].set_sensitive(True) break - elif self._screen.printer.get_power_device_status(device) == "on": + elif self._printer.get_power_device_status(device) == "on": self.labels['power'].set_sensitive(False) def firmware_restart(self, widget): diff --git a/panels/temperature.py b/panels/temperature.py index 7494e866..61ba9b5f 100644 --- a/panels/temperature.py +++ b/panels/temperature.py @@ -43,7 +43,7 @@ class TemperaturePanel(ScreenPanel): self.show_preheat = True selection.extend(self._printer.get_heaters()) else: - current_extruder = self._screen.printer.get_stat("toolhead", "extruder") + current_extruder = self._printer.get_stat("toolhead", "extruder") if current_extruder: selection.append(current_extruder) diff --git a/panels/zcalibrate.py b/panels/zcalibrate.py index 9a642f56..661abbda 100644 --- a/panels/zcalibrate.py +++ b/panels/zcalibrate.py @@ -21,7 +21,7 @@ class ZCalibratePanel(ScreenPanel): def __init__(self, screen, title): super().__init__(screen, title) self.z_offset = None - self.probe = self._screen.printer.get_probe() + self.probe = self._printer.get_probe() if self.probe: self.z_offset = float(self.probe['z_offset']) logging.info(f"Z offset: {self.z_offset}") @@ -51,7 +51,7 @@ class ZCalibratePanel(ScreenPanel): functions = [] pobox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) if self._printer.config_section_exists("stepper_z") \ - and not self._screen.printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"): + and not self._printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"): self._add_button("Endstop", "endstop", pobox) functions.append("endstop") if self.probe: @@ -61,7 +61,7 @@ class ZCalibratePanel(ScreenPanel): # 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._screen.printer.get_config_section("printer")['kinematics']: + if "delta" in self._printer.get_config_section("printer")['kinematics']: if "probe" in functions: self._add_button("Delta Automatic", "delta", pobox) functions.append("delta") @@ -132,7 +132,7 @@ class ZCalibratePanel(ScreenPanel): def start_calibration(self, widget, method): self.labels['popover'].popdown() - if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": + if self._printer.get_stat("toolhead", "homed_axes") != "xyz": self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME) if method == "probe": @@ -166,8 +166,8 @@ class ZCalibratePanel(ScreenPanel): speed = self.probe['speed'] # Use safe_z_home position - if "safe_z_home" in self._screen.printer.get_config_section_list(): - safe_z = self._screen.printer.get_config_section("safe_z_home") + if "safe_z_home" in self._printer.get_config_section_list(): + safe_z = self._printer.get_config_section("safe_z_home") safe_z_xy = safe_z['home_xy_position'] safe_z_xy = [str(i.strip()) for i in safe_z_xy.split(',')] if x_position is None: @@ -188,7 +188,7 @@ class ZCalibratePanel(ScreenPanel): if x_position is not None and y_position is not None: logging.debug(f"Configured probing position X: {x_position} Y: {y_position}") self._screen._ws.klippy.gcode_script(f'G0 X{x_position} Y{y_position} F3000') - elif "delta" in self._screen.printer.get_config_section("printer")['kinematics']: + elif "delta" in self._printer.get_config_section("printer")['kinematics']: logging.info("Detected delta kinematics calibrating at 0,0") self._screen._ws.klippy.gcode_script('G0 X0 Y0 F3000') else: @@ -197,8 +197,8 @@ class ZCalibratePanel(ScreenPanel): def _calculate_position(self): logging.debug("Position not configured, probing the middle of the bed") try: - xmax = float(self._screen.printer.get_config_section("stepper_x")['position_max']) - ymax = float(self._screen.printer.get_config_section("stepper_y")['position_max']) + xmax = float(self._printer.get_config_section("stepper_x")['position_max']) + ymax = float(self._printer.get_config_section("stepper_y")['position_max']) except KeyError: logging.error("Couldn't get max position from stepper_x and stepper_y") return @@ -231,7 +231,7 @@ class ZCalibratePanel(ScreenPanel): self.process_busy(data) return if action == "notify_status_update": - if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz": + if self._printer.get_stat("toolhead", "homed_axes") != "xyz": self.widgets['zposition'].set_text("Z: ?") elif "gcode_move" in data and "gcode_position" in data['gcode_move']: self.update_position(data['gcode_move']['gcode_position'])