def draw(self, da, ctx: cairo.Context): print('ok') print(pixbuf) Gdk.cairo_set_source_pixbuf(ctx, pixbuf, 0, 0) ctx.paint() ctx.set_source_rgb(255, 0, 0) ctx.set_line_width(SIZE / 4) ctx.set_tolerance(0.1) ctx.set_line_join(cairo.LINE_JOIN_ROUND) ctx.set_dash([SIZE / 4.0, SIZE / 4.0], 0) self.stroke_shapes(ctx, 0, 0) ctx.get_target().write_to_png('./a.png') return True
def glyphs(*args, **kwargs): options = Options(infname='data/vorttest.txt', saveas='output/part1/', outfname='vorttest.png', scale=100., seed_num=20, stepsize=.01, steps=5, directions=1, norm=False, line_width=.5) options.update(kwargs) print >> log, options.infname if not path.exists(options.saveas): os.makedirs(options.saveas) (xmin, ymin), (xmax, ymax), uv = read2vecs(options.infname) width, height = xmax - xmin, ymax - ymin def index2world(points, xmin=xmin, ymin=ymin, scale=options.scale, debug=False): if debug: print "index2world:", print xscale, yscale, points.dtype if debug: print points, points[:,0] -= xmin if debug: print points, points[:,1] -= ymin if debug: print points, points *= scale if debug: print points if 'seed' in options: seed = options.seed else: seed = product(np.linspace(xmin, xmax, num=options.seed_num), np.linspace(ymin, ymax, num=options.seed_num)) ctx = Context(ImageSurface(cairo.FORMAT_ARGB32, int(options.scale * width), int(options.scale * height))) ctx.set_source_rgba(0,0,0) ctx.set_line_width(options.line_width) for s in seed: points = sline(uv, (xmin, ymin), (xmax, ymax), np.array(s), options.stepsize, options.steps, options.norm, options.directions) print >> log, points index2world(points) print >> log, points draw_arrow(ctx, points, arrowhead_size=2) with open(path.join(options.saveas, options.outfname), 'w') as outf: ctx.get_target().write_to_png(outf)
def do_draw(self, context: cairo.Context) -> bool: if not self.adjustment or self.adjustment.get_upper() <= 0: return False height = self.get_allocated_height() width = self.get_allocated_width() if width <= 0 or height <= 0: return False base_bg, base_outline, handle_overdraw, handle_outline = ( self.get_map_base_colors()) x0 = self.overdraw_padding + 0.5 x1 = width - 2 * x0 height_scale = height * self.get_height_scale() if self._cached_map is None: surface = cairo.Surface.create_similar(context.get_target(), cairo.CONTENT_COLOR_ALPHA, width, height) cache_ctx = cairo.Context(surface) cache_ctx.set_line_width(1) cache_ctx.rectangle(x0, -0.5, x1, height_scale + 0.5) cache_ctx.set_source_rgba(*base_bg) cache_ctx.fill() # We get drawing coordinates by tag to minimise our source # colour setting, and make this loop slightly cleaner. tagged_diffs = self.chunk_coords_by_tag() for tag, diffs in tagged_diffs.items(): cache_ctx.set_source_rgba(*self.fill_colors[tag]) for y0, y1 in diffs: y0 = round(y0 * height_scale) + 0.5 y1 = round(y1 * height_scale) - 0.5 cache_ctx.rectangle(x0, y0, x1, y1 - y0) cache_ctx.fill_preserve() cache_ctx.set_source_rgba(*self.line_colors[tag]) cache_ctx.stroke() cache_ctx.rectangle(x0, -0.5, x1, height_scale + 0.5) cache_ctx.set_source_rgba(*base_outline) cache_ctx.stroke() self._cached_map = surface context.set_source_surface(self._cached_map, 0, 0) context.paint() # Draw our scroll position indicator context.set_line_width(1) context.set_source_rgba(*handle_overdraw) adj_y = self.adjustment.get_value() / self.adjustment.get_upper() adj_h = self.adjustment.get_page_size() / self.adjustment.get_upper() context.rectangle( x0 - self.overdraw_padding, round(height_scale * adj_y) + 0.5, x1 + 2 * self.overdraw_padding, round(height_scale * adj_h) - 1, ) context.fill_preserve() context.set_source_rgba(*handle_outline) context.stroke() return True
def do_draw(self, context: cairo.Context) -> bool: if not self.adjustment or self.adjustment.get_upper() <= 0: return False height = self.get_allocated_height() width = self.get_allocated_width() if width <= 0 or height <= 0: return False base_bg, base_outline, handle_overdraw, handle_outline = ( self.get_map_base_colors()) x0 = self.overdraw_padding + 0.5 x1 = width - 2 * x0 height_scale = height * self.get_height_scale() if self._cached_map is None: surface = cairo.Surface.create_similar( context.get_target(), cairo.CONTENT_COLOR_ALPHA, width, height) cache_ctx = cairo.Context(surface) cache_ctx.set_line_width(1) cache_ctx.rectangle(x0, -0.5, x1, height_scale + 0.5) cache_ctx.set_source_rgba(*base_bg) cache_ctx.fill() # We get drawing coordinates by tag to minimise our source # colour setting, and make this loop slightly cleaner. tagged_diffs = self.chunk_coords_by_tag() for tag, diffs in tagged_diffs.items(): cache_ctx.set_source_rgba(*self.fill_colors[tag]) for y0, y1 in diffs: y0 = round(y0 * height_scale) + 0.5 y1 = round(y1 * height_scale) - 0.5 cache_ctx.rectangle(x0, y0, x1, y1 - y0) cache_ctx.fill_preserve() cache_ctx.set_source_rgba(*self.line_colors[tag]) cache_ctx.stroke() cache_ctx.rectangle(x0, -0.5, x1, height_scale + 0.5) cache_ctx.set_source_rgba(*base_outline) cache_ctx.stroke() self._cached_map = surface context.set_source_surface(self._cached_map, 0, 0) context.paint() # Draw our scroll position indicator context.set_line_width(1) context.set_source_rgba(*handle_overdraw) adj_y = self.adjustment.get_value() / self.adjustment.get_upper() adj_h = self.adjustment.get_page_size() / self.adjustment.get_upper() context.rectangle( x0 - self.overdraw_padding, round(height_scale * adj_y) + 0.5, x1 + 2 * self.overdraw_padding, round(height_scale * adj_h) - 1, ) context.fill_preserve() context.set_source_rgba(*handle_outline) context.stroke() return True