macros: hide the panel if there are no elegible macros
This commit is contained in:
parent
e80ef7eff5
commit
e01b6e5f26
@ -201,7 +201,15 @@ class Printer:
|
||||
return output_pins
|
||||
|
||||
def get_gcode_macros(self):
|
||||
return self.get_config_section_list("gcode_macro ")
|
||||
macros = []
|
||||
for macro in self.get_config_section_list("gcode_macro "):
|
||||
macro = macro[12:].strip()
|
||||
if macro.startswith("_") or macro.upper() in ('LOAD_FILAMENT', 'UNLOAD_FILAMENT'):
|
||||
continue
|
||||
if self.get_macro(macro) and "rename_existing" in self.get_macro(macro):
|
||||
continue
|
||||
macros.append(macro)
|
||||
return macros
|
||||
|
||||
def get_heaters(self):
|
||||
heaters = []
|
||||
|
@ -185,7 +185,7 @@ class BasePanel(ScreenPanel):
|
||||
|
||||
def add_content(self, panel):
|
||||
show = self._printer is not None and self._printer.state not in ('disconnected', 'startup', 'shutdown', 'error')
|
||||
self.show_shortcut(show and self._config.get_main_config().getboolean('side_macro_shortcut', True))
|
||||
self.show_shortcut(show)
|
||||
self.show_heaters(show)
|
||||
self.set_control_sensitive(show, control='estop')
|
||||
for control in ('back', 'home'):
|
||||
@ -258,6 +258,11 @@ class BasePanel(ScreenPanel):
|
||||
self.control[control].set_sensitive(value)
|
||||
|
||||
def show_shortcut(self, show=True):
|
||||
show = (
|
||||
show
|
||||
and self._config.get_main_config().getboolean('side_macro_shortcut', True)
|
||||
and self._printer.get_printer_status_data()["printer"]["gcode_macros"]["count"] > 0
|
||||
)
|
||||
self.control['shortcut'].set_visible(show)
|
||||
self.set_control_sensitive(self._screen._cur_panels[-1] != self.shorcut['panel'])
|
||||
|
||||
|
@ -13,7 +13,7 @@ class Panel(ScreenPanel):
|
||||
def __init__(self, screen, title):
|
||||
super().__init__(screen, title)
|
||||
self.current_extruder = self._printer.get_stat("toolhead", "extruder")
|
||||
macros = self._printer.get_gcode_macros()
|
||||
macros = self._printer.get_config_section_list("gcode_macro ")
|
||||
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)
|
||||
|
||||
|
@ -130,11 +130,6 @@ class Panel(ScreenPanel):
|
||||
|
||||
def load_gcode_macros(self):
|
||||
for macro in self._printer.get_gcode_macros():
|
||||
macro = macro[12:].strip()
|
||||
# Support for hiding macros by _
|
||||
if macro.startswith("_") or macro.upper() in ('LOAD_FILAMENT', 'UNLOAD_FILAMENT'):
|
||||
logging.info(f"Skipping macro {macro}")
|
||||
continue
|
||||
self.options[macro] = {
|
||||
"name": macro,
|
||||
"section": f"displayed_macros {self._screen.connected_printer}",
|
||||
|
11
screen.py
11
screen.py
@ -685,8 +685,15 @@ class KlipperScreen(Gtk.Window):
|
||||
msg = msg if "ready" not in msg else ""
|
||||
self.printer_initializing(_("Klipper has shutdown") + "\n\n" + msg, remove=True)
|
||||
|
||||
def toggle_shortcut(self, value):
|
||||
self.base_panel.show_shortcut(value)
|
||||
def toggle_shortcut(self, show):
|
||||
if show and not self.printer.get_printer_status_data()["printer"]["gcode_macros"]["count"] > 0:
|
||||
self.show_popup_message(
|
||||
_("No elegible macros:") + "\n"
|
||||
+ _("macros with a name starting with '_' are hidden") + "\n"
|
||||
+ _("macros that use 'rename_existing' are hidden") + "\n"
|
||||
+ _("LOAD_FILAMENT/UNLOAD_FILAMENT are hidden and shold be used from extrude") + "\n"
|
||||
)
|
||||
self.base_panel.show_shortcut(show)
|
||||
|
||||
def change_language(self, widget, lang):
|
||||
self._config.install_language(lang)
|
||||
|
Loading…
x
Reference in New Issue
Block a user