当前位置: 首页>>代码示例>>Python>>正文


Python Context.get_target方法代码示例

本文整理汇总了Python中cairo.Context.get_target方法的典型用法代码示例。如果您正苦于以下问题:Python Context.get_target方法的具体用法?Python Context.get_target怎么用?Python Context.get_target使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cairo.Context的用法示例。


在下文中一共展示了Context.get_target方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: glyphs

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import get_target [as 别名]
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)
开发者ID:damonwang,项目名称:scivis-proj4,代码行数:52,代码来源:proj4.py

示例2: do_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import get_target [as 别名]
    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
开发者ID:GNOME,项目名称:meld,代码行数:66,代码来源:chunkmap.py


注:本文中的cairo.Context.get_target方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。