screen: refactor to fix #1397

only auto-close dialogs when changing menu struct
only remove_all when changing menu
This commit is contained in:
Alfredo Monclus 2024-06-10 10:38:33 -03:00
parent e3174c4929
commit 8e735bfd5d

View File

@ -309,8 +309,13 @@ class KlipperScreen(Gtk.Window):
panel_name = panel panel_name = panel
try: try:
if remove_all: if remove_all:
self._remove_all_panels()
self.panels_reinit = list(self.panels) self.panels_reinit = list(self.panels)
if panel in self._cur_panels:
self._menu_go_back(home=True)
else:
self._remove_all_panels()
for dialog in self.dialogs:
self.gtk.remove_dialog(dialog)
else: else:
self._remove_current_panel() self._remove_current_panel()
if panel_name not in self.panels: if panel_name not in self.panels:
@ -552,12 +557,12 @@ class KlipperScreen(Gtk.Window):
self._remove_current_panel() self._remove_current_panel()
del self._cur_panels[-1] del self._cur_panels[-1]
self._cur_panels.clear() self._cur_panels.clear()
for dialog in self.dialogs:
self.gtk.remove_dialog(dialog)
self.close_screensaver() self.close_screensaver()
gc.collect() gc.collect()
def _remove_current_panel(self): def _remove_current_panel(self):
if not self._cur_panels:
return
if hasattr(self.panels[self._cur_panels[-1]], "deactivate"): if hasattr(self.panels[self._cur_panels[-1]], "deactivate"):
self.panels[self._cur_panels[-1]].deactivate() self.panels[self._cur_panels[-1]].deactivate()
self.base_panel.remove(self.panels[self._cur_panels[-1]].content) self.base_panel.remove(self.panels[self._cur_panels[-1]].content)
@ -570,9 +575,6 @@ class KlipperScreen(Gtk.Window):
del self._cur_panels[-1] del self._cur_panels[-1]
if not home: if not home:
break break
if len(self._cur_panels) < 1:
self.reload_panels()
return
self.attach_panel(self._cur_panels[-1]) self.attach_panel(self._cur_panels[-1])
def reset_screensaver_timeout(self, *args): def reset_screensaver_timeout(self, *args):
@ -757,8 +759,6 @@ class KlipperScreen(Gtk.Window):
self.show_panel("extrude") self.show_panel("extrude")
def state_printing(self): def state_printing(self):
for dialog in self.dialogs:
self.gtk.remove_dialog(dialog)
self.show_panel("job_status", remove_all=True) self.show_panel("job_status", remove_all=True)
def state_ready(self, wait=True): def state_ready(self, wait=True):
@ -803,9 +803,10 @@ class KlipperScreen(Gtk.Window):
if "printer_select" in self._cur_panels: if "printer_select" in self._cur_panels:
self.show_printer_select() self.show_printer_select()
return return
home = self._cur_panels[0]
self.panels_reinit = list(self.panels)
self._remove_all_panels() self._remove_all_panels()
if self.printer is not None: self.show_panel(home)
self.printer.change_state(self.printer.state)
def _websocket_callback(self, action, data): def _websocket_callback(self, action, data):
if self.connecting: if self.connecting: