[gnome-clocks] WorldClocks: use the new GWeather abilities to find if it's daytime or not



commit b332ba99da051294e19b1a015b6d6bcdbe129709
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Dec 2 20:48:11 2012 +0100

    WorldClocks: use the new GWeather abilities to find if it's daytime or not
    
    GWeatherInfo has a new is_daytime() method, which does what gnome-clocks
    needs and additionally accounts for locations within the polar circles.
    Also, GWeatherInfo no longer requires an update to get astronomical data,
    which means we can avoid hitting the network.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689495

 gnomeclocks/world.py |   25 ++++++-------------------
 1 files changed, 6 insertions(+), 19 deletions(-)
---
diff --git a/gnomeclocks/world.py b/gnomeclocks/world.py
index d0b29bc..0fdbd7f 100644
--- a/gnomeclocks/world.py
+++ b/gnomeclocks/world.py
@@ -193,35 +193,22 @@ class ClockItem:
 
     def _update_sunrise_sunset(self):
         self.weather = GWeather.Info(location=self.location, world=gweather_world)
-        self.weather.connect('updated', self._on_weather_updated)
-        self.weather.update()
-
-    def _on_weather_updated(self, weather):
-        # returned as the time here
-        ok1, sunrise = weather.get_value_sunrise()
-        ok2, sunset = weather.get_value_sunset()
+        # We don't need to update self.weather, we're using only astronomical data
+        # and that's offline
+        ok1, sunrise = self.weather.get_value_sunrise()
+        ok2, sunset = self.weather.get_value_sunset()
+        self.is_light = self.weather.is_daytime()
         if ok1 and ok2:
             self.sunrise = self._get_location_time(sunrise)
             self.sunset = self._get_location_time(sunset)
             self.sunrise_string = TimeString.format_time(self.sunrise)
             self.sunset_string = TimeString.format_time(self.sunset)
-            self.is_light = self._get_is_light()
-
-    def _get_is_light(self):
-        current = self.location_time
-        if self.sunrise:
-            return self.sunrise <= current <= self.sunset
-        else:
-            # default fallback when we have no sunrise/sunset times,
-            # as we only have images for either day or night
-            return 7 <= current.tm_hour <= 19
 
     def update_time(self):
         self.location_time = self._get_location_time()
         self.time_string = TimeString.format_time(self.location_time)
         self.day_string = self._get_day_string()
-        self.is_light = self._get_is_light()
-
+        self._update_sunrise_sunset()
 
 class ClockStandalone(Gtk.EventBox):
     def __init__(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]