screen: reduce the complexity of the status changes close #792
This commit is contained in:
parent
9020d0b0ea
commit
6b1fd23e35
@ -165,15 +165,13 @@ class Printer:
|
|||||||
if state not in list(self.state_callbacks): # disconnected, startup, ready, shutdown, error, paused, printing
|
if state not in list(self.state_callbacks): # disconnected, startup, ready, shutdown, error, paused, printing
|
||||||
return
|
return
|
||||||
logging.debug(f"Changing state from '{self.state}' to '{state}'")
|
logging.debug(f"Changing state from '{self.state}' to '{state}'")
|
||||||
prev_state = self.state
|
|
||||||
self.state = state
|
self.state = state
|
||||||
if self.state_callbacks[state] is not None:
|
if self.state_callbacks[state] is not None:
|
||||||
logging.debug(f"Adding callback for state: {state}")
|
logging.debug(f"Adding callback for state: {state}")
|
||||||
Gdk.threads_add_idle(
|
Gdk.threads_add_idle(
|
||||||
GLib.PRIORITY_HIGH_IDLE,
|
GLib.PRIORITY_HIGH_IDLE,
|
||||||
self.state_cb,
|
self.state_cb,
|
||||||
self.state_callbacks[state],
|
self.state_callbacks[state]
|
||||||
prev_state
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def configure_power_devices(self, data):
|
def configure_power_devices(self, data):
|
||||||
|
83
screen.py
83
screen.py
@ -82,8 +82,6 @@ class KlipperScreen(Gtk.Window):
|
|||||||
popup_message = None
|
popup_message = None
|
||||||
screensaver = None
|
screensaver = None
|
||||||
printer = None
|
printer = None
|
||||||
printer_select_callbacks = []
|
|
||||||
printer_select_prepanel = None
|
|
||||||
subscriptions = []
|
subscriptions = []
|
||||||
shutdown = True
|
shutdown = True
|
||||||
updating = False
|
updating = False
|
||||||
@ -171,19 +169,7 @@ class KlipperScreen(Gtk.Window):
|
|||||||
|
|
||||||
self.connecting_to_printer = name
|
self.connecting_to_printer = name
|
||||||
|
|
||||||
if self.connected_printer == name:
|
|
||||||
if self.printer_select_prepanel is not None:
|
|
||||||
self.show_panel(self.printer_select_prepanel, "", "", 2)
|
|
||||||
self.printer_select_prepanel = None
|
|
||||||
while len(self.printer_select_callbacks) > 0:
|
|
||||||
i = self.printer_select_callbacks.pop(0)
|
|
||||||
i()
|
|
||||||
self.base_panel.show_printer_select(True)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
self.printer_select_callbacks = []
|
|
||||||
self.printer_select_prepanel = None
|
|
||||||
if self.files is not None:
|
if self.files is not None:
|
||||||
self.files.reset()
|
self.files.reset()
|
||||||
self.files = None
|
self.files = None
|
||||||
@ -709,42 +695,32 @@ class KlipperScreen(Gtk.Window):
|
|||||||
if self.updating is True and updating is False and len(self.update_queue) > 0:
|
if self.updating is True and updating is False and len(self.update_queue) > 0:
|
||||||
i = self.update_queue.pop()
|
i = self.update_queue.pop()
|
||||||
self.update_queue = []
|
self.update_queue = []
|
||||||
i[0](i[1])
|
i[0]()
|
||||||
|
|
||||||
self.updating = updating
|
self.updating = updating
|
||||||
|
|
||||||
def show_printer_select(self, widget=None):
|
def show_printer_select(self, widget=None):
|
||||||
logging.debug(f"Saving panel: {self._cur_panels[0]}")
|
|
||||||
self.printer_select_prepanel = self._cur_panels[0]
|
|
||||||
self.base_panel.show_heaters(False)
|
self.base_panel.show_heaters(False)
|
||||||
self.show_panel("printer_select", "printer_select", _("Printer Select"), 2)
|
self.show_panel("printer_select", "printer_select", _("Printer Select"), 2)
|
||||||
|
|
||||||
def state_execute(self, callback, prev_state):
|
def state_execute(self, callback):
|
||||||
if self.is_updating():
|
if self.is_updating():
|
||||||
self.update_queue.append([callback, prev_state])
|
self.update_queue.append([callback])
|
||||||
else:
|
else:
|
||||||
callback(prev_state)
|
callback()
|
||||||
|
|
||||||
def state_disconnected(self, prev_state):
|
|
||||||
if "printer_select" in self._cur_panels:
|
|
||||||
self.printer_select_callbacks = [self.state_disconnected]
|
|
||||||
return
|
|
||||||
|
|
||||||
|
def state_disconnected(self):
|
||||||
logging.debug("### Going to disconnected")
|
logging.debug("### Going to disconnected")
|
||||||
self.close_screensaver()
|
self.close_screensaver()
|
||||||
self.printer_initializing(_("Klipper has disconnected"))
|
self.printer_initializing(_("Klipper has disconnected"))
|
||||||
if self.connected_printer is not None:
|
self.subscriptions = []
|
||||||
self.connected_printer = None
|
for panel in list(self.panels):
|
||||||
# Try to reconnect
|
if panel not in ["printer_select", "splash_screen"]:
|
||||||
self.connect_printer(self.connecting_to_printer)
|
del self.panels[panel]
|
||||||
else:
|
for dialog in self.dialogs:
|
||||||
self.initial_connection()
|
dialog.destroy()
|
||||||
|
self.init_printer()
|
||||||
def state_error(self, prev_state):
|
|
||||||
if "printer_select" in self._cur_panels:
|
|
||||||
self.printer_select_callbacks = [self.state_error]
|
|
||||||
return
|
|
||||||
|
|
||||||
|
def state_error(self):
|
||||||
self.close_screensaver()
|
self.close_screensaver()
|
||||||
msg = self.printer.get_stat("webhooks", "state_message")
|
msg = self.printer.get_stat("webhooks", "state_message")
|
||||||
if "FIRMWARE_RESTART" in msg:
|
if "FIRMWARE_RESTART" in msg:
|
||||||
@ -765,47 +741,27 @@ class KlipperScreen(Gtk.Window):
|
|||||||
for dialog in self.dialogs:
|
for dialog in self.dialogs:
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def state_paused(self, prev_state):
|
def state_paused(self):
|
||||||
if "job_status" not in self._cur_panels:
|
if "job_status" not in self._cur_panels:
|
||||||
self.printer_printing()
|
self.printer_printing()
|
||||||
|
|
||||||
def state_printing(self, prev_state):
|
def state_printing(self):
|
||||||
if "printer_select" in self._cur_panels:
|
|
||||||
self.printer_select_callbacks = [self.state_printing]
|
|
||||||
return
|
|
||||||
|
|
||||||
if "job_status" not in self._cur_panels:
|
if "job_status" not in self._cur_panels:
|
||||||
self.printer_printing()
|
self.printer_printing()
|
||||||
else:
|
else:
|
||||||
self.panels["job_status"].new_print()
|
self.panels["job_status"].new_print()
|
||||||
|
|
||||||
def state_ready(self, prev_state):
|
def state_ready(self):
|
||||||
if "printer_select" in self._cur_panels:
|
|
||||||
self.printer_select_callbacks = [self.state_ready]
|
|
||||||
return
|
|
||||||
|
|
||||||
# Do not return to main menu if completing a job, timeouts/user input will return
|
# Do not return to main menu if completing a job, timeouts/user input will return
|
||||||
if "job_status" in self._cur_panels or "main_menu" in self._cur_panels:
|
if "job_status" in self._cur_panels:
|
||||||
return
|
return
|
||||||
|
|
||||||
if prev_state not in ['paused', 'printing']:
|
|
||||||
self.init_printer()
|
self.init_printer()
|
||||||
self.base_panel._printer = self.printer
|
|
||||||
|
|
||||||
self.printer_ready()
|
self.printer_ready()
|
||||||
|
|
||||||
def state_startup(self, prev_state):
|
def state_startup(self):
|
||||||
if "printer_select" in self._cur_panels:
|
|
||||||
self.printer_select_callbacks = [self.state_startup]
|
|
||||||
return
|
|
||||||
|
|
||||||
self.printer_initializing(_("Klipper is attempting to start"))
|
self.printer_initializing(_("Klipper is attempting to start"))
|
||||||
|
|
||||||
def state_shutdown(self, prev_state):
|
def state_shutdown(self):
|
||||||
if "printer_select" in self._cur_panels:
|
|
||||||
self.printer_select_callbacks = [self.state_shutdown]
|
|
||||||
return
|
|
||||||
|
|
||||||
self.close_screensaver()
|
self.close_screensaver()
|
||||||
msg = self.printer.get_stat("webhooks", "state_message")
|
msg = self.printer.get_stat("webhooks", "state_message")
|
||||||
if "ready" in msg:
|
if "ready" in msg:
|
||||||
@ -1028,7 +984,6 @@ class KlipperScreen(Gtk.Window):
|
|||||||
self.close_popup_message()
|
self.close_popup_message()
|
||||||
self.show_panel('main_panel', "main_menu", None, 2, items=self._config.get_menu_items("__main"))
|
self.show_panel('main_panel', "main_menu", None, 2, items=self._config.get_menu_items("__main"))
|
||||||
self.base_panel_show_all()
|
self.base_panel_show_all()
|
||||||
self.ws_subscribe()
|
|
||||||
if "job_status" in self.panels:
|
if "job_status" in self.panels:
|
||||||
self.remove_subscription("job_status")
|
self.remove_subscription("job_status")
|
||||||
del self.panels["job_status"]
|
del self.panels["job_status"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user