macros: hide the panel if there are no elegible macros

This commit is contained in:
alfrix
2023-08-31 22:01:14 -03:00
parent e80ef7eff5
commit e01b6e5f26
5 changed files with 25 additions and 10 deletions

View File

@@ -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'])

View File

@@ -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)

View File

@@ -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}",