From 056831910087a858908f9f5d117ad5c50446e729 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Sun, 5 Apr 2026 09:38:39 -0300 Subject: [PATCH] Revert "feat: Add an option to add the remaining spool weight to the title-bar (#1662)" This reverts commit 0293a63ed305edb2dee2ba59d0258da99e52e766. it will be on a special branch for now, until some more testing --- docs/Configuration.md | 9 +-- ks_includes/config.py | 2 +- ks_includes/printer.py | 11 --- panels/base_panel.py | 170 ++--------------------------------------- screen.py | 1 - styles/base.css | 4 - 6 files changed, 8 insertions(+), 189 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index c9777b6a..10aa870e 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -70,7 +70,7 @@ moonraker_port: 7125 # moonraker_ssl: False # If you're using the route_prefix option in your moonraker config, specify it here. # This can be useful for running multiple printers behind a path-based reverse proxy. -# Most installs will not need this. +# Most installs will not need this. # moonraker_path: printer1 # Moonraker API key if this host is not connecting from a trusted client IP # moonraker_api_key: False @@ -87,17 +87,12 @@ moonraker_port: 7125 # Define what items should be shown in titlebar besides the extruder and bed # the name must be the same as defined in the klipper config # valid options are temperature_sensors or temperature_fans, or heater_generic -# There is a special item named "spool" that depends on Spoolman data provided through Moonraker -# titlebar_items: chamber, MCU, Pi, spool +# titlebar_items: chamber, MCU, Pi # The style of the user defined items in the titlebar # Can be 'full' indicating that the full name is shown, 'short' for the first letter, or None (default) for no name # titlebar_name_type: None -# Low limit for remaining spool weight in the title bar, in grams. -# When the active spool drops below this value, the spool icon and weight turn red. -# spool_low_limit: 20 - # Z probe calibrate position # By default it tries to guess the correct location # it will try using zero reference position, safe_z, mesh midddle, middle of axis length, etc diff --git a/ks_includes/config.py b/ks_includes/config.py index 93c28c13..2bd35d29 100644 --- a/ks_includes/config.py +++ b/ks_includes/config.py @@ -195,7 +195,7 @@ class KlipperScreenConfig: ) numbers = ( 'moonraker_port', 'move_speed_xy', 'move_speed_z', 'screw_rotation', - 'calibrate_x_position', 'calibrate_y_position', 'spool_low_limit', + 'calibrate_x_position', 'calibrate_y_position', ) elif section.startswith('preheat '): strs = ('gcode', '') diff --git a/ks_includes/printer.py b/ks_includes/printer.py index 1ed1b444..b5236764 100644 --- a/ks_includes/printer.py +++ b/ks_includes/printer.py @@ -27,9 +27,6 @@ class Printer: self.cameras = [] self.available_commands = {} self.spoolman = False - self.active_spool_id = None - self.active_spool = None - self.active_spool_checked = False self.temp_devices = self.sensors = None self.system_info = {} self.warnings = [] @@ -51,9 +48,6 @@ class Printer: self.stop_tempstore_updates() self.system_info.clear() self.warnings = [] - self.active_spool_id = None - self.active_spool = None - self.active_spool_checked = False for x in self.config.keys(): # Support for hiding devices by name @@ -426,8 +420,3 @@ class Printer: def enable_spoolman(self): logging.info("Enabling Spoolman") self.spoolman = True - - def set_active_spool(self, spool_id=None, spool=None, checked=True): - self.active_spool_id = spool_id - self.active_spool = spool - self.active_spool_checked = checked diff --git a/panels/base_panel.py b/panels/base_panel.py index a551be8e..705feb11 100644 --- a/panels/base_panel.py +++ b/panels/base_panel.py @@ -1,19 +1,15 @@ # -*- coding: utf-8 -*- import logging -import os -import pathlib import gi gi.require_version("Gtk", "3.0") -from gi.repository import Gio, GLib, Gtk, Pango, GdkPixbuf +from gi.repository import GLib, Gtk, Pango from jinja2 import Environment from datetime import datetime from math import log from ks_includes.screen_panel import ScreenPanel -SPOOL_ID_UNSET = object() - try: import psutil psutil_available = True @@ -32,10 +28,6 @@ class BasePanel(ScreenPanel): self.battery_update = None self.titlebar_items = [] self.titlebar_name_type = None - self.show_spoolman_in_title = False - self.spoolman_low_limit = 20 - self.spoolman_icon_size = self._gtk.img_scale * self.bts * .9 - self.spoolman_icon_alert_pixbuf = None self.current_extruder = None self.last_usage_report = datetime.now() self.usage_report = 0 @@ -112,15 +104,6 @@ class BasePanel(ScreenPanel): for widget in self.control['battery_box']: widget.show() - self.labels['spoolman_icon'] = Gtk.Image() - self.labels['spoolman_weight'] = Gtk.Label() - self.control['spoolman_box'] = Gtk.Box() - self.control['spoolman_box'].set_no_show_all(True) - self.control['spoolman_box'].pack_start(self.labels['spoolman_icon'], False, False, 7) - self.control['spoolman_box'].pack_start(self.labels['spoolman_weight'], False, False, 0) - self.labels['spoolman_icon'].show() - self.labels['spoolman_weight'].show() - self.titlebar = Gtk.Box(spacing=5, valign=Gtk.Align.CENTER) self.titlebar.get_style_context().add_class("title_bar") self.titlebar.add(self.control['temp_box']) @@ -173,49 +156,10 @@ class BasePanel(ScreenPanel): self.battery_icons = self.load_battery_icons() self.battery_percentage() - self.update_spoolman_alert_visuals(False) - - def get_spoolman_icon_pixbuf(self, color): - klipperscreendir = pathlib.Path(__file__).parent.resolve().parent - icon_path = os.path.join(klipperscreendir, "styles", self._screen.theme, "images", "spool.svg") - if not os.path.isfile(icon_path): - icon_path = os.path.join(klipperscreendir, "styles", "spool.svg") - try: - svg = pathlib.Path(icon_path).read_text(encoding="utf-8") - svg = svg.replace("var(--filament-color)", f"#{color}") - stream = Gio.MemoryInputStream.new_from_data(svg.encode(), None) - pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( - stream, - -1, - self.spoolman_icon_size, - True, - None, - ) - stream.close_async(2) - return pixbuf - except Exception as e: - logging.error(f"Couldn't load spoolman icon: {e}") - return self._gtk.PixbufFromIcon("spool", self.spoolman_icon_size, self.spoolman_icon_size) - - def get_active_spoolman_color(self): - default_color = "000000" - if ( - self._printer is None - or not self._printer.active_spool - or "filament" not in self._printer.active_spool - or not self._printer.active_spool["filament"] - ): - return default_color - filament = self._printer.active_spool["filament"] - color = filament.get("color_hex") - if isinstance(color, str): - return color.strip().lstrip("#") or default_color - return default_color def show_heaters(self, show=True): for child in self.control['temp_box'].get_children(): self.control['temp_box'].remove(child) - self.control['spoolman_box'].hide() if self._printer is None or not show: return try: @@ -249,17 +193,13 @@ class BasePanel(ScreenPanel): elif device.startswith("heater"): self.control['temp_box'].add(self.labels[f"{device}_box"]) n += 1 - for item in self.titlebar_items: + for device in devices: # Users can fill the bar if they want if n >= nlimit + 1: break - if item == "spool" and self._printer.spoolman: - self.control['temp_box'].add(self.control['spoolman_box']) - n += 1 - continue - for device in devices: - name = device.split()[1] if len(device.split()) > 1 else device - if name == item and self.labels[f"{device}_box"].get_parent() is None: + name = device.split()[1] if len(device.split()) > 1 else device + for item in self.titlebar_items: + if name == item: self.control['temp_box'].add(self.labels[f"{device}_box"]) n += 1 break @@ -302,7 +242,6 @@ class BasePanel(ScreenPanel): self.control['shutdown'].set_visible(not printing) self.show_shortcut(connected and printer_select) self.show_heaters(connected and printer_select) - self.refresh_spoolman_weight(connected and printer_select) self.show_printer_select(len(self._config.get_printers()) > 1) for control in ('back', 'home'): self.set_control_sensitive(len(self._screen._cur_panels) > 1, control=control) @@ -310,83 +249,6 @@ class BasePanel(ScreenPanel): self.set_title(panel.title) self.content.add(panel.content) - def update_spoolman_alert_visuals(self, alert): - self.labels['spoolman_icon'].set_from_pixbuf( - self.get_spoolman_icon_pixbuf(self.get_active_spoolman_color()) - ) - if alert: - self.labels['spoolman_weight'].get_style_context().add_class("spoolman_low") - else: - self.labels['spoolman_weight'].get_style_context().remove_class("spoolman_low") - - def update_spoolman_weight_label(self): - if ( - self._printer is None - or not self.show_spoolman_in_title - ): - self.update_spoolman_alert_visuals(False) - self.control['spoolman_box'].hide() - return - if ( - not self._printer.spoolman - or not self._printer.active_spool - or "remaining_weight" not in self._printer.active_spool - or self._printer.active_spool["remaining_weight"] is None - ): - self.update_spoolman_alert_visuals(False) - self.labels['spoolman_weight'].set_label("?") - self.control['spoolman_box'].show() - return - remaining_weight = self._printer.active_spool["remaining_weight"] - self.labels['spoolman_weight'].set_label(f'{round(remaining_weight):.0f} g') - self.update_spoolman_alert_visuals(remaining_weight < self.spoolman_low_limit) - self.control['spoolman_box'].show() - - def refresh_spoolman_weight(self, show=True, spool_id=SPOOL_ID_UNSET): - if self._printer is None or not self.show_spoolman_in_title: - self.update_spoolman_alert_visuals(False) - self.control['spoolman_box'].hide() - return - if not show: - self.update_spoolman_alert_visuals(False) - self.control['spoolman_box'].hide() - return - if not self._printer.spoolman: - self._printer.set_active_spool(checked=False) - self.update_spoolman_weight_label() - return - if spool_id is SPOOL_ID_UNSET and self._printer.active_spool_checked: - self.update_spoolman_weight_label() - return - if spool_id is SPOOL_ID_UNSET: - result = self._screen.apiclient.send_request("server/spoolman/spool_id") - if result is False: - logging.error("Error trying to fetch active spool id") - self._printer.set_active_spool(checked=False) - self.update_spoolman_weight_label() - return - if "spool_id" not in result or not result["spool_id"]: - self._printer.set_active_spool() - self.update_spoolman_weight_label() - return - spool_id = result["spool_id"] - elif not spool_id: - self._printer.set_active_spool() - self.update_spoolman_weight_label() - return - - spool = self._screen.apiclient.post_request("server/spoolman/proxy", json={ - "request_method": "GET", - "path": f"/v1/spool/{spool_id}", - }) - if not spool or "result" not in spool: - logging.error("Error trying to fetch active spool information") - self._printer.set_active_spool(spool_id=spool_id, checked=False) - self.update_spoolman_weight_label() - return - self._printer.set_active_spool(spool_id=spool_id, spool=spool["result"]) - self.update_spoolman_weight_label() - def back(self, widget=None): if self.current_panel is None: return @@ -397,19 +259,6 @@ class BasePanel(ScreenPanel): self._screen._menu_go_back() def process_update(self, action, data): - if action == "notify_active_spool_set": - has_spool_id = isinstance(data, dict) and "spool_id" in data - if not has_spool_id and self._printer is not None: - # Force a refetch when the event arrives without an explicit spool_id - # so the titlebar doesn't keep showing a stale cached spool. - self._printer.set_active_spool(checked=False) - spool_id = data.get("spool_id") if has_spool_id else SPOOL_ID_UNSET - self.refresh_spoolman_weight( - self._printer is not None - and self._printer.state not in {'disconnected', 'startup', 'shutdown', 'error'}, - spool_id=spool_id - ) - return if action == "notify_proc_stat_update": cpu = data["system_cpu_usage"]["cpu"] memory = (data["system_memory"]["used"] / data["system_memory"]["total"]) * 100 @@ -579,15 +428,6 @@ class BasePanel(ScreenPanel): logging.info(f"Titlebar name type: {self.titlebar_name_type} items: {self.titlebar_items}") else: self.titlebar_items = [] - self.show_spoolman_in_title = "spool" in self.titlebar_items - self.spoolman_low_limit = self.ks_printer_cfg.getfloat("spool_low_limit", fallback=20) - else: - self.titlebar_items = [] - self.show_spoolman_in_title = False - self.spoolman_low_limit = 20 - self.refresh_spoolman_weight( - self._printer is not None and self._printer.state not in {'disconnected', 'startup', 'shutdown', 'error'} - ) def show_update_dialog(self): if self.update_dialog is not None: diff --git a/screen.py b/screen.py index 9a3683a9..1ccc5d9e 100755 --- a/screen.py +++ b/screen.py @@ -1108,7 +1108,6 @@ class KlipperScreen(Gtk.Window): self.printer.configure_cameras(cameras['webcams']) if "spoolman" in self.server_info["components"]: self.printer.enable_spoolman() - self.base_panel.refresh_spoolman_weight() def init_klipper(self): if self.reinit_count > self.max_retries or 'printer_select' in self._cur_panels: diff --git a/styles/base.css b/styles/base.css index fdd82a31..084e20b6 100644 --- a/styles/base.css +++ b/styles/base.css @@ -290,10 +290,6 @@ trough { min-height: 2em; } -.spoolman_low { - color: @warning; -} - .content { margin: 0 .1em; }