예제 #1
0
파일: tails.py 프로젝트: FPar/gnome15
 def _reload(self):
     icons = []
     mime_type = mime.get_type(self.file_path)
     if mime_type != None:
         icons.append(str(mime_type).replace("/","-"))
     icons.append("text-plain")
     icons.append("panel-searchtool")
     icons.append("gnome-searchtool")
     icon = g15icontools.get_icon_path(icons, size=self.plugin._screen.height)
     
     if icon is None:
         self._icon_surface = None
         self._icon_embedded = None
     else:
         try :
             icon_surface = g15cairo.load_surface_from_file(icon)
             self._icon_surface = icon_surface
             self._icon_embedded = g15icontools.get_embedded_image_url(icon_surface)
         except Exception as e:
             logger.warning("Failed to get icon %s", str(icon), exc_info = e)
             self._icon_surface = None
             self._icon_embedded = None
     
     self._stop()
     if os.path.exists(self.file_path):
         self._subtitle =  time.strftime('%Y-%m-%d %H:%M', time.localtime(os.path.getmtime(self.file_path)))
         self._message = ""
         self.thread = G15TailThread(self)
         self.thread.start()
     else:
         self._subtitle = ""
         self._message = "File does not exist"
예제 #2
0
파일: rss.py 프로젝트: FPar/gnome15
 def _on_selected(self):
     self._selected_icon_embedded = None
     if self._menu.selected is not None and self._menu.selected.icon is not None:
         try :
             icon_surface = g15cairo.load_surface_from_file(self._menu.selected.icon)
             self._selected_icon_embedded = g15icontools.get_embedded_image_url(icon_surface)
         except Exception as e:
             logger.warning("Failed to get icon %s", str(self._menu.selected.icon), exc_info = e)
예제 #3
0
 def _on_selected(self):
     self._selected_icon_embedded = None
     if self._menu.selected is not None and self._menu.selected.icon is not None:
         try:
             icon_surface = g15cairo.load_surface_from_file(
                 self._menu.selected.icon)
             self._selected_icon_embedded = g15icontools.get_embedded_image_url(
                 icon_surface)
         except Exception as e:
             logger.warning("Failed to get icon %s",
                            str(self._menu.selected.icon),
                            exc_info=e)
예제 #4
0
    def _reload(self):
        self.feed = feedparser.parse(self.url)
        icon = None
        if "icon" in self.feed["feed"]:
            icon = self.feed["feed"]["icon"]
        elif "image" in self.feed["feed"]:
            img = self.feed["feed"]["image"]
            if "url" in img:
                icon = img["url"]
            elif "link" in img:
                icon = img["link"]

        title = self.feed["feed"]["title"] if "title" in self.feed[
            "feed"] else self.url
        if icon is None and title.endswith("- Twitter Search"):
            title = title[:-16]
            icon = g15icontools.get_icon_path("gnome15")
        if icon is None:
            icon = g15icontools.get_icon_path(
                ["application-rss+xml", "gnome-mime-application-rss+xml"],
                self._screen.height)

        if icon is None:
            self._icon_surface = None
            self._icon_embedded = None
        else:
            try:
                icon_surface = g15cairo.load_surface_from_file(icon)
                self._icon_surface = icon_surface
                self._icon_embedded = g15icontools.get_embedded_image_url(
                    icon_surface)
            except Exception as e:
                logger.warning("Failed to get icon %s", str(icon), exc_info=e)
                self._icon_surface = None
                self._icon_embedded = None
        self.set_title(title)
        self._subtitle = self.feed["feed"][
            "subtitle"] if "subtitle" in self.feed["feed"] else ""
        self._menu.remove_all_children()
        i = 0
        for entry in self.feed.entries:
            self._menu.add_child(
                G15FeedsMenuItem("feeditem-%d" % i, entry, self._gconf_client,
                                 self._gconf_key))
            i += 1
예제 #5
0
파일: rss.py 프로젝트: FPar/gnome15
 def _reload(self):
     self.feed = feedparser.parse(self.url)
     icon = None
     if "icon" in self.feed["feed"]:
         icon = self.feed["feed"]["icon"]
     elif "image" in self.feed["feed"]:
         img = self.feed["feed"]["image"]
         if "url" in img:
             icon = img["url"]
         elif "link" in img:
             icon = img["link"]
             
     title = self.feed["feed"]["title"] if "title" in self.feed["feed"] else self.url
     if icon is None and title.endswith("- Twitter Search"):
         title = title[:-16]
         icon = g15icontools.get_icon_path("gnome15")
     if icon is None:
         icon = g15icontools.get_icon_path(["application-rss+xml","gnome-mime-application-rss+xml"], self._screen.height)
         
     if icon == None:
         self._icon_surface = None
         self._icon_embedded = None
     else:
         try :
             icon_surface = g15cairo.load_surface_from_file(icon)
             self._icon_surface = icon_surface
             self._icon_embedded = g15icontools.get_embedded_image_url(icon_surface)
         except Exception as e:
             logger.warning("Failed to get icon %s", str(icon), exc_info = e)
             self._icon_surface = None
             self._icon_embedded = None
     self.set_title(title)
     self._subtitle = self.feed["feed"]["subtitle"] if "subtitle" in self.feed["feed"] else ""
     self._menu.remove_all_children()
     i = 0
     for entry in self.feed.entries:
         self._menu.add_child(G15FeedsMenuItem("feeditem-%d" % i, entry, self._gconf_client, self._gconf_key))
         i += 1
예제 #6
0
    def _reload(self):
        icons = []
        mime_type = mime.get_type(self.file_path)
        if mime_type != None:
            icons.append(str(mime_type).replace("/", "-"))
        icons.append("text-plain")
        icons.append("panel-searchtool")
        icons.append("gnome-searchtool")
        icon = g15icontools.get_icon_path(icons,
                                          size=self.plugin._screen.height)

        if icon is None:
            self._icon_surface = None
            self._icon_embedded = None
        else:
            try:
                icon_surface = g15cairo.load_surface_from_file(icon)
                self._icon_surface = icon_surface
                self._icon_embedded = g15icontools.get_embedded_image_url(
                    icon_surface)
            except Exception as e:
                logger.warning("Failed to get icon %s", str(icon), exc_info=e)
                self._icon_surface = None
                self._icon_embedded = None

        self._stop()
        if os.path.exists(self.file_path):
            self._subtitle = time.strftime(
                '%Y-%m-%d %H:%M',
                time.localtime(os.path.getmtime(self.file_path)))
            self._message = ""
            self.thread = G15TailThread(self)
            self.thread.start()
        else:
            self._subtitle = ""
            self._message = "File does not exist"
예제 #7
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
예제 #8
0
파일: weather.py 프로젝트: FPar/gnome15
 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
예제 #9
0
def get_embedded_image_url(path):
    return g15icontools.get_embedded_image_url(path)