From ac6f34acb0645119f122b394c76c9ab211fd8161 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Tue, 4 Jun 2024 14:15:14 -0300 Subject: [PATCH] extrude: move firmware retraction into the panel, add pressure advance control closes #724 --- config/main_menu.conf | 6 - config/print_menu.conf | 6 - ks_includes/locales/KlipperScreen.pot | 3 + .../locales/cs/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/da/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/de/LC_MESSAGES/KlipperScreen.po | 3 + .../de_formal/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/es/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/et/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/fr/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/he/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/hu/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/it/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/jp/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/ko/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/lt/LC_MESSAGES/KlipperScreen.po | 4 + .../locales/nl/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/pl/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/pt/LC_MESSAGES/KlipperScreen.po | 3 + .../pt_BR/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/ru/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/sl/LC_MESSAGES/KlipperScreen.po | 4 + .../locales/sv/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/tr/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/uk/LC_MESSAGES/KlipperScreen.po | 3 + .../locales/vi/LC_MESSAGES/KlipperScreen.po | 3 + .../zh_CN/LC_MESSAGES/KlipperScreen.po | 3 + .../zh_TW/LC_MESSAGES/KlipperScreen.po | 3 + panels/extrude.py | 31 +++- panels/pressure_advance.py | 162 ++++++++++++++++++ 30 files changed, 267 insertions(+), 18 deletions(-) create mode 100644 panels/pressure_advance.py diff --git a/config/main_menu.conf b/config/main_menu.conf index 3f956ef8..3ac5dff7 100644 --- a/config/main_menu.conf +++ b/config/main_menu.conf @@ -60,12 +60,6 @@ name: {{ gettext('Limits') }} icon: fine-tune panel: limits -[menu __main more retraction] -name: {{ gettext('Retraction') }} -icon: retract -panel: retraction -enable: {{ 'firmware_retraction' in printer.config_sections }} - [menu __main more fan] name: {{ gettext('Fan') }} icon: fan diff --git a/config/print_menu.conf b/config/print_menu.conf index a6d68c6a..42baf82d 100644 --- a/config/print_menu.conf +++ b/config/print_menu.conf @@ -69,12 +69,6 @@ name: {{ gettext('Network') }} icon: network panel: network -[menu __print retraction] -name: {{ gettext('Retraction') }} -icon: retract -panel: retraction -enable: {{ 'firmware_retraction' in printer.config_sections }} - [menu __print settings] name: KlipperScreen icon: settings diff --git a/ks_includes/locales/KlipperScreen.pot b/ks_includes/locales/KlipperScreen.pot index d24de1e9..7472cb2f 100644 --- a/ks_includes/locales/KlipperScreen.pot +++ b/ks_includes/locales/KlipperScreen.pot @@ -658,6 +658,9 @@ msgstr "" msgid "Pressure Advance:" msgstr "" +msgid "Pressure Advance" +msgstr "" + msgid "Print" msgstr "" diff --git a/ks_includes/locales/cs/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/cs/LC_MESSAGES/KlipperScreen.po index c4efe084..2fa7e68e 100644 --- a/ks_includes/locales/cs/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/cs/LC_MESSAGES/KlipperScreen.po @@ -661,6 +661,9 @@ msgstr "Zapni tiskárnu" msgid "Pressure Advance:" msgstr "Pressure Advance:" +msgid "Pressure Advance" +msgstr "Pressure Advance" + msgid "Print" msgstr "Tisk" diff --git a/ks_includes/locales/da/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/da/LC_MESSAGES/KlipperScreen.po index 1b2e0936..e5679625 100644 --- a/ks_includes/locales/da/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/da/LC_MESSAGES/KlipperScreen.po @@ -656,6 +656,9 @@ msgstr "Tænd printer" msgid "Pressure Advance:" msgstr "Pressure Advance:" +msgid "Pressure Advance" +msgstr "Pressure Advance" + msgid "Print" msgstr "Print" diff --git a/ks_includes/locales/de/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/de/LC_MESSAGES/KlipperScreen.po index 58e300e9..64b43c9a 100644 --- a/ks_includes/locales/de/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/de/LC_MESSAGES/KlipperScreen.po @@ -661,6 +661,9 @@ msgstr "Drucker einschalten" msgid "Pressure Advance:" msgstr "Druckvorlauf:" +msgid "Pressure Advance" +msgstr "Druckvorlauf" + msgid "Print" msgstr "Druck" diff --git a/ks_includes/locales/de_formal/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/de_formal/LC_MESSAGES/KlipperScreen.po index c083d3d4..1d6d543e 100644 --- a/ks_includes/locales/de_formal/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/de_formal/LC_MESSAGES/KlipperScreen.po @@ -661,6 +661,9 @@ msgstr "Drucker einschalten" msgid "Pressure Advance:" msgstr "Druckvorlauf:" +msgid "Pressure Advance" +msgstr "Druckvorlauf" + msgid "Print" msgstr "Druck" diff --git a/ks_includes/locales/es/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/es/LC_MESSAGES/KlipperScreen.po index 4fc2b67a..67427989 100644 --- a/ks_includes/locales/es/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/es/LC_MESSAGES/KlipperScreen.po @@ -662,6 +662,9 @@ msgstr "Encender Impresora" msgid "Pressure Advance:" msgstr "Avance de presión:" +msgid "Pressure Advance" +msgstr "Avance de presión" + msgid "Print" msgstr "Imprimir" diff --git a/ks_includes/locales/et/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/et/LC_MESSAGES/KlipperScreen.po index 6022c115..9ca6ed14 100644 --- a/ks_includes/locales/et/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/et/LC_MESSAGES/KlipperScreen.po @@ -656,6 +656,9 @@ msgstr "Printeri sisselülitamine" msgid "Pressure Advance:" msgstr "Surveelisus:" +msgid "Pressure Advance" +msgstr "Surveelisus" + msgid "Print" msgstr "Prindi" diff --git a/ks_includes/locales/fr/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/fr/LC_MESSAGES/KlipperScreen.po index bb23e6c0..34aff1a8 100644 --- a/ks_includes/locales/fr/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/fr/LC_MESSAGES/KlipperScreen.po @@ -662,6 +662,9 @@ msgstr "Allumer l'imprimante" msgid "Pressure Advance:" msgstr "Avance de pression:" +msgid "Pressure Advance" +msgstr "Avance de pression" + msgid "Print" msgstr "Imprimer" diff --git a/ks_includes/locales/he/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/he/LC_MESSAGES/KlipperScreen.po index 0d05fc03..94b955f8 100644 --- a/ks_includes/locales/he/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/he/LC_MESSAGES/KlipperScreen.po @@ -663,6 +663,9 @@ msgstr "הפעל מדפסת" msgid "Pressure Advance:" msgstr "פרשר אדוונס" +msgid "Pressure Advance" +msgstr "פרשר אדוונס" + msgid "Print" msgstr "הדפסה" diff --git a/ks_includes/locales/hu/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/hu/LC_MESSAGES/KlipperScreen.po index d51b734c..b5526938 100644 --- a/ks_includes/locales/hu/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/hu/LC_MESSAGES/KlipperScreen.po @@ -655,6 +655,9 @@ msgstr "Nyomtató bekapcsolása" msgid "Pressure Advance:" msgstr "Nyomás előtolás:" +msgid "Pressure Advance" +msgstr "Nyomás előtolás" + msgid "Print" msgstr "Nyomtatás" diff --git a/ks_includes/locales/it/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/it/LC_MESSAGES/KlipperScreen.po index 5aae10d7..fb5e3857 100644 --- a/ks_includes/locales/it/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/it/LC_MESSAGES/KlipperScreen.po @@ -657,6 +657,9 @@ msgstr "Accendi la stampante" msgid "Pressure Advance:" msgstr "Pressure Advance:" +msgid "Pressure Advance" +msgstr "Pressure Advance" + msgid "Print" msgstr "Stampa" diff --git a/ks_includes/locales/jp/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/jp/LC_MESSAGES/KlipperScreen.po index bcc9d548..61c1c189 100644 --- a/ks_includes/locales/jp/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/jp/LC_MESSAGES/KlipperScreen.po @@ -653,6 +653,9 @@ msgstr "プリンター電源" msgid "Pressure Advance:" msgstr "" +msgid "Pressure Advance" +msgstr "" + msgid "Print" msgstr "印刷" diff --git a/ks_includes/locales/ko/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/ko/LC_MESSAGES/KlipperScreen.po index ac2c4cd2..48183f75 100644 --- a/ks_includes/locales/ko/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/ko/LC_MESSAGES/KlipperScreen.po @@ -654,6 +654,9 @@ msgstr "프린터 전원 켜기" msgid "Pressure Advance:" msgstr "모서리 압출 제어 수치:" +msgid "Pressure Advance" +msgstr "모서리 압출 제어 수치" + msgid "Print" msgstr "출력" diff --git a/ks_includes/locales/lt/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/lt/LC_MESSAGES/KlipperScreen.po index 723a6d21..1c665b8b 100644 --- a/ks_includes/locales/lt/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/lt/LC_MESSAGES/KlipperScreen.po @@ -664,6 +664,10 @@ msgstr "Išjungti spausdintuvą" msgid "Pressure Advance:" msgstr "Slėgio kontrolė:" + +msgid "Pressure Advance" +msgstr "Slėgio kontrolė" + msgid "Print" msgstr "Spausdinti" diff --git a/ks_includes/locales/nl/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/nl/LC_MESSAGES/KlipperScreen.po index 9782994e..3ac20a77 100644 --- a/ks_includes/locales/nl/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/nl/LC_MESSAGES/KlipperScreen.po @@ -661,6 +661,9 @@ msgstr "Printer Aanzetten" msgid "Pressure Advance:" msgstr "Pressure Advance:" +msgid "Pressure Advance" +msgstr "Pressure Advance" + msgid "Print" msgstr "Print" diff --git a/ks_includes/locales/pl/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/pl/LC_MESSAGES/KlipperScreen.po index 885d0ced..9a6603a2 100644 --- a/ks_includes/locales/pl/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/pl/LC_MESSAGES/KlipperScreen.po @@ -659,6 +659,9 @@ msgstr "Zasilanie włączone" msgid "Pressure Advance:" msgstr "Pressure Advance:" +msgid "Pressure Advance" +msgstr "Pressure Advance" + msgid "Print" msgstr "Drukuj" diff --git a/ks_includes/locales/pt/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/pt/LC_MESSAGES/KlipperScreen.po index 9da38216..d45b9f59 100644 --- a/ks_includes/locales/pt/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/pt/LC_MESSAGES/KlipperScreen.po @@ -662,6 +662,9 @@ msgstr "Ligar a impressora" msgid "Pressure Advance:" msgstr "Avanço de Pressão:" +msgid "Pressure Advance" +msgstr "Avanço de Pressão" + msgid "Print" msgstr "Imprimir" diff --git a/ks_includes/locales/pt_BR/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/pt_BR/LC_MESSAGES/KlipperScreen.po index bff55907..325963da 100644 --- a/ks_includes/locales/pt_BR/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/pt_BR/LC_MESSAGES/KlipperScreen.po @@ -661,6 +661,9 @@ msgstr "Ligar Impressora" msgid "Pressure Advance:" msgstr "Pressão de Avanço (Pressure Advance):" +msgid "Pressure Advance" +msgstr "Pressão de Avanço" + msgid "Print" msgstr "Imprimir" diff --git a/ks_includes/locales/ru/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/ru/LC_MESSAGES/KlipperScreen.po index c56403c0..8b5914ac 100644 --- a/ks_includes/locales/ru/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/ru/LC_MESSAGES/KlipperScreen.po @@ -662,6 +662,9 @@ msgstr "Включить принтер" msgid "Pressure Advance:" msgstr "Повышение давления:" +msgid "Pressure Advance" +msgstr "Повышение давления" + msgid "Print" msgstr "Печать" diff --git a/ks_includes/locales/sl/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/sl/LC_MESSAGES/KlipperScreen.po index 81c9ea5f..0b33abc0 100644 --- a/ks_includes/locales/sl/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/sl/LC_MESSAGES/KlipperScreen.po @@ -664,6 +664,10 @@ msgstr "Vklopite tiskalnik" msgid "Pressure Advance:" msgstr "Pressure Advance:" + +msgid "Pressure Advance" +msgstr "Pressure Advance" + msgid "Print" msgstr "Natisni" diff --git a/ks_includes/locales/sv/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/sv/LC_MESSAGES/KlipperScreen.po index 3d2a67d8..97dc8891 100644 --- a/ks_includes/locales/sv/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/sv/LC_MESSAGES/KlipperScreen.po @@ -660,6 +660,9 @@ msgstr "Slå på skrivaren" msgid "Pressure Advance:" msgstr "Tryckförflyttning:" +msgid "Pressure Advance" +msgstr "Tryckförflyttning" + msgid "Print" msgstr "Skriv ut" diff --git a/ks_includes/locales/tr/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/tr/LC_MESSAGES/KlipperScreen.po index ea2a760b..2ba37634 100644 --- a/ks_includes/locales/tr/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/tr/LC_MESSAGES/KlipperScreen.po @@ -659,6 +659,9 @@ msgstr "Yazıcıya Güç Ver (aç)" msgid "Pressure Advance:" msgstr "Akış Dengeleme:" +msgid "Pressure Advance" +msgstr "Akış Dengeleme" + msgid "Print" msgstr "Yazdır" diff --git a/ks_includes/locales/uk/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/uk/LC_MESSAGES/KlipperScreen.po index 915a9155..fcad84bc 100644 --- a/ks_includes/locales/uk/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/uk/LC_MESSAGES/KlipperScreen.po @@ -662,6 +662,9 @@ msgstr "Увімкнути принтер" msgid "Pressure Advance:" msgstr "Випередження тиску:" +msgid "Pressure Advance" +msgstr "Випередження тиску" + msgid "Print" msgstr "Друк" diff --git a/ks_includes/locales/vi/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/vi/LC_MESSAGES/KlipperScreen.po index a098507d..c49b3051 100644 --- a/ks_includes/locales/vi/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/vi/LC_MESSAGES/KlipperScreen.po @@ -653,6 +653,9 @@ msgstr "Bật nguồn máy in" msgid "Pressure Advance:" msgstr "Nâng áp suất:" +msgid "Pressure Advance" +msgstr "Nâng áp suất" + msgid "Print" msgstr "In" diff --git a/ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.po index b59ad547..5d8d88b5 100644 --- a/ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.po @@ -658,6 +658,9 @@ msgstr "打印机通电" msgid "Pressure Advance:" msgstr "压力提前:" +msgid "Pressure Advance" +msgstr "压力提前" + msgid "Print" msgstr "打印" diff --git a/ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.po b/ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.po index a714ffe8..28fb03e1 100644 --- a/ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.po +++ b/ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.po @@ -658,6 +658,9 @@ msgstr "啟動列印機" msgid "Pressure Advance:" msgstr "壓力推進:" +msgid "Pressure Advance" +msgstr "壓力推進" + msgid "Print" msgstr "列印" diff --git a/panels/extrude.py b/panels/extrude.py index 255a851e..a87c32e7 100644 --- a/panels/extrude.py +++ b/panels/extrude.py @@ -42,6 +42,8 @@ class Panel(ScreenPanel): 'retract': self._gtk.Button("retract", _("Retract"), "color1"), 'temperature': self._gtk.Button("heat-up", _("Temperature"), "color4"), 'spoolman': self._gtk.Button("spoolman", "Spoolman", "color3"), + 'pressure': self._gtk.Button("settings", _("Pressure Advance"), "color2"), + 'retraction': self._gtk.Button("settings", _("Retraction"), "color1") } self.buttons['extrude'].connect("clicked", self.extrude, "+") self.buttons['load'].connect("clicked", self.load_unload, "+") @@ -53,6 +55,12 @@ class Panel(ScreenPanel): self.buttons['spoolman'].connect("clicked", self.menu_item_clicked, { "panel": "spoolman" }) + self.buttons['pressure'].connect("clicked", self.menu_item_clicked, { + "panel": "pressure_advance" + }) + self.buttons['retraction'].connect("clicked", self.menu_item_clicked, { + "panel": "retraction" + }) xbox = Gtk.Box(homogeneous=True) limit = 4 @@ -67,7 +75,7 @@ class Panel(ScreenPanel): self.labels[extruder].connect("clicked", self.change_extruder, extruder) if extruder == self.current_extruder: self.labels[extruder].get_style_context().add_class("button_active") - if self._printer.extrudercount <= limit: + if self._printer.extrudercount < limit: xbox.add(self.labels[extruder]) i += 1 else: @@ -76,13 +84,19 @@ class Panel(ScreenPanel): self.labels['extruders'] = AutoGrid(extruder_buttons, vertical=self._screen.vertical_mode) self.labels['extruders_menu'] = self._gtk.ScrolledWindow() self.labels['extruders_menu'].add(self.labels['extruders']) - if self._printer.extrudercount > limit: + if self._printer.extrudercount >= limit: changer = self._gtk.Button("toolchanger") changer.connect("clicked", self.load_menu, 'extruders', _('Extruders')) xbox.add(changer) self.labels["current_extruder"] = self._gtk.Button("extruder", "") xbox.add(self.labels["current_extruder"]) self.labels["current_extruder"].connect("clicked", self.load_menu, 'extruders', _('Extruders')) + if not self._screen.vertical_mode: + xbox.add(self.buttons['pressure']) + i += 1 + if self._printer.get_config_section("firmware_retraction") and not self._screen.vertical_mode: + xbox.add(self.buttons['retraction']) + i += 1 if i < limit: xbox.add(self.buttons['temperature']) if i < (limit - 1) and self._printer.spoolman: @@ -145,9 +159,14 @@ class Panel(ScreenPanel): 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) + settings_box = Gtk.Box(homogeneous=True) + settings_box.add(self.buttons['pressure']) + if self._printer.get_config_section("firmware_retraction"): + settings_box.add(self.buttons['retraction']) + grid.attach(settings_box, 0, 3, 4, 1) + grid.attach(distbox, 0, 4, 4, 1) + grid.attach(speedbox, 0, 5, 4, 1) + grid.attach(sensors, 0, 6, 4, 1) else: grid.attach(self.buttons['extrude'], 0, 2, 1, 1) grid.attach(self.buttons['load'], 1, 2, 1, 1) @@ -163,7 +182,7 @@ class Panel(ScreenPanel): def enable_buttons(self, enable): for button in self.buttons: - if button in ("temperature", "spoolman"): + if button in ("pressure", "retraction", "spoolman", "temperature"): continue self.buttons[button].set_sensitive(enable) diff --git a/panels/pressure_advance.py b/panels/pressure_advance.py new file mode 100644 index 00000000..a478d9df --- /dev/null +++ b/panels/pressure_advance.py @@ -0,0 +1,162 @@ +import logging +import gi + +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk, Pango +from ks_includes.screen_panel import ScreenPanel + +# TODO multi-extruder support + + +class Panel(ScreenPanel): + def __init__(self, screen, title): + title = title or _("Pressure advance") + super().__init__(screen, title) + self.current_extruder = "extruder" + self.current_extruder_label = Gtk.Label( + label=_("Current") + f": {self.current_extruder}" + ) + self.grid = Gtk.Grid() + self.grid.attach(self.current_extruder_label, 0, 0, 1, 1) + self.values = {} + self.list = {} + self.options = [ + { + "name": _("Pressure Advance"), + "units": _("mm"), + "option": "pressure_advance", + "value": 0, + "digits": 2, + "maxval": 1, + }, + { + "name": _("Smooth time"), + "units": _("s"), + "option": "smooth_time", + "value": 0.04, + "digits": 3, + "maxval": 0.200, + }, + ] + + for opt in self.options: + self.add_option(opt) + + scroll = self._gtk.ScrolledWindow() + scroll.add(self.grid) + + self.content.add(scroll) + self.content.show_all() + + def add_option(self, option_data): + option = option_data["option"] + optname = option_data["name"] + units = option_data["units"] + value = option_data["value"] + digits = option_data["digits"] + maxval = option_data["maxval"] + + logging.info(f"Adding option: {option}") + + name_label = Gtk.Label() + name_label.set_markup(f"{optname} ({units})") + + adjustment = Gtk.Adjustment( + value, + 0, + maxval, + 0.05 if option.startswith("pressure") else 0.005, + 0.1 if option.startswith("pressure") else 0.01, + 0, + ) + + scale = Gtk.Scale( + adjustment=adjustment, + digits=digits, + hexpand=True, + has_origin=True, + ) + scale.get_style_context().add_class("option_slider") + scale.connect("button-release-event", self.set_opt_value, option) + + reset_button = self._gtk.Button("refresh", style="color1") + reset_button.connect("clicked", self.reset_value, option) + reset_button.set_hexpand(False) + + item = Gtk.Grid() + item.attach(name_label, 0, 0, 2, 1) + item.attach(scale, 0, 1, 1, 1) + item.attach(reset_button, 1, 1, 1, 1) + + self.list[option] = { + "row": item, + "scale": scale, + "adjustment": adjustment, + } + + pos = sorted(self.list).index(option) + 1 + self.grid.attach(self.list[option]["row"], 0, pos, 1, 1) + self.grid.show_all() + + def reset_value(self, widget, option): + for opt in self.options: + if opt["option"] == option: + self.update_option(option, opt["value"]) + self.set_opt_value(None, None, option) + + def set_opt_value(self, widget, event, opt): + value = self.list[opt]["scale"].get_value() + if opt == "pressure_advance": + self._screen._ws.klippy.gcode_script( + f"SET_PRESSURE_ADVANCE EXTRUDER={self.current_extruder} ADVANCE={value}" + ) + if opt == "smooth_time": + self._screen._ws.klippy.gcode_script( + f"SET_PRESSURE_ADVANCE EXTRUDER={self.current_extruder} SMOOTH_TIME={value}" + ) + + def process_update(self, action, data): + if action != "notify_status_update": + return + if ( + "toolhead" in data + and "extruder" in data["toolhead"] + and data["toolhead"]["extruder"] + ): + self.current_extruder = data["toolhead"]["extruder"] + logging.debug(f"Changing to {self.current_extruder}") + self.current_extruder_label.set_label( + _("Current") + f": {self.current_extruder}" + ) + for opt in self.list: + if opt in self._printer.data[self.current_extruder]: + self.update_option( + opt, self._printer.data[self.current_extruder][opt] + ) + if self.current_extruder in data: + for opt in self.list: + if opt in data[self.current_extruder]: + self.update_option(opt, data[self.current_extruder][opt]) + + def update_option(self, option, value): + if option not in self.list: + return + + if self.list[option]["scale"].has_grab(): + return + + self.values[option] = float(value) + + # Infinite scale + for opt in self.options: + if opt["option"] == option and not option.startswith("smooth_time"): + if self.values[option] > opt["maxval"] * 0.75: + self.list[option]["adjustment"].set_upper(self.values[option] * 1.5) + else: + self.list[option]["adjustment"].set_upper(opt["maxval"]) + break + self.list[option]["scale"].set_value(self.values[option]) + self.list[option]["scale"].disconnect_by_func(self.set_opt_value) + self.list[option]["scale"].connect( + "button-release-event", self.set_opt_value, option + )