def get_default_window_icon(self): #return the icon which would be used from the wmclass c_i = self.get_property("class-instance") if not c_i or len(c_i)!=2: return None wmclass_name, wmclass_class = [x.encode("utf-8") for x in c_i] iconlog("get_default_window_icon() using %s", (wmclass_name, wmclass_class)) if not wmclass_name: return None it = gtk.icon_theme_get_default() p = None for fmt in ("%s-color", "%s", "%s_48x48", "application-x-%s", "%s-symbolic", "%s.symbolic"): icon_name = fmt % wmclass_name i = it.lookup_icon(icon_name, 48, 0) iconlog("%s.lookup_icon(%s)=%s", it, icon_name, i) if not i: continue p = i.load_icon() iconlog("%s.load_icon()=%s", i, p) if p: break if p is None: return None #to make it consistent with the "icon" property, #return a cairo surface.. surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, p.get_width(), p.get_height()) gc = gdk.CairoContext(cairo.Context(surf)) gc.set_source_pixbuf(p, 0, 0) gc.paint() iconlog("get_default_window_icon()=%s", surf) return surf
def draw_days(self, widget, event, context): if self.__cache_surface is None: self.__cache_surface = context.get_target().create_similar( cairo.CONTENT_COLOR_ALPHA, event.area.width, event.area.height) cache_context = gdk.CairoContext( cairo.Context(self.__cache_surface)) text_color = widget.get_style().fg[gtk.STATE_PRELIGHT] # Draw days for xpos, ypos, day in zip(self.xPositions, self.yPositions, self.forecast["DAYS"]): self.drawSingleDay(cache_context, xpos, ypos, day, text_color) cache_context.set_source_rgb(text_color.red / 65535.0, text_color.green / 65535.0, text_color.blue / 65535.0) descStr = _("Weather data provided by weather.com") width = cache_context.text_extents(descStr)[2:4][0] xpos = event.area.width / 2.0 - width / 2.0 cache_context.move_to(xpos, 145) cache_context.show_text(descStr) context.set_operator(cairo.OPERATOR_OVER) context.set_source_surface(self.__cache_surface) context.paint()
def gdkpixbuf_loader(file_obj, string): """Load raster images with gdk-pixbuf through PyGTK.""" pixbuf = get_pixbuf(file_obj, string) dummy_context = cairo.Context(DUMMY_SURFACE) gdk.CairoContext(dummy_context).set_source_pixbuf(pixbuf, 0, 0) pattern = dummy_context.get_source() result = pattern, pixbuf.get_width(), pixbuf.get_height() return lambda: result