refactor graph update timer
This commit is contained in:
1 parent
7a7d275c31
commit
dbe3f03019
2 files changed
+19
-11
No files matched your search
+13
-8
@@ -17,6 +17,7 @@ def create_panel(*args, **kwargs):
|
||||
class MainPanel(MenuPanel):
|
||||
def __init__(self, screen, title, items=None):
|
||||
super().__init__(screen, title, items)
|
||||
self.graph_retry_timeout = None
|
||||
self.left_panel = None
|
||||
self.devices = {}
|
||||
self.graph_update = None
|
||||
@@ -33,8 +34,6 @@ class MainPanel(MenuPanel):
|
||||
if stats["temperature_devices"]["count"] > 0 or stats["extruders"]["count"] > 0:
|
||||
self._gtk.reset_temp_color()
|
||||
self.main_menu.attach(self.create_left_panel(), 0, 0, 1, 1)
|
||||
else:
|
||||
self.graph_update = False
|
||||
if self._screen.vertical_mode:
|
||||
self.labels['menu'] = self.arrangeMenuItems(items, 3, True)
|
||||
self.main_menu.attach(self.labels['menu'], 0, 1, 1, 1)
|
||||
@@ -47,7 +46,8 @@ class MainPanel(MenuPanel):
|
||||
if self.left_panel is None or not self._printer.get_temp_store_devices():
|
||||
self.graph_retry += 1
|
||||
if self.graph_retry < 5:
|
||||
GLib.timeout_add_seconds(5, self.update_graph_visibility)
|
||||
if self.graph_retry_timeout is None:
|
||||
self.graph_retry_timeout = GLib.timeout_add_seconds(5, self.update_graph_visibility)
|
||||
else:
|
||||
logging.debug(f"Could not create graph {self.left_panel} {self._printer.get_temp_store_devices()}")
|
||||
return False
|
||||
@@ -69,23 +69,28 @@ class MainPanel(MenuPanel):
|
||||
self.left_panel.add(self.labels['da'])
|
||||
self.labels['da'].queue_draw()
|
||||
self.labels['da'].show()
|
||||
if self.graph_update is None:
|
||||
# This has a high impact on load
|
||||
self.graph_update = GLib.timeout_add_seconds(5, self.update_graph)
|
||||
elif self.labels['da'] in self.left_panel:
|
||||
self.left_panel.remove(self.labels['da'])
|
||||
if self.graph_update is not None:
|
||||
GLib.source_remove(self.graph_update)
|
||||
self.graph_update = None
|
||||
self.graph_retry = 0
|
||||
return False
|
||||
|
||||
def activate(self):
|
||||
# For this case False != None
|
||||
if self.graph_update is None:
|
||||
# This has a high impact on load
|
||||
self.graph_update = GLib.timeout_add_seconds(5, self.update_graph)
|
||||
self.update_graph_visibility()
|
||||
self._screen.base_panel_show_all()
|
||||
|
||||
def deactivate(self):
|
||||
if self.graph_update:
|
||||
if self.graph_update is not None:
|
||||
GLib.source_remove(self.graph_update)
|
||||
self.graph_update = None
|
||||
if self.graph_retry_timeout is not None:
|
||||
GLib.source_remove(self.graph_retry_timeout)
|
||||
self.graph_retry_timeout = None
|
||||
if self.active_heater is not None:
|
||||
self.hide_numpad()
|
||||
|
||||
|
||||
@@ -194,13 +194,16 @@ class TemperaturePanel(ScreenPanel):
|
||||
self.left_panel.add(self.labels['da'])
|
||||
self.labels['da'].queue_draw()
|
||||
self.labels['da'].show()
|
||||
if self.graph_update is None:
|
||||
# This has a high impact on load
|
||||
self.graph_update = GLib.timeout_add_seconds(5, self.update_graph)
|
||||
elif self.labels['da'] in self.left_panel:
|
||||
self.left_panel.remove(self.labels['da'])
|
||||
if self.graph_update is not None:
|
||||
GLib.source_remove(self.graph_update)
|
||||
self.graph_update = None
|
||||
|
||||
def activate(self):
|
||||
if self.graph_update is None:
|
||||
# This has a high impact on load
|
||||
self.graph_update = GLib.timeout_add_seconds(5, self.update_graph)
|
||||
self.update_graph_visibility()
|
||||
|
||||
def deactivate(self):
|
||||
|
||||
Reference in new issue
Block a user