Beispiel #1
0
 def _get_properties(self):
     now = datetime.datetime.now()
     calendar_date = self._get_calendar_date()
     properties = {}
     properties["icon"] = self._icon_path
     properties["title"] = _('Calendar')
     if g15gconf.get_bool_or_default(
             self.gconf_client,
             "%s/twenty_four_hour_times" % self.gconf_key, True):
         properties["time"] = g15locale.format_time_24hour(
             now, self.gconf_client, False)
         properties["full_time"] = g15locale.format_time_24hour(
             now, self.gconf_client, True)
     else:
         properties["full_time"] = g15locale.format_time(
             now, self.gconf_client, True)
         properties["time"] = g15locale.format_time(now, self.gconf_client,
                                                    False)
     properties["time_24"] = now.strftime("%H:%M")
     properties["full_time_24"] = now.strftime("%H:%M:%S")
     properties["time_12"] = now.strftime("%I:%M %p")
     properties["full_time_12"] = now.strftime("%I:%M:%S %p")
     properties["short_date"] = now.strftime("%a %d %b")
     properties["full_date"] = now.strftime("%A %d %B")
     properties["date"] = g15locale.format_date(now, self.gconf_client)
     properties["locale_date"] = now.strftime("%x")
     properties["locale_time"] = now.strftime("%X")
     properties["year"] = now.strftime("%Y")
     properties["short_year"] = now.strftime("%y")
     properties["week"] = now.strftime("%W")
     properties["month"] = now.strftime("%m")
     properties["month_name"] = now.strftime("%B")
     properties["short_month_name"] = now.strftime("%b")
     properties["day_name"] = now.strftime("%A")
     properties["short_day_name"] = now.strftime("%a")
     properties["day_of_year"] = now.strftime("%d")
     properties["cal_year"] = calendar_date.strftime("%Y")
     properties["cal_month"] = calendar_date.strftime("%m")
     properties["cal_month_name"] = calendar_date.strftime("%B")
     properties["cal_short_month_name"] = calendar_date.strftime("%b")
     properties["cal_year"] = calendar_date.strftime("%Y")
     properties["cal_short_year"] = calendar_date.strftime("%y")
     properties["cal_locale_date"] = calendar_date.strftime("%x")
     if self._event_days is None or not str(
             calendar_date.day) in self._event_days:
         properties["message"] = "No events"
         properties["events"] = False
     else:
         properties["events"] = True
         properties["message"] = ""
     return properties
Beispiel #2
0
 def _get_properties(self):
     properties = { }
     
     '''
     Get the details to display and place them as properties which are passed to
     the theme
     '''
     now = datetime.datetime.now()
     if self.use_24hr_format:
         properties["time"] = g15locale.format_time_24hour(now, self.gconf_client, self.display_seconds)
     else:
         properties["time"] = g15locale.format_time(now, self.gconf_client, self.display_seconds)
     if self.display_date:
         properties["date"] = g15locale.format_date(now, self.gconf_client)
         
     return properties
Beispiel #3
0
    def _get_properties(self):
        properties = {}
        '''
        Get the details to display and place them as properties which are passed to
        the theme
        '''
        now = datetime.datetime.now()
        if self.use_24hr_format:
            properties["time"] = g15locale.format_time_24hour(
                now, self.gconf_client, self.display_seconds)
        else:
            properties["time"] = g15locale.format_time(now, self.gconf_client,
                                                       self.display_seconds)
        if self.display_date:
            properties["date"] = g15locale.format_date(now, self.gconf_client)

        return properties
Beispiel #4
0
 def _get_properties(self):
     now = datetime.datetime.now()
     calendar_date = self._get_calendar_date()
     properties = {}
     properties["icon"] = self._icon_path 
     properties["title"] = _('Calendar')
     if g15gconf.get_bool_or_default(self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True):
         properties["time"] = g15locale.format_time_24hour(now, self.gconf_client, False)
         properties["full_time"] = g15locale.format_time_24hour(now, self.gconf_client, True)
     else:
         properties["full_time"] = g15locale.format_time(now, self.gconf_client, True)
         properties["time"] = g15locale.format_time(now, self.gconf_client, False)
     properties["time_24"] = now.strftime("%H:%M") 
     properties["full_time_24"] = now.strftime("%H:%M:%S") 
     properties["time_12"] = now.strftime("%I:%M %p") 
     properties["full_time_12"] = now.strftime("%I:%M:%S %p")
     properties["short_date"] = now.strftime("%a %d %b")
     properties["full_date"] = now.strftime("%A %d %B")
     properties["date"] = g15locale.format_date(now, self.gconf_client)
     properties["locale_date"] = now.strftime("%x")
     properties["locale_time"] = now.strftime("%X")
     properties["year"] = now.strftime("%Y")
     properties["short_year"] = now.strftime("%y")
     properties["week"] = now.strftime("%W")
     properties["month"] = now.strftime("%m")
     properties["month_name"] = now.strftime("%B")
     properties["short_month_name"] = now.strftime("%b")
     properties["day_name"] = now.strftime("%A")
     properties["short_day_name"] = now.strftime("%a")
     properties["day_of_year"] = now.strftime("%d")
     properties["cal_year"] = calendar_date.strftime("%Y")
     properties["cal_month"] = calendar_date.strftime("%m")
     properties["cal_month_name"] = calendar_date.strftime("%B")
     properties["cal_short_month_name"] = calendar_date.strftime("%b")
     properties["cal_year"] = calendar_date.strftime("%Y")
     properties["cal_short_year"] = calendar_date.strftime("%y")
     properties["cal_locale_date"] = calendar_date.strftime("%x")
     if self._event_days is None or not str(calendar_date.day) in self._event_days:
         properties["message"] = "No events"
         properties["events"] = False
     else:
         properties["events"] = True
         properties["message"] = ""
     return properties
Beispiel #5
0
    def _build_properties(self):
        properties = {}
        attributes = {}
        use_twenty_four_hour = g15gconf.get_bool_or_default(
            self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key,
            True)
        if self._weather is None:
            properties["message"] = _("No weather source configuration")
        else:
            current = self._weather['current_conditions']
            if len(current) == 0:
                properties["message"] = _("No weather data for location:-\n%s"
                                          ) % self._weather['location']
            else:
                properties["location"] = self._weather['location']
                dt = self._weather['datetime']
                if use_twenty_four_hour:
                    properties["time"] = g15locale.format_time_24hour(
                        dt, self.gconf_client, False)
                else:
                    properties["time"] = g15locale.format_time(
                        dt, self.gconf_client, False)
                properties["date"] = g15locale.format_date(
                    dt, self.gconf_client)
                properties["datetime"] = g15locale.format_date_time(
                    dt, self.gconf_client, False)
                properties["message"] = ""
                c_icon, f_icon, t_icon = self._get_icons(current)
                if t_icon != None:
                    attributes["icon"] = g15cairo.load_surface_from_file(
                        t_icon)
                    properties["icon"] = g15icontools.get_embedded_image_url(
                        attributes["icon"])
                else:
                    logger.warning("No translated weather icon for %s", c_icon)
                mono_thumb = self._get_mono_thumb_icon(c_icon)
                if mono_thumb != None:
                    attributes[
                        "mono_thumb_icon"] = g15cairo.load_surface_from_file(
                            os.path.join(
                                os.path.join(os.path.dirname(__file__),
                                             "default"), mono_thumb))
                properties["condition"] = current['condition']

                temp_c = g15pythonlang.to_float_or_none(current['temp_c'])
                if temp_c is not None:
                    temp_f = c_to_f(temp_c)
                    temp_k = c_to_k(temp_c)
                low_c = g15pythonlang.to_float_or_none(
                    current['low']) if 'low' in current else None
                if low_c is not None:
                    low_f = c_to_f(low_c)
                    low_k = c_to_k(low_c)
                high_c = g15pythonlang.to_float_or_none(
                    current['high']) if 'high' in current else None
                if high_c is not None:
                    high_f = c_to_f(high_c)
                    high_k = c_to_k(high_c)

                properties[
                    "temp_c"] = "%3.1f°C" % temp_c if temp_c is not None else ""
                properties[
                    "hi_c"] = "%3.1f°C" % high_c if high_c is not None else ""
                properties[
                    "lo_c"] = "%3.1f°C" % low_c if low_c is not None else ""
                properties[
                    "temp_f"] = "%3.1f°F" % temp_f if temp_c is not None else ""
                properties[
                    "lo_f"] = "%3.1f°F" % low_f if low_c is not None else ""
                properties[
                    "high_f"] = "%3.1f°F" % high_f if high_c is not None else ""
                properties[
                    "temp_k"] = "%3.1f°K" % temp_k if temp_c is not None else ""
                properties[
                    "lo_k"] = "%3.1f°K" % low_k if low_c is not None else ""
                properties[
                    "high_k"] = "%3.1f°K" % high_k if high_c is not None else ""

                units = self.gconf_client.get_int(self.gconf_key + "/units")
                if units == CELSIUS:
                    unit = "C"
                    properties["temp"] = properties["temp_c"]
                    properties[
                        "temp_short"] = "%2.0f°" % temp_c if temp_c else ""
                    properties["hi"] = properties["hi_c"]
                    properties[
                        "hi_short"] = "%2.0f°" % high_c if high_c else ""
                    properties["lo"] = properties["lo_c"]
                    properties["lo_short"] = "%2.0f°" % low_c if low_c else ""
                elif units == FARANHEIT:
                    unit = "F"
                    properties["lo"] = properties["lo_f"]
                    properties[
                        "lo_short"] = "%2.0f°" % low_f if low_c is not None else ""
                    properties["hi"] = properties["high_f"]
                    properties[
                        "hi_short"] = "%2.0f°" % high_f if high_c is not None else ""
                    properties["temp"] = properties["temp_f"]
                    properties[
                        "temp_short"] = "%2.0f°" % temp_f if temp_c is not None else ""
                else:
                    unit = "K"
                    properties["lo"] = properties["lo_k"]
                    properties[
                        "lo_short"] = "%2.0f°" % low_k if low_c is not None else ""
                    properties["hi"] = properties["high_k"]
                    properties[
                        "hi_short"] = "%2.0f°" % high_k if high_c is not None else ""
                    properties["temp"] = properties["temp_k"]
                    properties[
                        "temp_short"] = "%2.0f°" % temp_k if temp_c is not None else ""

                # Wind
                wind = g15pythonlang.append_if_exists(current, "wind_chill",
                                                      "", "%sC")
                wind = g15pythonlang.append_if_exists(current, "wind_speed",
                                                      wind, "%sKph")
                wind = g15pythonlang.append_if_exists(current,
                                                      "wind_direction", wind,
                                                      "%sdeg")
                properties["wind"] = wind

                # Visibility
                visibility = g15pythonlang.append_if_exists(
                    current, "visibility", "", "%sM")
                properties["visibility"] = visibility

                # Pressure
                pressure = g15pythonlang.append_if_exists(
                    current, "pressure", "", "%smb")
                properties["pressure"] = pressure

                # Humidity
                humidity = g15pythonlang.append_if_exists(
                    current, "humidity", "", "%s%%")
                properties["humidity"] = humidity

                # Sunrise
                dt = current['sunrise'] if 'sunrise' in current else None
                if dt is None:
                    properties["sunrise_time"] = ""
                elif use_twenty_four_hour:
                    properties["sunrise_time"] = g15locale.format_time_24hour(
                        dt, self.gconf_client, False)
                else:
                    properties["sunrise_time"] = g15locale.format_time(
                        dt, self.gconf_client, False)

                # Sunset
                dt = current['sunset'] if 'sunset' in current else None
                if dt is None:
                    properties["sunset_time"] = ""
                elif use_twenty_four_hour:
                    properties["sunset_time"] = g15locale.format_time_24hour(
                        dt, self.gconf_client, False)
                else:
                    properties["sunset_time"] = g15locale.format_time(
                        dt, self.gconf_client, False)

                # Blank all the forecasts by default
                for y in range(1, 10):
                    properties["condition" + str(y)] = ""
                    properties["hi" + str(y)] = ""
                    properties["lo" + str(y)] = ""
                    properties["day" + str(y)] = ""
                    properties["day_letter" + str(y)] = ""
                    properties["icon" + str(y)] = ""

                # Forecasts
                y = 1
                if 'forecasts' in self._weather:
                    for forecast in self._weather['forecasts']:
                        properties["condition" +
                                   str(y)] = forecast['condition']

                        lo_c = g15pythonlang.to_float_or_none(forecast['low'])
                        if lo_c is not None:
                            lo_f = c_to_f(temp_c)
                            lo_k = c_to_k(temp_c)
                        hi_c = g15pythonlang.to_float_or_none(forecast['high'])
                        if hi_c is not None:
                            hi_f = c_to_f(hi_c)
                            hi_k = c_to_k(hi_c)

                        if units == CELSIUS:
                            properties["hi" + str(y)] = "%3.0f°C" % hi_c
                            properties["lo" + str(y)] = "%3.0f°C" % lo_c
                        elif units == FARANHEIT:
                            properties["hi" + str(y)] = "%3.0f°F" % hi_f
                            properties["lo" + str(y)] = "%3.0f°F" % lo_f
                        else:
                            properties["hi" + str(y)] = "%3.0f°K" % hi_k
                            properties["lo" + str(y)] = "%3.0f°K" % lo_k

                        properties["day" + str(y)] = forecast['day_of_week']
                        properties["day_letter" +
                                   str(y)] = forecast['day_of_week'][:1]

                        c_icon, f_icon, t_icon = self._get_icons(forecast)
                        properties[
                            "icon" +
                            str(y)] = g15icontools.get_embedded_image_url(
                                g15cairo.load_surface_from_file(t_icon))

                        y += 1

        return properties, attributes
Beispiel #6
0
 def _build_properties(self):
     properties = {}
     attributes = {}
     use_twenty_four_hour = g15gconf.get_bool_or_default(self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True)
     if self._weather is None:            
         properties["message"] = _("No weather source configuration")
     else: 
         current = self._weather['current_conditions']
         if len(current) == 0:
             properties["message"] = _("No weather data for location:-\n%s") % self._weather['location']
         else:
             properties["location"] = self._weather['location']
             dt = self._weather['datetime']
             if use_twenty_four_hour:
                 properties["time"] = g15locale.format_time_24hour(dt, self.gconf_client, False)
             else:          
                 properties["time"] = g15locale.format_time(dt, self.gconf_client, False)
             properties["date"] = g15locale.format_date(dt, self.gconf_client)
             properties["datetime"] = g15locale.format_date_time(dt, self.gconf_client, False)
             properties["message"] = ""
             c_icon, f_icon, t_icon = self._get_icons(current)
             if t_icon != None:
                 attributes["icon"] = g15cairo.load_surface_from_file(t_icon)
                 properties["icon"] = g15icontools.get_embedded_image_url(attributes["icon"])
             else:
                 logger.warning("No translated weather icon for %s", c_icon)
             mono_thumb = self._get_mono_thumb_icon(c_icon)        
             if mono_thumb != None:
                 attributes["mono_thumb_icon"] = g15cairo.load_surface_from_file(os.path.join(os.path.join(os.path.dirname(__file__), "default"), mono_thumb))
             properties["condition"] = current['condition']
             
             temp_c = g15pythonlang.to_float_or_none(current['temp_c'])
             if temp_c is not None:
                 temp_f = c_to_f(temp_c)
                 temp_k = c_to_k(temp_c)
             low_c = g15pythonlang.to_float_or_none(current['low']) if 'low' in current else None
             if low_c is not None :
                 low_f = c_to_f(low_c)
                 low_k = c_to_k(low_c)
             high_c  = g15pythonlang.to_float_or_none(current['high']) if 'high' in current else None
             if high_c is not None :
                 high_f  = c_to_f(high_c)
                 high_k = c_to_k(high_c)
             
             properties["temp_c"] = "%3.1f°C" % temp_c if temp_c is not None else ""
             properties["hi_c"] = "%3.1f°C" % high_c if high_c is not None else ""
             properties["lo_c"] = "%3.1f°C" % low_c if low_c is not None else ""
             properties["temp_f"] = "%3.1f°F" % temp_f if temp_c is not None else ""
             properties["lo_f"] = "%3.1f°F" % low_f if low_c is not None else ""
             properties["high_f"] = "%3.1f°F" % high_f if high_c is not None else ""
             properties["temp_k"] = "%3.1f°K" % temp_k if temp_c is not None else ""
             properties["lo_k"] = "%3.1f°K" % low_k if low_c is not None else ""
             properties["high_k"] = "%3.1f°K" % high_k if high_c is not None else ""
             
             units = self.gconf_client.get_int(self.gconf_key + "/units")
             if units == CELSIUS:      
                 unit = "C"           
                 properties["temp"] = properties["temp_c"]
                 properties["temp_short"] = "%2.0f°" % temp_c if temp_c else ""
                 properties["hi"] = properties["hi_c"]
                 properties["hi_short"] = "%2.0f°" % high_c if high_c else ""                 
                 properties["lo"] = properties["lo_c"]
                 properties["lo_short"] = "%2.0f°" % low_c if low_c else ""
             elif units == FARANHEIT:      
                 unit = "F"                      
                 properties["lo"] = properties["lo_f"]              
                 properties["lo_short"] = "%2.0f°" % low_f if low_c is not None else ""
                 properties["hi"] = properties["high_f"]              
                 properties["hi_short"] = "%2.0f°" % high_f if high_c is not None else ""
                 properties["temp"] = properties["temp_f"]              
                 properties["temp_short"] = "%2.0f°" % temp_f if temp_c is not None else ""
             else:                         
                 unit = "K"          
                 properties["lo"] = properties["lo_k"]
                 properties["lo_short"] = "%2.0f°" % low_k if low_c is not None else ""      
                 properties["hi"] = properties["high_k"]
                 properties["hi_short"] = "%2.0f°" % high_k if high_c is not None else ""
                 properties["temp"] = properties["temp_k"]
                 properties["temp_short"] = "%2.0f°" % temp_k if temp_c is not None else ""
                 
             
             # Wind
             wind = g15pythonlang.append_if_exists(current, "wind_chill", "", "%sC")
             wind = g15pythonlang.append_if_exists(current, "wind_speed", wind, "%sKph")
             wind = g15pythonlang.append_if_exists(current, "wind_direction", wind, "%sdeg")
             properties["wind"] =  wind 
             
             # Visibility
             visibility = g15pythonlang.append_if_exists(current, "visibility", "", "%sM")
             properties["visibility"] =  visibility
             
             # Pressure
             pressure = g15pythonlang.append_if_exists(current, "pressure", "", "%smb")
             properties["pressure"] =  pressure
             
             # Humidity
             humidity = g15pythonlang.append_if_exists(current, "humidity", "", "%s%%")
             properties["humidity"] =  humidity
             
             # Sunrise                
             dt = current['sunrise'] if 'sunrise' in current else None
             if dt is None:
                 properties["sunrise_time"] = ""
             elif use_twenty_four_hour:
                 properties["sunrise_time"] = g15locale.format_time_24hour(dt, self.gconf_client, False)
             else:          
                 properties["sunrise_time"] = g15locale.format_time(dt, self.gconf_client, False)
                 
             # Sunset                
             dt = current['sunset'] if 'sunset' in current else None
             if dt is None:
                 properties["sunset_time"] = ""
             elif use_twenty_four_hour:
                 properties["sunset_time"] = g15locale.format_time_24hour(dt, self.gconf_client, False)
             else:          
                 properties["sunset_time"] = g15locale.format_time(dt, self.gconf_client, False)
                 
             # Blank all the forecasts by default
             for y in range(1, 10):
                 properties["condition" + str(y)] = ""
                 properties["hi" + str(y)] = ""
                 properties["lo" + str(y)] = ""
                 properties["day" + str(y)] = ""
                 properties["day_letter" + str(y)] = ""
                 properties["icon" + str(y)] = ""
                 
             # Forecasts
             y = 1
             if 'forecasts' in self._weather:
                 for forecast in self._weather['forecasts']:        
                     properties["condition" + str(y)] = forecast['condition']
                     
                     lo_c = g15pythonlang.to_float_or_none(forecast['low'])
                     if lo_c is not None:
                         lo_f = c_to_f(temp_c)
                         lo_k = c_to_k(temp_c)
                     hi_c = g15pythonlang.to_float_or_none(forecast['high'])
                     if hi_c is not None:
                         hi_f = c_to_f(hi_c)
                         hi_k = c_to_k(hi_c)
                     
                     if units == CELSIUS:                 
                         properties["hi" + str(y)] = "%3.0f°C" % hi_c
                         properties["lo" + str(y)] = "%3.0f°C" % lo_c
                     elif units == FARANHEIT:                         
                         properties["hi" + str(y)] = "%3.0f°F" % hi_f
                         properties["lo" + str(y)] = "%3.0f°F" % lo_f
                     else:                                  
                         properties["hi" + str(y)] = "%3.0f°K" % hi_k
                         properties["lo" + str(y)] = "%3.0f°K" % lo_k
     
                     properties["day" + str(y)] = forecast['day_of_week']
                     properties["day_letter" + str(y)] = forecast['day_of_week'][:1]
                     
                     c_icon, f_icon, t_icon = self._get_icons(forecast)
                     properties["icon" + str(y)] = g15icontools.get_embedded_image_url(g15cairo.load_surface_from_file(t_icon))
                     
                     y += 1
     
     return properties, attributes