Beispiel #1
0
 def _attention_changed(self, attention):
     self._attention = attention
     if self._attention == 1:
         self._start_blink()
         if self.screen.driver.get_bpp() == 1:
             self.thumb_icon = g15cairo.load_surface_from_file(os.path.join(os.path.dirname(__file__), "mono-mail-new.gif"))
         else:
             self.thumb_icon = g15cairo.load_surface_from_file(g15icontools.get_icon_path("indicator-messages-new"))
         self._popup()
     else:
         self._stop_blink()
         if self.screen.driver.get_bpp() == 16:
             self.thumb_icon = g15cairo.load_surface_from_file(g15icontools.get_icon_path("indicator-messages"))
         self.screen.redraw()
Beispiel #2
0
    def refresh(self):
        t_count = 0
        t_errors = 0
        for item in self.items:
            try :
                item.refreshing = True
                self.page.redraw()
                status = self._check_account(item.account)
                item.count  = status[0]
                t_count += item.count
                item.error = None
                item.refreshing = False
            except Exception as e:
                item.refreshing = False
                t_errors += 1
                item.error = e
                item.count = 0
                logger.debug("Error while refreshing item %s", str(item), exc_info = e)
                
        self.total_count = t_count
        self.total_errors = t_errors
        
        if self.total_errors > 0:
            self._stop_blink()
            self.attention = True   
            if self.screen.driver.get_bpp() == 1:
                self.thumb_icon = g15cairo.load_surface_from_file(os.path.join(os.path.dirname(__file__), "mono-mail-error.gif"))
            elif self.screen.driver.get_bpp() > 0:
                self.thumb_icon = g15cairo.load_surface_from_file(g15icontools.get_icon_path(["new-messages-red","messagebox_critical"]))
        else:
            if self.total_count > 0:
                self._start_blink()
                self.attention = True
                if self.screen.driver.get_bpp() == 1:
                    self.thumb_icon = g15cairo.load_surface_from_file(os.path.join(os.path.dirname(__file__), "mono-mail-new.gif"))
                elif self.screen.driver.get_bpp() > 0:
                    self.thumb_icon = g15cairo.load_surface_from_file(g15icontools.get_icon_path(["indicator-messages-new", "mail-message-new"]))
            else:
                self._stop_blink()
                self.attention = False   
                if self.screen.driver.get_bpp() == 1:
                    self.thumb_icon = None
                elif self.screen.driver.get_bpp() > 0:
                    self.thumb_icon = g15cairo.load_surface_from_file(g15icontools.get_icon_path(["indicator-messages", "mail-message"]))

        if self.screen.driver.get_bpp() > 0:        
            self.screen.redraw(self.page)
            
        self.schedule_refresh()
Beispiel #3
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"
Beispiel #4
0
 def __init__(self, screen, source, plugin):
     g15theme.G15Page.__init__(self, "videopage-%s" % source.name, screen, \
                               priority = g15screen.PRI_NORMAL, \
                               title = source.name, \
                               theme = g15theme.G15Theme(self, variant = 'mediakeys' if plugin._grabbed_keys else None), thumbnail_painter = self._paint_thumbnail, originating_plugin = plugin)
     self._sidebar_offset = 0
     self._source = source
     self._muted = False
     self._lock = Lock()
     self._plugin = plugin
     self._surface = None
     self._hide_timer = None
     self._screen = screen
     self._full_screen = self._screen.driver.get_size()
     self._aspect = self._full_screen
     self._active = True
     self._frame_index = 1
     self._last_seconds = -1
     self._thumb_icon = g15cairo.load_surface_from_file(icon_path)
     self._setup_gstreamer()
     self.screen.key_handler.action_listeners.append(self) 
     def on_delete():
         self._pipeline.set_state(gst.STATE_NULL)
         self.screen.key_handler.action_listeners.remove(self)
         self.screen.painters.remove(self.background_painter)
         self._plugin.show_menu()
         self._plugin._release_multimedia_keys()
     self.on_deleted = on_delete
     self.background_painter = G15VideoPainter(self)
     self.screen.painters.append(self.background_painter)
     self._plugin.hide_menu()
Beispiel #5
0
    def __init__(self, screen, source, plugin):
        g15theme.G15Page.__init__(self, "videopage-%s" % source.name, screen, \
                                  priority = g15screen.PRI_NORMAL, \
                                  title = source.name, \
                                  theme = g15theme.G15Theme(self, variant = 'mediakeys' if plugin._grabbed_keys else None), thumbnail_painter = self._paint_thumbnail, originating_plugin = plugin)
        self._sidebar_offset = 0
        self._source = source
        self._muted = False
        self._lock = Lock()
        self._plugin = plugin
        self._surface = None
        self._hide_timer = None
        self._screen = screen
        self._full_screen = self._screen.driver.get_size()
        self._aspect = self._full_screen
        self._active = True
        self._frame_index = 1
        self._last_seconds = -1
        self._thumb_icon = g15cairo.load_surface_from_file(icon_path)
        self._setup_gstreamer()
        self.screen.key_handler.action_listeners.append(self)

        def on_delete():
            self._pipeline.set_state(Gst.State.NULL)
            self.screen.key_handler.action_listeners.remove(self)
            self.screen.painters.remove(self.background_painter)
            self._plugin.show_menu()
            self._plugin._release_multimedia_keys()

        self.on_deleted = on_delete
        self.background_painter = G15VideoPainter(self)
        self.screen.painters.append(self.background_painter)
        self._plugin.hide_menu()
Beispiel #6
0
    def __init__(self, gconf_key, gconf_client, screen):
        g15plugin.G15RefreshingPlugin.__init__(
            self, gconf_client, gconf_key, screen,
            self._get_icon_path("Machovka_tomato.png"), id, name)
        self.waiting_image = \
                g15cairo.load_surface_from_file(self._get_icon_path("Machovka_tomato.png"))
        self.running_image = \
                g15cairo.load_surface_from_file(self._get_icon_path("Machovka_tomato_green.png"))
        self.waiting_image_1bpp = \
                g15cairo.load_surface_from_file(self._get_icon_path("tomato_empty_1bpp.png"))
        self.running_image_1bpp = \
                g15cairo.load_surface_from_file(self._get_icon_path("tomato_1bpp.png"))

        self.pommodoro_timer = PommodoroTimer()
        self.pommodoro_timer.on_state_change = self.timer_state_changed
        self.pommodoro_timer.on_count_change = self.pommodoro_count_save
        self._load_configuration()
Beispiel #7
0
 def __init__(self, gconf_key, gconf_client, screen):
     g15plugin.G15Plugin.__init__(self, gconf_client, gconf_key, screen)
     self._timer = None
     self._icon_path = g15icontools.get_icon_path([
         "calendar", "evolution-calendar", "office-calendar",
         "stock_calendar"
     ])
     self._thumb_icon = g15cairo.load_surface_from_file(self._icon_path)
Beispiel #8
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)
Beispiel #9
0
 def __init__(self, gconf_key, gconf_client, screen):
     
     self._screen = screen
     self._gconf_client = gconf_client
     self._gconf_key = gconf_key
     self._timer = None
     self._icon_path = g15icontools.get_icon_path([ "redhat-office", "package_office", "gnome-applications", "xfce-office", "baobab" ])
     self._thumb_icon = g15cairo.load_surface_from_file(self._icon_path)
     self._timer = None
Beispiel #10
0
 def _attention_changed(self, attention):
     self._attention = attention
     if self._attention == 1:
         self._start_blink()
         if self.screen.driver.get_bpp() == 1:
             self.thumb_icon = g15cairo.load_surface_from_file(
                 os.path.join(os.path.dirname(__file__),
                              "mono-mail-new.gif"))
         else:
             self.thumb_icon = g15cairo.load_surface_from_file(
                 g15icontools.get_icon_path("indicator-messages-new"))
         self._popup()
     else:
         self._stop_blink()
         if self.screen.driver.get_bpp() == 16:
             self.thumb_icon = g15cairo.load_surface_from_file(
                 g15icontools.get_icon_path("indicator-messages"))
         self.screen.redraw()
Beispiel #11
0
    def Image(self, path, x, y, width, height):
        if not "/" in path:
            path = g15icontools.get_icon_path(path,
                                              width if width != 0 else 128)

        size = None if width == 0 or height == 0 else (width, height)

        img_surface = g15cairo.load_surface_from_file(path, size)
        self._page.image(img_surface, x, y)
Beispiel #12
0
    def __init__(self, gconf_key, gconf_client, screen):
        g15plugin.G15RefreshingPlugin.__init__(self,
                                               gconf_client,
                                               gconf_key,
                                               screen,
                                               self._get_icon_path("Machovka_tomato.png"),
                                               id,
                                               name)
        self.waiting_image = \
                g15cairo.load_surface_from_file(self._get_icon_path("Machovka_tomato.png"))
        self.running_image = \
                g15cairo.load_surface_from_file(self._get_icon_path("Machovka_tomato_green.png"))
        self.waiting_image_1bpp = \
                g15cairo.load_surface_from_file(self._get_icon_path("tomato_empty_1bpp.png"))
        self.running_image_1bpp = \
                g15cairo.load_surface_from_file(self._get_icon_path("tomato_1bpp.png"))

        self.pommodoro_timer = PommodoroTimer()
        self.pommodoro_timer.on_state_change = self.timer_state_changed
        self.pommodoro_timer.on_count_change = self.pommodoro_count_save
        self._load_configuration()
Beispiel #13
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)
Beispiel #14
0
 def __init__(self, screen):
     g15theme.G15Page.__init__(self, id, screen, title = name, theme = g15theme.G15Theme(self), thumbnail_painter = self._paint_thumbnail)
     self._sidebar_offset = 0
     self._muted = False
     self._lock = Lock()
     self._surface = None
     self._hide_timer = None
     self._screen = screen
     self._full_screen = self._screen.driver.get_size()
     self._aspect = self._full_screen
     self._playing = None
     self._active = True
     self._frame_index = 1
     self._frame_wait = 0.04
     self._thumb_icon = g15cairo.load_surface_from_file(g15icontools.get_icon_path(["media-video", "emblem-video", "emblem-videos", "video", "video-player" ]))
Beispiel #15
0
 def _check_status(self):
     """
     indicator-messages replaces indicator-me from Oneiric, so we get the current status icon if available
     to show that on the panel too
     """
     self._status_icon = None
     for c in self._messages_menu.menu_map:
         menu_entry = self._messages_menu.menu_map[c]
         if menu_entry.toggle_type == dbusmenu.TOGGLE_TYPE_RADIO and menu_entry.toggle_state == 1:
             icon_name = menu_entry.get_icon_name()
             if icon_name is not None and \
                 icon_name in [ "user-available", "user-away", 
                                 "user-busy", "user-offline", 
                                 "user-invisible", "user-indeterminate" ]:
                 self._status_icon = g15cairo.load_surface_from_file(g15icontools.get_icon_path(icon_name))
Beispiel #16
0
 def _check_status(self):
     """
     indicator-messages replaces indicator-me from Oneiric, so we get the current status icon if available
     to show that on the panel too
     """
     self._status_icon = None
     for c in self._messages_menu.menu_map:
         menu_entry = self._messages_menu.menu_map[c]
         if menu_entry.toggle_type == dbusmenu.TOGGLE_TYPE_RADIO and menu_entry.toggle_state == 1:
             icon_name = menu_entry.get_icon_name()
             if icon_name is not None and \
                 icon_name in [ "user-available", "user-away",
                                 "user-busy", "user-offline",
                                 "user-invisible", "user-indeterminate" ]:
                 self._status_icon = g15cairo.load_surface_from_file(
                     g15icontools.get_icon_path(icon_name))
    def paint_foreground(self, canvas, properties, attributes, args, x_offset,
                         y_offset):
        items = attributes["items"]
        selected = attributes["selected"]

        canvas.save()
        y = y_offset

        # How many complete items fit on the screen? Make sure the selected item is visible
        # TODO again, this needs turning into a re-usable component - see menu and rss
        item_height = self.entry_theme.bounds[3]
        max_items = int((self.screen.height - y) / item_height)
        if selected != None:
            sel_index = items.index(selected)
            diff = sel_index + 1 - max_items
            if diff > 0:
                y -= diff * item_height
        canvas.rectangle(x_offset, y_offset,
                         self.screen.width - (x_offset * 2),
                         self.screen.height - y_offset)
        canvas.clip()

        canvas.translate(x_offset, y)
        for item in items:
            item_properties = {}
            if selected == item:
                item_properties["item_selected"] = True
            item_properties["item_name"] = item.get_label()
            item_properties["item_alt"] = item.get_right_side_text()
            item_properties["item_type"] = item.get_type()
            icon_name = item.get_icon_name()
            if icon_name != None:
                item_properties["item_icon"] = g15cairo.load_surface_from_file(
                    g15icontools.get_icon_path(self.screen.applet.conf_client,
                                               icon_name))
            else:
                item_properties["item_icon"] = item.get_icon()

            if item.get_type() == "separator":
                self.separator_theme.draw(canvas, item_properties)
            else:
                self.entry_theme.draw(canvas, item_properties)
            canvas.translate(0, item_height)
            y += item_height
            if y + item_height > self.theme.screen.height:
                break
        canvas.restore()
Beispiel #18
0
 def __init__(self, screen):
     g15theme.G15Page.__init__(self, id, screen, title=name, theme=g15theme.G15Theme(self),
                               thumbnail_painter=self._paint_thumbnail)
     self._sidebar_offset = 0
     self._muted = False
     self._lock = Lock()
     self._surface = None
     self._hide_timer = None
     self._screen = screen
     self._full_screen = self._screen.driver.get_size()
     self._aspect = self._full_screen
     self._playing = None
     self._active = True
     self._frame_index = 1
     self._frame_wait = 0.04
     self._thumb_icon = g15cairo.load_surface_from_file(
         g15icontools.get_icon_path(["media-video", "emblem-video", "emblem-videos", "video", "video-player"]))
Beispiel #19
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
Beispiel #20
0
    def _load_surface_list(self, names):
        lst = []
        for i in names:
            path = self.clock_theme_dir + "/" + i + ".svg"
            if os.path.exists(path):
                svg = rsvg.Handle(path)
                try:
                    if self.svg_size is None:
                        self.svg_size = svg.get_dimension_data()[2:4]

                    svg_size = self.svg_size

                    sx = self.width / svg_size[0]
                    sy = self.height / svg_size[1]
                    scale = min(sx, sy)
                    surface = cairo.SVGSurface(None, svg_size[0] * scale * 2,
                                               svg_size[1] * scale * 2)
                    context = cairo.Context(surface)
                    self.screen.configure_canvas(context)
                    context.scale(scale, scale)
                    context.translate(svg_size[0], svg_size[1])
                    svg.render_cairo(context)
                    context.translate(-svg_size[0], -svg_size[1])
                    lst.append(
                        ((svg_size[0] * scale, svg_size[1] * scale), surface))
                finally:
                    svg.close()

            path = self.clock_theme_dir + "/" + i + ".gif"
            if os.path.exists(path):
                img_surface = g15cairo.load_surface_from_file(
                    path, self.height)
                surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                             img_surface.get_width() * 2,
                                             img_surface.get_height() * 2)
                context = cairo.Context(surface)
                self.screen.configure_canvas(context)
                context.translate(img_surface.get_width(),
                                  img_surface.get_height())
                context.set_source_surface(img_surface)
                context.paint()
                lst.append(((img_surface.get_width(),
                             img_surface.get_height()), surface))
        return lst
 def paint_foreground(self, canvas, properties, attributes, args, x_offset, y_offset):  
     items = attributes["items"]
     selected = attributes["selected"]
     
     canvas.save()
     y = y_offset
     
     # How many complete items fit on the screen? Make sure the selected item is visible
     # TODO again, this needs turning into a re-usable component - see menu and rss
     item_height = self.entry_theme.bounds[3]
     max_items = int( ( self.screen.height - y )  / item_height)
     if selected != None:
         sel_index = items.index(selected)
         diff = sel_index + 1 - max_items
         if diff > 0:
             y -= diff  * item_height
     canvas.rectangle(x_offset, y_offset, self.screen.width - ( x_offset * 2 ), self.screen.height - y_offset)
     canvas.clip() 
     
     canvas.translate(x_offset, y)
     for item in items:
         item_properties = {}
         if selected == item:
             item_properties["item_selected"] = True
         item_properties["item_name"] = item.get_label() 
         item_properties["item_alt"] = item.get_right_side_text()
         item_properties["item_type"] = item.get_type()
         icon_name = item.get_icon_name()
         if icon_name != None:
             item_properties["item_icon"] = g15cairo.load_surface_from_file(g15icontools.get_icon_path(self.screen.applet.conf_client, icon_name))
         else:
             item_properties["item_icon"] = item.get_icon()
             
         if item.get_type() == "separator":
             self.separator_theme.draw(canvas, item_properties)
         else:
             self.entry_theme.draw(canvas, item_properties)
         canvas.translate(0, item_height)
         y += item_height
         if y + item_height > self.theme.screen.height:
             break
     canvas.restore() 
Beispiel #22
0
 def _get_item_for_bamf_application(self, window):
     view = self._get_bamf_application_object(window)
     item = self._get_menu_item(window)
     try:
         item.process_name = view.Name()
     except dbus.DBusException as e:
         logger.debug("Could not get process_name. Using default", exc_info = e)
         item.process_name = "Unknown"
     try:
         icon_name = view.Icon()
         if icon_name and len(icon_name) > 0:
             icon_path = g15icontools.get_icon_path(icon_name, warning = False)
             if icon_path:
                 item.icon = g15cairo.load_surface_from_file(icon_path, 32)
     except dbus.DBusException as e:
         logger.debug("Could not get icon", exc_info = e)
         pass
             
         
     return item
Beispiel #23
0
 def __init__(self, gconf_client, gconf_key, screen, icon, page_id, title):
     """
     Constructor
     
     Keyword arguments:
     gconf_client            - gconf client
     gconf_key               - gconf key for plugin
     screen                  - screen
     icon                    - icon to use for thumbnail
     title                   - title for page (displayed in menu etc)
     refresh_interval        - how often to refresh the page
     """
     G15Plugin.__init__(self, gconf_client, gconf_key, screen)
     self.page_id = page_id
     self.hidden = False
     self._icon_path = g15icontools.get_icon_path(icon)
     self._title = title
     self.page = None
     self.thumb_icon = g15cairo.load_surface_from_file(self._icon_path)
     self.add_page_on_activate = True
Beispiel #24
0
    def paint(self, canvas):
        g15theme.G15Page.paint(self, canvas)
        wait = self._frame_wait
        size = self._screen.driver.get_size()

        if self._playing != None:

            # Process may have been killed
            if not self._playing._playing():
                self._stop()

            dir = sorted(os.listdir(self._playing.temp_dir), reverse=True)
            if len(dir) > 1:
                dir = dir[1:]
                file = os.path.join(self._playing.temp_dir, dir[0])
                self._surface = g15cairo.load_surface_from_file(file)
                for path in dir:
                    file = os.path.join(self._playing.temp_dir, path)
                    os.remove(file)
            else:
                wait = 0.1

            if self._surface != None:
                target_size = (float(size[0]),
                               float(size[0]) * (float(self._aspect[1])) /
                               float(self._aspect[0]))
                sx = float(target_size[0]) / float(self._surface.get_width())
                sy = float(target_size[1]) / float(self._surface.get_height())
                canvas.save()
                canvas.translate((size[0] - target_size[0]) / 2.0,
                                 (size[1] - target_size[1]) / 2.0)
                canvas.scale(sx, sy)
                canvas.set_source_surface(self._surface)
                canvas.paint()
                canvas.restore()

        if self._playing != None:
            timer = Timer(wait, self.redraw)
            timer.name = "VideoRedrawTimer"
            timer.setDaemon(True)
            timer.start()
Beispiel #25
0
    def _get_item_for_bamf_application(self, window):
        view = self._get_bamf_application_object(window)
        item = self._get_menu_item(window)
        try:
            item.process_name = view.Name()
        except dbus.DBusException as e:
            logger.debug("Could not get process_name. Using default",
                         exc_info=e)
            item.process_name = "Unknown"
        try:
            icon_name = view.Icon()
            if icon_name and len(icon_name) > 0:
                icon_path = g15icontools.get_icon_path(icon_name,
                                                       warning=False)
                if icon_path:
                    item.icon = g15cairo.load_surface_from_file(icon_path, 32)
        except dbus.DBusException as e:
            logger.debug("Could not get icon", exc_info=e)
            pass

        return item
Beispiel #26
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 == 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
Beispiel #27
0
 def paint(self, canvas):
     g15theme.G15Page.paint(self, canvas)
     wait = self._frame_wait
     size = self._screen.driver.get_size()
         
     if self._playing != None:
         
         # Process may have been killed
         if not self._playing._playing():
             self._stop()
         
         dir = sorted(os.listdir(self._playing.temp_dir), reverse=True)
         if len(dir) > 1:
             dir = dir[1:]
             file = os.path.join(self._playing.temp_dir, dir[0])
             self._surface = g15cairo.load_surface_from_file(file)
             for path in dir:
                 file = os.path.join(self._playing.temp_dir, path)
                 os.remove(file)
         else:
             wait = 0.1
         
         if self._surface != None:
             target_size = ( float(size[0]), float(size[0]) * (float(self._aspect[1]) ) / float(self._aspect[0]) )
             sx = float(target_size[0]) / float(self._surface.get_width())
             sy = float(target_size[1]) / float(self._surface.get_height())
             canvas.save()
             canvas.translate((size[0] - target_size[0]) / 2.0,(size[1] - target_size[1]) / 2.0)
             canvas.scale(sx, sy)
             canvas.set_source_surface(self._surface)
             canvas.paint()
             canvas.restore()   
     
     if self._playing != None:
         timer = Timer(wait, self.redraw)
         timer.name = "VideoRedrawTimer"
         timer.setDaemon(True)
         timer.start()
Beispiel #28
0
 def _load_surface_list(self, names):
     list = []        
     for i in names:
         path = self.clock_theme_dir + "/" + i + ".svg"
         if os.path.exists(path):  
             svg = rsvg.Handle(path)
             try: 
                 if self.svg_size == None:
                     self.svg_size = svg.get_dimension_data()[2:4]
                     
                 svg_size = self.svg_size
                      
                 sx = self.width / svg_size[0]
                 sy = self.height / svg_size[1]
                 scale = min(sx, sy)                      
                 surface = cairo.SVGSurface(None, svg_size[0] * scale * 2,svg_size[1] * scale * 2)  
                 context = cairo.Context(surface)
                 self.screen.configure_canvas(context)
                 context.scale(scale, scale)
                 context.translate(svg_size[0], svg_size[1])
                 svg.render_cairo(context)
                 context.translate(-svg_size[0], -svg_size[1])
                 list.append(((svg_size[0] * scale, svg_size[1] * scale), surface))
             finally:
                 svg.close()
             
         path = self.clock_theme_dir + "/" + i + ".gif"
         if os.path.exists(path):
             img_surface = g15cairo.load_surface_from_file(path, self.height)
             surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, img_surface.get_width() * 2, img_surface.get_height() * 2)  
             context = cairo.Context(surface)
             self.screen.configure_canvas(context)
             context.translate(img_surface.get_width(), img_surface.get_height())
             context.set_source_surface(img_surface)
             context.paint()
             list.append(((img_surface.get_width(), img_surface.get_height()), surface))
     return list
Beispiel #29
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"
Beispiel #30
0
 def _do_config_changed(self):
     # Get the configuration
     screen_size = self.screen.size
     self.bg_img = None
     bg_type = self.gconf_client.get_string(self.gconf_key + "/type")
     if bg_type == None:
         bg_type = "desktop"
     bg_style = self.gconf_client.get_string(self.gconf_key + "/style")
     if bg_style == None:
         bg_style = "zoom"
     allow_profile_override = g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/allow_profile_override", True)
     
     # See if the current profile has a background
     if allow_profile_override:
         active_profile = g15profile.get_active_profile(self.screen.device)
         if active_profile is not None and active_profile.background is not None and active_profile.background != "":
             self.bg_img = active_profile.background
     
     if self.bg_img == None and bg_type == "desktop":
         # Get the current background the desktop is using if possible
         desktop_env = g15desktop.get_desktop()
         if desktop_env in [ "gnome", "gnome-shell" ]:
             if self.gnome_dconf_settings is not None:
                 self.bg_img = self.gnome_dconf_settings.get_string("picture-uri")
             else:
                 self.bg_img = self.gconf_client.get_string("/desktop/gnome/background/picture_filename")
         else:
             logger.warning("User request wallpaper from the desktop, but the desktop environment is unknown. Please report this bug to the Gnome15 project")
     
     if self.bg_img == None:
         # Use the file
         self.bg_img = self.gconf_client.get_string(self.gconf_key + "/path")
         
     # Fallback to the default provided image
     if self.bg_img == None:
         self.bg_img = os.path.join(os.path.dirname(__file__), "background-%dx%d.png" % ( screen_size[0], screen_size[1] ) )
         
     # Load the image 
     if self.bg_img != self.this_image or bg_style != self.current_style:
         self.this_image = self.bg_img
         self.current_style = bg_style
         if g15cairo.is_url(self.bg_img) or os.path.exists(self.bg_img):
             
             """
             TODO handle background themes and transitions from XML files properly
             
             For now, just get the first static image
             """
             if self.bg_img.endswith(".xml"):                    
                 filet = etree.parse(self.bg_img).getroot().findtext('.//file')
                 if filet:
                     self.bg_img = filet                
             
             img_surface = g15cairo.load_surface_from_file(self.bg_img)
             if img_surface is not None:
                 sx = float(screen_size[0]) / img_surface.get_width()
                 sy = float(screen_size[1]) / img_surface.get_height()  
                 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, screen_size[0], screen_size[1])
                 context = cairo.Context(surface)
                 context.save()
                 if bg_style == "zoom":
                     scale = max(sx, sy)
                     context.scale(scale, scale)
                     context.set_source_surface(img_surface)
                     context.paint()
                 elif bg_style == "stretch":              
                     context.scale(sx, sy)
                     context.set_source_surface(img_surface)
                     context.paint()
                 elif bg_style == "scale":  
                     x = ( screen_size[0] - img_surface.get_width() * sy ) / 2   
                     context.translate(x, 0)         
                     context.scale(sy, sy)
                     context.set_source_surface(img_surface)
                     context.paint()
                 elif bg_style == "center":        
                     x = ( screen_size[0] - img_surface.get_width() ) / 2
                     y = ( screen_size[1] - img_surface.get_height() ) / 2
                     context.translate(x, y)
                     context.set_source_surface(img_surface)
                     context.paint()
                 elif bg_style == "tile":
                     context.set_source_surface(img_surface)
                     context.paint()
                     y = 0
                     x = img_surface.get_width()
                     while y < screen_size[1] + img_surface.get_height():
                         if x >= screen_size[1] + img_surface.get_width():
                             x = 0
                             y += img_surface.get_height()
                         context.restore()
                         context.save()
                         context.translate(x, y)
                         context.set_source_surface(img_surface)
                         context.paint()
                         x += img_surface.get_width()
                     
                 context.restore()
                 self.painter.background_image = surface
             else:
                 self.painter.background_image = None
         else:
             self.painter.background_image = None
             
     self.painter.brightness = self.gconf_client.get_int(self.gconf_key + "/brightness")
             
     self.screen.redraw()
Beispiel #31
0
 def ImageData(self, image_data, x, y):
     file_str = StringIO(str(image_data))
     img_surface = g15cairo.load_surface_from_file(file_str, None)
     file_str.close()
     self._page.image(img_surface, x, y)
Beispiel #32
0
 def paint_thumbnail(self, canvas, allocated_size, horizontal):
     return g15cairo.paint_thumbnail_image(allocated_size, g15cairo.load_surface_from_file(self.icon), canvas)
Beispiel #33
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 #34
0
 def on_configure(self):
     g15theme.MenuItem.on_configure(self)
     self._surface = g15cairo.load_surface_from_file(
         self.profile.get_profile_icon_path(16), self.theme.bounds[3])
Beispiel #35
0
    def _do_config_changed(self):
        # Get the configuration
        screen_size = self.screen.size
        self.bg_img = None
        bg_type = self.gconf_client.get_string(self.gconf_key + "/type")
        if bg_type == None:
            bg_type = "desktop"
        bg_style = self.gconf_client.get_string(self.gconf_key + "/style")
        if bg_style == None:
            bg_style = "zoom"
        allow_profile_override = g15gconf.get_bool_or_default(
            self.gconf_client, self.gconf_key + "/allow_profile_override",
            True)

        # See if the current profile has a background
        if allow_profile_override:
            active_profile = g15profile.get_active_profile(self.screen.device)
            if active_profile is not None and active_profile.background is not None and active_profile.background != "":
                self.bg_img = active_profile.background

        if self.bg_img == None and bg_type == "desktop":
            # Get the current background the desktop is using if possible
            desktop_env = g15desktop.get_desktop()
            if desktop_env in ["gnome", "gnome-shell"]:
                if self.gnome_dconf_settings is not None:
                    self.bg_img = self.gnome_dconf_settings.get_string(
                        "picture-uri")
                else:
                    self.bg_img = self.gconf_client.get_string(
                        "/desktop/gnome/background/picture_filename")
            else:
                logger.warning(
                    "User request wallpaper from the desktop, but the desktop environment is unknown. Please report this bug to the Gnome15 project"
                )

        if self.bg_img == None:
            # Use the file
            self.bg_img = self.gconf_client.get_string(self.gconf_key +
                                                       "/path")

        # Fallback to the default provided image
        if self.bg_img == None:
            self.bg_img = os.path.join(
                os.path.dirname(__file__),
                "background-%dx%d.png" % (screen_size[0], screen_size[1]))

        # Load the image
        if self.bg_img != self.this_image or bg_style != self.current_style:
            self.this_image = self.bg_img
            self.current_style = bg_style
            if g15cairo.is_url(self.bg_img) or os.path.exists(self.bg_img):
                """
                TODO handle background themes and transitions from XML files properly
                
                For now, just get the first static image
                """
                if self.bg_img.endswith(".xml"):
                    filet = etree.parse(
                        self.bg_img).getroot().findtext('.//file')
                    if filet:
                        self.bg_img = filet

                img_surface = g15cairo.load_surface_from_file(self.bg_img)
                if img_surface is not None:
                    sx = float(screen_size[0]) / img_surface.get_width()
                    sy = float(screen_size[1]) / img_surface.get_height()
                    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                                 screen_size[0],
                                                 screen_size[1])
                    context = cairo.Context(surface)
                    context.save()
                    if bg_style == "zoom":
                        scale = max(sx, sy)
                        context.scale(scale, scale)
                        context.set_source_surface(img_surface)
                        context.paint()
                    elif bg_style == "stretch":
                        context.scale(sx, sy)
                        context.set_source_surface(img_surface)
                        context.paint()
                    elif bg_style == "scale":
                        x = (screen_size[0] - img_surface.get_width() * sy) / 2
                        context.translate(x, 0)
                        context.scale(sy, sy)
                        context.set_source_surface(img_surface)
                        context.paint()
                    elif bg_style == "center":
                        x = (screen_size[0] - img_surface.get_width()) / 2
                        y = (screen_size[1] - img_surface.get_height()) / 2
                        context.translate(x, y)
                        context.set_source_surface(img_surface)
                        context.paint()
                    elif bg_style == "tile":
                        context.set_source_surface(img_surface)
                        context.paint()
                        y = 0
                        x = img_surface.get_width()
                        while y < screen_size[1] + img_surface.get_height():
                            if x >= screen_size[1] + img_surface.get_width():
                                x = 0
                                y += img_surface.get_height()
                            context.restore()
                            context.save()
                            context.translate(x, y)
                            context.set_source_surface(img_surface)
                            context.paint()
                            x += img_surface.get_width()

                    context.restore()
                    self.painter.background_image = surface
                else:
                    self.painter.background_image = None
            else:
                self.painter.background_image = None

        self.painter.brightness = self.gconf_client.get_int(self.gconf_key +
                                                            "/brightness")

        self.screen.redraw()
Beispiel #36
0
 def process_properties(self):
     
     logger.debug("Processing properties")
             
     self.recalc_progress()
     # Find the best icon for the media
     
     
     if "art_uri" in self.song_properties and self.song_properties["art_uri"] != "":
         new_cover_uri = self.song_properties["art_uri"]
     else:   
         cover_art = os.path.join(xdg.BaseDirectory.xdg_cache_home,
                                  "rhythmbox",
                                  "covers",
                                  "%s - %s.jpg" % (self.song_properties["artist"],
                                                   self.song_properties["album"]))
         new_cover_uri = None
         if cover_art != None and os.path.exists(cover_art):
             new_cover_uri = cover_art
             
     if new_cover_uri == None:
         new_cover_uri = self.get_default_cover()
             
     if new_cover_uri != self.cover_uri:
         self.cover_uri = new_cover_uri
         logger.info("Getting cover art from %s", self.cover_uri)
         self.cover_image = None
         self.thumb_image = None
         if self.cover_uri != None:
             cover_image = g15cairo.load_surface_from_file(self.cover_uri, self.screen.driver.get_size()[0])
             if cover_image:
                 self.cover_image = cover_image
                 
                 # If the cover URI was from HTTP, then we cached it. Use that as the URI
                 if self.cover_uri.startswith("http:") or self.cover_uri.startswith("http:"):
                     self.cover_uri = g15cairo.get_image_cache_file(self.cover_uri, self.screen.driver.get_size()[0])
             else:
                 cover_image = self.get_default_cover()
                 logger.warning("Failed to loaded preferred cover art, " \
                                "falling back to default of %s", cover_image)
                 if cover_image:
                     self.cover_uri = cover_image
                     self.cover_image = g15cairo.load_surface_from_file(self.cover_uri, self.screen.driver.get_size()[0])
               
     # Track status
     if self.status == "Stopped":
         self.song_properties["stopped"] = True
         self.song_properties["icon"] = g15icontools.get_icon_path(["media-stop", "media-playback-stop", "gtk-media-stop", "player_stop" ], self.screen.height)
         self.song_properties["title"] = _("No track playing")
         self.song_properties["time_text"] = ""
     else:            
         if self.status == "Playing":
             if self.screen.driver.get_bpp() == 1:
                 self.thumb_image = g15cairo.load_surface_from_file(os.path.join(os.path.join(os.path.dirname(__file__), "default"), "play.gif"))
             else:
                 self.thumb_image = self.cover_image
             self.song_properties["playing"] = True
         else:
             if self.screen.driver.get_bpp() == 1:
                 self.thumb_image = g15cairo.load_surface_from_file(os.path.join(os.path.join(os.path.dirname(__file__), "default"), "pause.gif"))
             else:
                 self.thumb_image = self.cover_image                
             self.song_properties["paused"] = True
         self.song_properties["icon"] = self.cover_uri
Beispiel #37
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 #38
0
 def __init__(self, gconf_key, gconf_client, screen):
     g15plugin.G15Plugin.__init__(self, gconf_client, gconf_key, screen)
     self._timer = None
     self._icon_path = g15icontools.get_icon_path(["calendar", "evolution-calendar", "office-calendar", "stock_calendar" ])
     self._thumb_icon = g15cairo.load_surface_from_file(self._icon_path)
Beispiel #39
0
 def on_configure(self): 
     g15theme.MenuItem.on_configure(self)
     self._surface = g15cairo.load_surface_from_file(self.profile.get_profile_icon_path(16), self.theme.bounds[3])
Beispiel #40
0
 def paint_thumbnail(self, canvas, allocated_size, horizontal):
     return g15cairo.paint_thumbnail_image(
         allocated_size, g15cairo.load_surface_from_file(self.icon), canvas)
Beispiel #41
0
    def process_properties(self):

        logger.debug("Processing properties")

        self.recalc_progress()
        # Find the best icon for the media

        if "art_uri" in self.song_properties and self.song_properties[
                "art_uri"] != "":
            new_cover_uri = self.song_properties["art_uri"]
        else:
            cover_art = os.path.join(
                xdg.BaseDirectory.xdg_cache_home, "rhythmbox", "covers",
                "%s - %s.jpg" % (self.song_properties["artist"],
                                 self.song_properties["album"]))
            new_cover_uri = None
            if cover_art != None and os.path.exists(cover_art):
                new_cover_uri = cover_art

        if new_cover_uri == None:
            new_cover_uri = self.get_default_cover()

        if new_cover_uri != self.cover_uri:
            self.cover_uri = new_cover_uri
            logger.info("Getting cover art from %s", self.cover_uri)
            self.cover_image = None
            self.thumb_image = None
            if self.cover_uri != None:
                cover_image = g15cairo.load_surface_from_file(
                    self.cover_uri,
                    self.screen.driver.get_size()[0])
                if cover_image:
                    self.cover_image = cover_image

                    # If the cover URI was from HTTP, then we cached it. Use that as the URI
                    if self.cover_uri.startswith(
                            "http:") or self.cover_uri.startswith("http:"):
                        self.cover_uri = g15cairo.get_image_cache_file(
                            self.cover_uri,
                            self.screen.driver.get_size()[0])
                else:
                    cover_image = self.get_default_cover()
                    logger.warning("Failed to loaded preferred cover art, " \
                                   "falling back to default of %s", cover_image)
                    if cover_image:
                        self.cover_uri = cover_image
                        self.cover_image = g15cairo.load_surface_from_file(
                            self.cover_uri,
                            self.screen.driver.get_size()[0])

        # Track status
        if self.status == "Stopped":
            self.song_properties["stopped"] = True
            self.song_properties["icon"] = g15icontools.get_icon_path([
                "media-stop", "media-playback-stop", "gtk-media-stop",
                "player_stop"
            ], self.screen.height)
            self.song_properties["title"] = _("No track playing")
            self.song_properties["time_text"] = ""
        else:
            if self.status == "Playing":
                if self.screen.driver.get_bpp() == 1:
                    self.thumb_image = g15cairo.load_surface_from_file(
                        os.path.join(
                            os.path.join(os.path.dirname(__file__), "default"),
                            "play.gif"))
                else:
                    self.thumb_image = self.cover_image
                self.song_properties["playing"] = True
            else:
                if self.screen.driver.get_bpp() == 1:
                    self.thumb_image = g15cairo.load_surface_from_file(
                        os.path.join(
                            os.path.join(os.path.dirname(__file__), "default"),
                            "pause.gif"))
                else:
                    self.thumb_image = self.cover_image
                self.song_properties["paused"] = True
            self.song_properties["icon"] = self.cover_uri
Beispiel #42
0
    def activate(self):
        self._net_icon = g15icontools.get_icon_path(
            ["network-transmit-receive", "gnome-fs-network", "network-server"],
            self.screen.height)
        self._cpu_icon = g15icontools.get_icon_path(CPU_ICONS,
                                                    self.screen.height)
        self._mem_icon = g15icontools.get_icon_path(
            ["media-memory", "media-flash"], self.screen.height)
        self._thumb_icon = g15cairo.load_surface_from_file(self._cpu_icon)

        self.variant = 0
        self.graphs = {}
        self.last_time_list = None
        self.last_times_list = []
        self.last_time = 0

        # CPU
        self.selected_cpu = None
        self.cpu_no = 0
        self.cpu_data = []
        selected_cpu_name = self.gconf_client.get_string(self.gconf_key +
                                                         "/cpu")
        cpus = gtop.cpu().cpus
        for i in range(-1, len(cpus)):
            cpu = CPU(i)
            self.cpu_data.append(cpu)
            if cpu.name == selected_cpu_name:
                self.selected_cpu = cpu
        if self.selected_cpu is None:
            self.selected_cpu = self.cpu_data[0]

        # Net
        self.selected_net = None
        _, self.net_list = self._get_net_stats()
        net_name = self.gconf_client.get_string(self.gconf_key + "/net")
        self.net_data = []
        for idx, n in enumerate(self.net_list):
            net = Net(idx, n)
            self.net_data.append(net)
            if net.name == net_name:
                self.selected_net = net

        if self.selected_net is None and len(self.net_data) > 0:
            self.selected_net = self.net_data[0]

            # Memory
        self.max_total_mem = 0
        self.total = 1.0
        self.cached = 0
        self.free = 0
        self.used = 0
        self.cached_history = [0] * GRAPH_SIZE
        self.used_history = [0] * GRAPH_SIZE

        g15plugin.G15RefreshingPlugin.activate(self)
        self._set_panel()
        self.watch(["show_cpu_on_panel", "theme"], self._config_changed)
        self.screen.key_handler.action_listeners.append(self)

        # Start refreshing
        self.do_refresh()
Beispiel #43
0
    def activate(self):
        self._net_icon = g15icontools.get_icon_path([ "network-transmit-receive",
                                                "gnome-fs-network",
                                                "network-server" ], 
                                               self.screen.height)
        self._cpu_icon = g15icontools.get_icon_path( CPU_ICONS,
                                               self.screen.height)
        self._mem_icon = g15icontools.get_icon_path( [ "media-memory",
                                                 "media-flash" ],  
                                               self.screen.height)
        self._thumb_icon = g15cairo.load_surface_from_file(self._cpu_icon)
        
        self.variant = 0
        self.graphs = {}
        self.last_time_list = None
        self.last_times_list = []
        self.last_time = 0
        
        # CPU
        self.selected_cpu = None
        self.cpu_no = 0  
        self.cpu_data = []  
        selected_cpu_name = self.gconf_client.get_string(self.gconf_key + "/cpu")
        cpus = gtop.cpu().cpus
        for i in range(-1, len(cpus)):
            cpu = CPU(i)
            self.cpu_data.append(cpu)
            if cpu.name == selected_cpu_name:
                self.selected_cpu = cpu
        if self.selected_cpu is None:
            self.selected_cpu = self.cpu_data[0]

        # Net
        self.selected_net = None
        _, self.net_list = self._get_net_stats()
        net_name = self.gconf_client.get_string(self.gconf_key + "/net")
        self.net_data = []
        for idx, n in enumerate(self.net_list):
            net = Net(idx, n)
            self.net_data.append(net)
            if net.name == net_name:
                self.selected_net = net
            
        if self.selected_net is None and len(self.net_data) > 0:
            self.selected_net = self.net_data[0] 
            
        
        # Memory
        self.max_total_mem = 0
        self.total = 1.0
        self.cached = 0
        self.free = 0
        self.used = 0
        self.cached_history = [0] * GRAPH_SIZE
        self.used_history =  [0] * GRAPH_SIZE 
        
        g15plugin.G15RefreshingPlugin.activate(self)
        self._set_panel()
        self.watch(["show_cpu_on_panel","theme"], self._config_changed)
        self.screen.key_handler.action_listeners.append(self)
        
        # Start refreshing
        self.do_refresh()
Beispiel #44
0
 def set_icon(self, icon):
     self._icon_path = g15icontools.get_icon_path(icon)
     self.thumb_icon = g15cairo.load_surface_from_file(self._icon_path)
Beispiel #45
0
def load_surface_from_file(filename, size=None):
    return g15cairo.load_surface_from_file(filename, size)