From c574a8f09baa18f452810c0b28bb44beff8a1510 Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Fri, 26 Apr 2024 07:56:56 +0200 Subject: [PATCH] Cleanly terminate polling timer on window closed --- src/window.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/window.py b/src/window.py index 7f8e070..b40e9a1 100644 --- a/src/window.py +++ b/src/window.py @@ -17,8 +17,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -from gi.repository import Adw -from gi.repository import Gtk +from gi.repository import Adw, Gtk, GObject from .sensors_polling_timer import SensorsPollingTimer from .ev_calculator import EVCalculator @@ -32,10 +31,17 @@ class LumosWindow(Adw.ApplicationWindow): def __init__(self, **kwargs): super().__init__(**kwargs) + # Register for window lifecycle events + self.connect("close-request", self.__on_close_request) + # Start polling sensors self.sensorsPollingTimer = SensorsPollingTimer(0.1, self.onSensorRead) self.sensorsPollingTimer.start() + def __on_close_request(self, _obj: GObject.Object) -> None: + # On window destroyed.Stop polling sensors + self.sensorsPollingTimer.cancel() + def onSensorRead(self, value: float, unit: str): # Called when the light value changed if self.lux_label: