def get_pixbuf_from_name(self, query_name, x=None, y=None, return_default=True): x = (x or BROWSER_COVER_SIZE["x"]) y = (y or BROWSER_COVER_SIZE["y"]) filename = get_cache_file("cover/%s.jpg" % query_name.replace("/", "")) if os.path.exists(filename): try: gtk.gdk.pixbuf_new_from_file_at_size(filename, COVER_SIZE["x"], COVER_SIZE["y"]) except gobject.GError: os.unlink(filename) filename = None else: filename = None if filename is None: if return_default: return get_optimum_pixbuf_from_file(self.default_cover) return None else: return get_optimum_pixbuf_from_file(filename, x, y)
def cleanup_small(self, old_path, new_path=None): if not new_path: new_path = old_path if not os.path.exists(old_path): return False try: pixbuf = get_optimum_pixbuf_from_file(old_path, SMALL_SIZE["x"], SMALL_SIZE["y"]) except gobject.GError: try: if os.path.exists(old_path): os.unlink(old_path) except: pass try: if os.path.exists(new_path): os.unlink(new_path) except: pass return False else: try: if os.path.exists(new_path): os.unlink(new_path) except: pass try: if os.path.exists(old_path): os.unlink(old_path) except: pass pixbuf.save(new_path, "jpeg", {"quality" : "100"}) del pixbuf return True
def set_current_cover(self, try_web=True, force_song=None): if not force_song: force_song = self.current_song filename = CoverManager.get_cover(force_song, try_web) if Player.song != force_song: return False if not filename: if not try_web: if force_song.get_type() == "webcast": pixbuf = utils.get_optimum_pixbuf( self.webcast_dpixbuf.get_pixbuf(), COVER_SIZE["x"], COVER_SIZE["y"]) self.start_animation(pixbuf, is_default=True) return True else: pixbuf = utils.get_optimum_pixbuf( self.local_dpixbuf.get_pixbuf(), COVER_SIZE["x"], COVER_SIZE["y"]) self.start_animation(pixbuf, is_default=True) return False return False else: try: pixbuf = get_optimum_pixbuf_from_file(filename, COVER_SIZE["x"], COVER_SIZE["y"]) except gobject.GError: return False else: self.start_animation(pixbuf, is_default=False) return True
def set_current_cover(self, try_web=True, force_song=None): if not force_song: force_song = self.current_song filename = CoverManager.get_cover(force_song, try_web) if Player.song != force_song: return False if not filename: if not try_web: if force_song.get_type() == "webcast": pixbuf = utils.get_optimum_pixbuf(self.webcast_dpixbuf.get_pixbuf(), COVER_SIZE["x"], COVER_SIZE["y"]) self.start_animation(pixbuf, is_default=True) return True else: pixbuf = utils.get_optimum_pixbuf(self.local_dpixbuf.get_pixbuf(), COVER_SIZE["x"], COVER_SIZE["y"]) self.start_animation(pixbuf, is_default=True) return False return False else: try: pixbuf = get_optimum_pixbuf_from_file(filename, COVER_SIZE["x"], COVER_SIZE["y"]) except gobject.GError: return False else: self.start_animation(pixbuf, is_default=False) return True
def cleanup_cover(self, old_path, new_path=None): if not new_path: new_path = old_path if not os.path.exists(old_path): return False try: pixbuf = get_optimum_pixbuf_from_file(old_path, DOUBAN_COVER_SIZE["x"], DOUBAN_COVER_SIZE["y"]) except gobject.GError: try: if os.path.exists(new_path): os.unlink(new_path) except: pass try: if os.path.exists(old_path): os.unlink(old_path) except: pass return False else: try: if os.path.exists(new_path): os.unlink(new_path) except: pass try: if os.path.exists(old_path): os.unlink(old_path) except: pass pixbuf.save(new_path, "png") del pixbuf # utils.clip_surface(new_path) return True
def get_small_pixbuf(self, image_object, x=None, y=None): x = (x or ICON_SIZE["x"]) y = (y or ICON_SIZE["y"]) image_path = self.get_image(image_object, False) if not image_path: image_path = self.default_image_path return get_optimum_pixbuf_from_file(image_path, x, y)
def get_pixbuf_from_song(self, song, x, y, try_web=True, optimum=True): filename = self.get_cover(song, try_web) if not filename: filename = self.default_cover if optimum: return get_optimum_pixbuf_from_file(filename, x, y) else: return gtk.gdk.pixbuf_new_from_file_at_size(filename, x, y)
def render(self, cr, rect): ''' Render item. This is IconView interface, you should implement it. ''' # Init. if self.pixbuf == None: self.pixbuf = get_optimum_pixbuf_from_file(self.image_path, self.wallpaper_width, self.wallpaper_height) wallpaper_x = rect.x + (rect.width - self.wallpaper_width) / 2 wallpaper_y = rect.y + (rect.height - self.wallpaper_height) / 2 # Draw shadow. drop_shadow_padding = 7 drop_shadow_radious = 7 draw_shadow( cr, wallpaper_x, wallpaper_y, self.wallpaper_width + drop_shadow_padding, self.wallpaper_height + drop_shadow_padding, drop_shadow_radious, app_theme.get_shadow_color("window_shadow") ) outside_shadow_padding = 4 outside_shadow_radious = 5 draw_shadow( cr, wallpaper_x - outside_shadow_padding, wallpaper_y - outside_shadow_padding, self.wallpaper_width + outside_shadow_padding * 2, self.wallpaper_height + outside_shadow_padding * 2, outside_shadow_radious, app_theme.get_shadow_color("window_shadow") ) # Draw wallpaper. draw_pixbuf(cr, self.pixbuf, wallpaper_x, wallpaper_y) # Draw wallpaper frame. with cairo_disable_antialias(cr): cr.set_line_width(2) cr.set_source_rgba(1, 1, 1, 1) cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height) cr.stroke() if self.is_hover: cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height) cr.set_source_rgb(*color_hex_to_cairo(self.hover_stroke_dcolor.get_color())) cr.stroke()
def render(self, cr, rect): ''' Render item. This is IconView interface, you should implement it. ''' # Init. if self.pixbuf == None: self.pixbuf = get_optimum_pixbuf_from_file(self.image_path, self.wallpaper_width, self.wallpaper_height) wallpaper_x = rect.x + (rect.width - self.wallpaper_width) / 2 wallpaper_y = rect.y + (rect.height - self.wallpaper_height) / 2 # Draw shadow. drop_shadow_padding = 7 drop_shadow_radious = 7 draw_shadow(cr, wallpaper_x, wallpaper_y, self.wallpaper_width + drop_shadow_padding, self.wallpaper_height + drop_shadow_padding, drop_shadow_radious, app_theme.get_shadow_color("window_shadow")) outside_shadow_padding = 4 outside_shadow_radious = 5 draw_shadow(cr, wallpaper_x - outside_shadow_padding, wallpaper_y - outside_shadow_padding, self.wallpaper_width + outside_shadow_padding * 2, self.wallpaper_height + outside_shadow_padding * 2, outside_shadow_radious, app_theme.get_shadow_color("window_shadow")) # Draw wallpaper. draw_pixbuf(cr, self.pixbuf, wallpaper_x, wallpaper_y) # Draw wallpaper frame. with cairo_disable_antialias(cr): cr.set_line_width(2) cr.set_source_rgba(1, 1, 1, 1) cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height) cr.stroke() if self.is_hover: cr.rectangle(wallpaper_x, wallpaper_y, self.wallpaper_width, self.wallpaper_height) cr.set_source_rgb( *color_hex_to_cairo(self.hover_stroke_dcolor.get_color())) cr.stroke()
def set_current_cover(self, try_web=True, force_song=None): if not force_song: force_song = self.current_song filename = CoverManager.get_cover(force_song, try_web) try: pixbuf = get_optimum_pixbuf_from_file(filename, COVER_SIZE["x"], COVER_SIZE["y"]) except gobject.GError: pass else: self.current_cover_pixbuf = pixbuf self.queue_draw() del pixbuf if not try_web: return CoverManager.default_cover != filename
def composite_images(files, width, height, write_file): try: surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) context = cairo.Context(surface) cr = gtk.gdk.CairoContext(context) cut_width = cut_height = width / 2 for index, f in enumerate(files): pixbuf = get_optimum_pixbuf_from_file(f, cut_width, cut_height) if index % 2 == 0: start_x = 0 else: start_x = cut_width if index <= 1: start_y = 0 else: start_y = cut_height cr.set_source_pixbuf(pixbuf, start_x, start_y) cr.paint() surface.write_to_png(write_file) return write_file except: return None
def cleanup_small(self, old_path, new_path=None): if not new_path: new_path = old_path if not os.path.exists(old_path): return False try: pixbuf = get_optimum_pixbuf_from_file(old_path, SMALL_SIZE["x"], SMALL_SIZE["y"]) except gobject.GError: try: if os.path.exists(old_path): os.unlink(old_path) except: pass try: if os.path.exists(new_path): os.unlink(new_path) except: pass return False else: try: if os.path.exists(new_path): os.unlink(new_path) except: pass try: if os.path.exists(old_path): os.unlink(old_path) except: pass pixbuf.save(new_path, "jpeg", {"quality": "100"}) del pixbuf return True
def create_cache_pixbuf(self): self.pixbuf = get_optimum_pixbuf_from_file(self.image_path, self.wallpaper_width, self.wallpaper_height)
def render(self, cr, rect): ''' Render item. This is IconView interface, you should implement it. ''' # Draw background. if self.highlight_flag: with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(self.highlight_fill_color)) cr.rectangle(rect.x + self.hover_offset, rect.y + self.hover_offset, rect.width - self.hover_offset * 2, rect.height - self.hover_offset * 2) cr.fill_preserve() cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo(self.highlight_stroke_color)) cr.stroke() elif self.hover_flag: with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(self.hover_fill_dcolor.get_color())) cr.rectangle(rect.x + self.hover_offset, rect.y + self.hover_offset, rect.width - self.hover_offset * 2, rect.height - self.hover_offset * 2) cr.fill_preserve() cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo(self.hover_stroke_dcolor.get_color())) cr.stroke() # Draw wallpapers. if self.pixbufs == []: wallpaper_paths = self.theme.get_wallpaper_paths()[:3] wallpaper_paths = wallpaper_paths[::-1] for wallpaper_file in wallpaper_paths: self.pixbufs.append(get_optimum_pixbuf_from_file(wallpaper_file, self.wallpaper_width, self.wallpaper_height)) theme_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, rect.width, rect.height) theme_surface_cr = gtk.gdk.CairoContext(cairo.Context(theme_surface)) with cairo_state(theme_surface_cr): reflection_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.wallpaper_width + self.wallpaper_frame_size * 2 + 2, self.reflection_height) reflection_surface_cr = gtk.gdk.CairoContext(cairo.Context(reflection_surface)) wallpaper_x = self.wallpaper_offset_x wallpaper_y = self.wallpaper_offset_y for (index, pixbuf) in enumerate(self.pixbufs): wallpaper_draw_x = wallpaper_x - 3 * self.wallpaper_render_offset + \ (len(self.pixbufs) - index) * self.wallpaper_render_offset wallpaper_draw_y = wallpaper_y + 3 * self.wallpaper_render_offset - \ (len(self.pixbufs) - index) * self.wallpaper_render_offset self.render_wallpaper(theme_surface_cr, pixbuf, wallpaper_draw_x, wallpaper_draw_y) if index == len(self.pixbufs) - 1: self.render_wallpaper(reflection_surface_cr, pixbuf, self.wallpaper_frame_size + 1, self.wallpaper_frame_size + 1, True) i = 0 while (i <= self.reflection_height): with cairo_state(theme_surface_cr): theme_surface_cr.rectangle( wallpaper_draw_x - self.wallpaper_frame_size - 1, wallpaper_draw_y + self.wallpaper_height + self.wallpaper_frame_size + i, self.wallpaper_width + self.wallpaper_frame_size * 2 + 2, 1) theme_surface_cr.clip() theme_surface_cr.set_source_surface( reflection_surface, wallpaper_draw_x - self.wallpaper_frame_size - 1, wallpaper_draw_y + self.wallpaper_frame_size + self.wallpaper_height ) theme_surface_cr.paint_with_alpha(1.0 - (math.sin(i * math.pi / 2 / self.reflection_height))) i += 1 # Paint wallpapers. cr.set_source_surface(theme_surface, rect.x, rect.y) cr.paint() ''' # Init window coordiante. window_frame_x = rect.x + self.window_frame_padding_x window_frame_y = rect.y + self.window_frame_padding_y # Paint gaussian area. gaussian_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.window_frame_width, self.window_frame_height) gaussian_surface_cr = gtk.gdk.CairoContext(cairo.Context(gaussian_surface)) gaussian_surface_cr.set_source_surface(theme_surface, -self.window_frame_padding_x, -self.window_frame_padding_y) gaussian_surface_cr.paint() dtk_cairo_blur.gaussian_blur(gaussian_surface, 3) cr.set_source_surface(gaussian_surface, window_frame_x, window_frame_y) cr.paint() # Draw window frame. cr.set_source_rgba(*alpha_color_hex_to_cairo((COLOR_NAME_DICT[self.theme.get_color()], 0.5))) cr.rectangle(window_frame_x + 1, window_frame_y, self.window_frame_width - 2, 1) cr.rectangle(window_frame_x, window_frame_y + 1, self.window_frame_width, self.window_frame_height - 2) cr.rectangle(window_frame_x + 1, window_frame_y + self.window_frame_height - 1, self.window_frame_width - 2, 1) cr.fill() draw_window_frame(cr, window_frame_x, window_frame_y, self.window_frame_width, self.window_frame_height, ui_theme.get_alpha_color("window_frame_outside_1"), ui_theme.get_alpha_color("window_frame_outside_2"), ui_theme.get_alpha_color("window_frame_outside_3"), ui_theme.get_alpha_color("window_frame_inside_1"), ui_theme.get_alpha_color("window_frame_inside_2"), ) ''' draw_text(cr, self.name, rect.x, rect.y + self.window_frame_padding_y + self.window_frame_height + self.title_padding_y, rect.width, DEFAULT_FONT_SIZE, self.title_size, alignment=pango.ALIGN_CENTER )