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()
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)
order='C', strides=[I.get_stride(), 4]) except NotImplementedError: raise SystemExit( "For python 3.x, you need pycairo >= 1.11+ (from https://github.com/pygobject/pycairo)" ) # 255 * 2**24 = opaque ndI[:, :] = 255 * 2**24 + ndR[:, :] * 2**16 + ndG[:, :] * 2**8 + ndB[:, :] I.mark_dirty() surface = ImageSurface(FORMAT_ARGB32, 800, 600) ctx = Context(surface) ctx.set_source_surface(I, 0, 0) pattern = ctx.get_source() SurfacePattern.set_filter(pattern, FILTER_BEST) scale = 480.0 / rows scalematrix = Matrix() scalematrix.scale(1.0 / scale, 1.0 / scale) scalematrix.translate(-(400.0 - width * scale / 2.0) + 200, -60) pattern.set_matrix(scalematrix) ctx.paint() # we need this later for shifting the taller LCD_V glyph up. rows_old = rows # LCD_V face.load_char('S', FT_LOAD_RENDER | FT_LOAD_TARGET_LCD_V) bitmap = face.glyph.bitmap width = face.glyph.bitmap.width rows = face.glyph.bitmap.rows // 3
try: ndI = ndarray(shape=(rows,width), buffer=I.get_data(), dtype=uint32, order='C', strides=[I.get_stride(), 4]) except NotImplementedError: raise SystemExit("For python 3.x, you need pycairo >= 1.11+ (from https://github.com/pygobject/pycairo)") # 255 * 2**24 = opaque ndI[:,:] = 255 * 2**24 + ndR[:,:] * 2**16 + ndG[:,:] * 2**8 + ndB[:,:] I.mark_dirty() surface = ImageSurface(FORMAT_ARGB32, 800, 600) ctx = Context(surface) ctx.set_source_surface(I, 0, 0) pattern = ctx.get_source() SurfacePattern.set_filter(pattern, FILTER_BEST) scale = 480.0 / rows scalematrix = Matrix() scalematrix.scale(1.0/scale,1.0/scale) scalematrix.translate(-(400.0 - width *scale /2.0 )+200, -60) pattern.set_matrix(scalematrix) ctx.paint() # we need this later for shifting the taller LCD_V glyph up. rows_old = rows # LCD_V face.load_char('S', FT_LOAD_RENDER | FT_LOAD_TARGET_LCD_V ) bitmap = face.glyph.bitmap width = face.glyph.bitmap.width