From f52b52f76a18fcc48627caf517f60dcd99864561 Mon Sep 17 00:00:00 2001 From: alfrix Date: Sun, 4 Dec 2022 12:03:29 -0300 Subject: [PATCH] main and temp: less tempstore dependency --- ks_includes/printer.py | 11 +++++------ ks_includes/widgets/graph.py | 1 - panels/main_menu.py | 6 +++--- panels/temperature.py | 6 ++++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ks_includes/printer.py b/ks_includes/printer.py index b8fd09cc..5e57cf79 100644 --- a/ks_includes/printer.py +++ b/ks_includes/printer.py @@ -72,10 +72,9 @@ class Printer: or x.startswith('heater_generic ') \ or x.startswith('temperature_sensor ') \ or x.startswith('temperature_fan '): - self.devices[x] = { - "temperature": 0, - "target": 0 - } + self.devices[x] = {"temperature": 0} + if not x.startswith('temperature_sensor '): + self.devices[x]["target"] = 0 # Support for hiding devices by name name = x.split()[1] if len(x.split()) > 1 else x if not name.startswith("_"): @@ -282,8 +281,8 @@ class Printer: if self.tempstore is not None: return list(self.tempstore) - def get_temp_store_device_has_target(self, device): - return device in self.tempstore and "targets" in self.tempstore[device] + def device_has_target(self, device): + return "target" in self.devices[device] or (device in self.tempstore and "targets" in self.tempstore[device]) def get_temp_store(self, device, section=False, results=0): if device not in self.tempstore: diff --git a/ks_includes/widgets/graph.py b/ks_includes/widgets/graph.py index c99a0a8b..eda5eefb 100644 --- a/ks_includes/widgets/graph.py +++ b/ks_includes/widgets/graph.py @@ -34,7 +34,6 @@ class HeaterGraph(Gtk.DrawingArea): "fill": fill, "rgb": rgb }}) - self.max_length = max(self.max_length, len(self.printer.get_temp_store(name, ev_type))) @staticmethod def event_cb(da, ev): diff --git a/panels/main_menu.py b/panels/main_menu.py index a214c3b9..bfe839d4 100644 --- a/panels/main_menu.py +++ b/panels/main_menu.py @@ -50,7 +50,7 @@ class MainPanel(MenuPanel): self.layout.show_all() def update_graph_visibility(self): - if self.left_panel is None: + if self.left_panel is None or not self._printer.get_temp_store_devices(): return count = 0 for device in self.devices: @@ -131,7 +131,7 @@ class MainPanel(MenuPanel): rgb = self._gtk.get_temp_color(dev_type) - can_target = self._printer.get_temp_store_device_has_target(device) + can_target = self._printer.device_has_target(device) self.labels['da'].add_object(device, "temperatures", rgb, False, True) if can_target: self.labels['da'].add_object(device, "targets", rgb, True, False) @@ -224,7 +224,7 @@ class MainPanel(MenuPanel): self.left_panel = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) self.left_panel.add(scroll) - for d in self._printer.get_temp_store_devices(): + for d in (self._printer.get_tools() + self._printer.get_heaters()): self.add_device(d) return self.left_panel diff --git a/panels/temperature.py b/panels/temperature.py index b2a12fdc..aa761669 100644 --- a/panels/temperature.py +++ b/panels/temperature.py @@ -175,6 +175,8 @@ class TemperaturePanel(ScreenPanel): logging.info(f"Setting {heater} to {target}") def update_graph_visibility(self): + if not self._printer.get_temp_store_devices(): + return count = 0 for device in self.devices: visible = self._config.get_config().getboolean(f"graph {self._screen.connected_printer}", @@ -335,7 +337,7 @@ class TemperaturePanel(ScreenPanel): else: name.get_style_context().add_class("graph_label_hidden") - can_target = self._printer.get_temp_store_device_has_target(device) + can_target = self._printer.device_has_target(device) self.labels['da'].add_object(device, "temperatures", rgb, False, True) if can_target: self.labels['da'].add_object(device, "targets", rgb, True, False) @@ -455,7 +457,7 @@ class TemperaturePanel(ScreenPanel): popover.connect('closed', self.popover_closed) self.labels['popover'] = popover - for d in self._printer.get_temp_store_devices(): + for d in (self._printer.get_tools() + self._printer.get_heaters()): self.add_device(d) return self.left_panel