[PATCH 1/3] Use a flag to determine if the datetime spoke is shown

Vratislav Podzimek vpodzime at redhat.com
Mon Dec 15 14:04:33 UTC 2014


Using the timer_id is a highway to hell because it seems totally unrelated.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pyanaconda/ui/gui/spokes/datetime_spoke.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py
index 12c9b06..703e8b8 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
@@ -404,6 +404,7 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
 
         self._update_datetime_timer_id = None
         self._start_updating_timer_id = None
+        self._shown = False
 
     def initialize(self):
         NormalSpoke.initialize(self)
@@ -530,6 +531,8 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
                 return _("Nothing selected")
 
     def apply(self):
+        self._shown = False
+
         # we could use self._tzmap.get_timezone() here, but it returns "" if
         # Etc/XXXXXX timezone is selected
         region = self._get_active_region()
@@ -574,6 +577,8 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
         return True
 
     def refresh(self):
+        self._shown = True
+
         #update the displayed time
         self._update_datetime_timer_id = GLib.timeout_add_seconds(1,
                                                     self._update_datetime)
@@ -764,7 +769,7 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
             isys.set_system_date_time(year, month, day, hours, minutes)
 
         #start the timer only when the spoke is shown
-        if self._update_datetime_timer_id is not None:
+        if self._shown and not self._update_datetime_timer_id:
             self._update_datetime_timer_id = GLib.timeout_add_seconds(1,
                                                         self._update_datetime)
 
@@ -786,14 +791,15 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
         """
 
         #do not start timers if the spoke is not shown
-        if self._update_datetime_timer_id is None:
+        if not self._shown:
             self._update_datetime()
             self._save_system_time()
             return
 
         #stop time updating
-        GLib.source_remove(self._update_datetime_timer_id)
-        self._update_datetime_timer_id = None
+        if self._update_datetime_timer_id:
+            GLib.source_remove(self._update_datetime_timer_id)
+            self._update_datetime_timer_id = None
 
         #stop previous $interval seconds timer (see below)
         if self._start_updating_timer_id:
-- 
2.1.0



More information about the anaconda-patches mailing list