class Icon(Widget): def __init__(self, w=10, h=10, path=''): self._w, self._h = w, h surface = ImageSurface.create_from_png(path) self._imgpat = SurfacePattern(surface) self._imgpat.set_filter(FILTER_BEST) scaler = Matrix() scaler.scale(surface.get_width() / w, surface.get_height() / h) self._imgpat.set_matrix(scaler) def bounding_box(self): return self._w + 2, self._h def render(self, ctx, w, h): ctx.set_source(self._imgpat) ctx.paint()