From cfeabdc3afe96471b6b632f2745ec1f7bf86ef8f Mon Sep 17 00:00:00 2001 From: James Cameron Date: Thu, 15 Oct 2015 11:17:41 +1100 Subject: [PATCH] remove GSource used by TimeoutAlert For an object of class TimeoutAlert, an OK response occurs on timeout, even if user has clicked a button. Remove the timeout when the user clicks a button. A new method _response is added which overrides the parent method. --- src/sugar3/graphics/alert.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sugar3/graphics/alert.py b/src/sugar3/graphics/alert.py index 4cd4c128..85047acb 100644 --- a/src/sugar3/graphics/alert.py +++ b/src/sugar3/graphics/alert.py @@ -402,16 +402,20 @@ class TimeoutAlert(Alert): self.add_button(Gtk.ResponseType.OK, _('Continue'), self._timeout_text) self._timeout_text.show() - GLib.timeout_add_seconds(1, self.__timeout) + self._timeout_sid = GLib.timeout_add(1000, self.__timeout) def __timeout(self): self._timeout -= 1 self._timeout_text.set_text(self._timeout) if self._timeout == 0: - self._response(Gtk.ResponseType.OK) + Alert._response(self, Gtk.ResponseType.OK) return False return True + def _response(self, *args): + GLib.source_remove(self._timeout_sid) + Alert._response(self, *args) + class NotifyAlert(Alert): """