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


Python Context.rectangle方法代码示例

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


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

示例1: outline

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
 def outline(self, surface):
     border = Context(surface)
     border.rectangle(self.w / 64, self.w / 64, self.w - self.w / 32, self.h - self.w / 32 - 2)
     border.set_line_width(self.w / 32)
     border.set_source_rgb(0.1, 0.1, 0.1)
     border.set_line_join(rounded)
     border.stroke()
开发者ID:,项目名称:,代码行数:9,代码来源:

示例2: _draw_cell

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
    def _draw_cell(self, context: cairo.Context,
                   cell_value: CrucipixelCellValue, area: Rectangle):

        r, g, b = self.crucipixel_cell_value_to_color[cell_value]
        context.set_source_rgb(r, g, b)
        context.rectangle(area.start.x,
                          area.start.y,
                          area.width,
                          area.height)
        context.fill()
        if not self.victory_screen and cell_value == CrucipixelCellValue.EMPTY:
            # draw the X
            r, g, b = self.crucipixel_cell_value_to_color[
                CrucipixelCellValue.SELECTED
            ]
            context.set_source_rgb(r, g, b)
            context.set_line_cap(cairo.LINE_CAP_ROUND)
            delta_x = self.cell_width // 2.8
            delta_y = self.cell_height // 2.8
            context.move_to(area.start.x + area.width - delta_x,
                            area.start.y + delta_y)
            context.line_to(area.start.x + delta_x,
                            area.start.y + area.height - delta_y)
            context.move_to(area.start.x + area.width - delta_x,
                            area.start.y + area.width - delta_y)
            context.line_to(area.start.x + delta_x,
                            area.start.y + delta_y)
            context.stroke()
开发者ID:gcali,项目名称:crucipixel,代码行数:30,代码来源:grid.py

示例3: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):
        if not self.is_shape_set:
            self.layout(context)

        context.set_font_size(self.font_size)

        self.shape.draw_on_context(context)
        context.set_source_rgb(1, 1, 1)
        context.fill_preserve()
        context.set_source_rgb(0, 0, 0)
        context.stroke()
        shape = self.shape

        label = self.label
        if len(label) > 0 and label[-1] == ' ':
            label += '.'
        xb, yb, w, h, xa, ya = context.text_extents(label)
        context.rectangle(shape.start.x + self.padding,
                          shape.start.y,
                          shape.width - self.padding,
                          shape.height)
        context.clip()
        context.move_to(shape.start.x + (shape.width - self.padding - w)/2,
                        shape.start.y + shape.height - self.padding)
        context.show_text(self.label)
开发者ID:gcali,项目名称:crucipixel,代码行数:27,代码来源:input.py

示例4: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
 def on_draw(self, widget: Widget, context: cairo.Context):
     for child in self.list:
         if child.visible:
             context.save()
             context.transform(child.fromWidgetCoords)
             if child.is_clip_set():
                 rectangle = child.clip_rectangle
                 context.rectangle(rectangle.start.x,rectangle.start.y,
                                   rectangle.width,rectangle.height)
                 context.clip()
             child.on_draw(self,context)
             context.restore()
开发者ID:gcali,项目名称:crucipixel,代码行数:14,代码来源:containers.py

示例5: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
    def on_draw(self, widget: "Widget", context: cairo.Context):
        translation = 10, 10
        context.translate(*translation)
        self.contents.set_translate(*translation)
        self.navigator.set_translate(*translation)
        self.back_button.set_translate(*translation)
        up_margin = 4
        down_margin = 6
        left_margin = 4
        right_margin = self.navigator.width
        navigator_margin = 4
        base_x, base_y = self.fromWidgetCoords.transform_point(0, 0)
        base_x += translation[0]
        base_y += translation[1]
        width = self.container_size[0] - 2 * base_x - right_margin - 2 * navigator_margin
        height = self.container_size[1] - 2 * base_y - down_margin
        self.contents.set_max_size(width, height)
        self.contents.on_draw(widget, context)
        offset = self.contents.table_width + navigator_margin
        tot = len(self.contents.entries)
        if tot != 0:
            self.navigator.skip = self.contents.base / tot
        else:
            self.navigator.skip = 0
        if tot != 0:
            self.navigator.fill = self.contents._shown / tot
        else:
            self.navigator.fill = 1
        self.navigator.translate(offset, 0)
        context.translate(offset, 0)
        self.navigator.down_pos = self.contents.table_height
        self.navigator.on_draw(widget, context)
        context.translate(-offset, 0)
        rectangle_width = left_margin + offset + navigator_margin + right_margin
        rectangle_height = self.contents.table_height + up_margin + down_margin
        context.rectangle(
            -left_margin,
            -up_margin,
            rectangle_width,
            rectangle_height
        )
        context.stroke()

        button_left = (rectangle_width - left_margin) / 2
        button_left = 0
        button_left = rectangle_width - left_margin
        button_up = rectangle_height + up_margin

        self.back_button.translate(button_left, button_up)
        context.translate(button_left, button_up)
        self.back_button.on_draw(self, context)
开发者ID:gcali,项目名称:crucipixel,代码行数:53,代码来源:chooser_table.py

示例6: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):
        self.guide_line.set_shape_from_context(context)
        shape = self.guide_line.shape
        self.guide_line.set_translate(shape.width + 10, shape.height + 10)

        context.save()
        context.set_source_rgb(1, 1, 1)
        if self.guide_line.orientation == Orientation.HORIZONTAL:
            context.rectangle(10, shape.height + 10, shape.width, 20)
        else:
            context.rectangle(shape.width + 10, 10, 20, shape.height)
        context.fill()
        context.restore()

        super().on_draw(widget, context)
开发者ID:gcali,项目名称:crucipixel,代码行数:17,代码来源:guides.py

示例7: _highlight_border

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
    def _highlight_border(self, context: cairo.Context, row: int, col: int):
        width = self._total_width
        height = self._total_height

        line_width = 3
        row_rectangles = [
            Rectangle(
                Point(1, row * self.cell_height - line_width / 2),
                width - 2,
                line_width
            ),
            Rectangle(
                Point(1, (row + 1) * self.cell_height - line_width / 2),
                width - 2,
                line_width
            )
        ]
        col_rectangles = [
            Rectangle(
                Point(col * self.cell_width - line_width / 2, 1),
                line_width,
                height - 2
            ),
            Rectangle(
                Point((col + 1) * self.cell_width - line_width / 2, 1),
                line_width,
                height - 2
            )
        ]
        context.save()
        r, g, b = self.highlight_color
        context.set_source_rgba(r, g, b, .6)
        for row_rectangle in row_rectangles:
            context.rectangle(row_rectangle.start.x,
                              row_rectangle.start.y,
                              row_rectangle.width,
                              row_rectangle.height)
            context.fill()
        for col_rectangle in col_rectangles:
            context.rectangle(col_rectangle.start.x,
                              col_rectangle.start.y,
                              col_rectangle.width,
                              col_rectangle.height)
            context.fill()
        context.restore()
开发者ID:gcali,项目名称:crucipixel,代码行数:47,代码来源:grid.py

示例8: renderText

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
 def renderText(self, surface,
                text, y_offset, size,
                shade, w=(2,3), wrap=True):
     if len(text) < 1:
         return
     def setdesc(l, size):
         l.set_font_description(
                 FontDescription(
                     self.font + " " + str(size)))
     origin = Context(surface)
     origin.translate(self.w * (w[1] - w[0]) /
                      (w[1] * 2), y_offset)
     box = CairoContext(origin)
 #  Start laying out text 
     layout = box.create_layout()
     setdesc(layout, size)
     width = self.w * w[0] / w[1]
     if wrap:
         layout.set_width(width * pango.SCALE)
     else:
         layout.set_width(-1)
     layout.set_alignment(pango.ALIGN_CENTER)
     layout.set_text(text)
 #   Resize text to make sure it doesn't exceed width.
     wi, n = layout.get_pixel_size()
     if wi > width:
         s = size * width / wi
         setdesc(layout, s)
     layout.set_width(width * pango.SCALE)
 #   Draw a transparent pane behind the text
     origin.set_source_rgba(1, 1, 1, 0.7)
     origin.rectangle(*layout.get_pixel_extents()[1])
     origin.fill()
 #   Draw text
     origin.set_source_rgb(shade, shade, shade)
     box.update_layout(layout)
     box.show_layout(layout)
开发者ID:,项目名称:,代码行数:39,代码来源:

示例9: ImageSurface

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
            ctx.paint()
        pen.x += face.glyph.advance.x
        pen.y += face.glyph.advance.y

    L.flush()
    return L


if __name__ == '__main__':
    from PIL import Image

    n_words = 200
    H, W, dpi = 600, 800, 72.0
    I = ImageSurface(FORMAT_A8, W, H)
    ctxI = Context(I)
    ctxI.rectangle(0,0,800,600)
    ctxI.set_source_rgba (0.9, 0.9, 0.9, 0)
    ctxI.fill()
    S = random.normal(0,1,n_words)
    S = (S-S.min())/(S.max()-S.min())
    S = sort(1-sqrt(S))[::-1]
    sizes = (12 + S*48).astype(int).tolist()

    def spiral():
        eccentricity = 1.5
        radius = 8
        step = 0.1
        t = 0
        while True:
            t += step
            yield eccentricity*radius*t*cos(t), radius*t*sin(t)
开发者ID:moyogo,项目名称:freetype-py,代码行数:33,代码来源:wordle-cairo.py

示例10: make_image_surface

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
    widthZ, rowsZ, pitch = bitmap.width, bitmap.rows, bitmap.pitch
    Z = make_image_surface(bitmap)

    # Plain
    flags = FT_LOAD_RENDER
    face.load_char('S', flags)
    bitmap = face.glyph.bitmap
    widthF, rowsF, pitch = bitmap.width, bitmap.rows, bitmap.pitch
    F = make_image_surface(bitmap)

    # Draw
    surface = ImageSurface(FORMAT_ARGB32, 1200, 500)
    ctx = Context(surface)

    # fill background as gray
    ctx.rectangle(0,0,1200,500)
    ctx.set_source_rgb (0.5 , 0.5, 0.5)
    ctx.fill()

    # use the stroked font's size as scale, as it is likely slightly larger
    scale = 400.0 / rowsZ

    # draw bitmap first
    ctx.set_source_surface(F, 0, 0)
    patternF = ctx.get_source()
    SurfacePattern.set_filter(patternF, FILTER_BEST)

    scalematrix = Matrix()
    scalematrix.scale(1.0/scale,1.0/scale)
    scalematrix.translate(-(600.0 - widthF *scale /2.0 ), -50)
    patternF.set_matrix(scalematrix)
开发者ID:moyogo,项目名称:freetype-py,代码行数:33,代码来源:glyph-color-cairo.py

示例11: main

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]
def main(marker, paper, format, bbox, emergency, place, recipient, sender, text, sender_is_recipient, map_href):
    """
    """
    mark = Location(*marker)
    
    handle, filename = mkstemp(prefix='safetymap-', suffix='.pdf')
    close(handle)

    if paper == 'a4':
        surf = PDFSurface(filename, 210*ptpmm, 297*ptpmm)
    
    elif paper == 'letter':
        surf = PDFSurface(filename, 8.5*ptpin, 11*ptpin)
    
    ctx = Context(surf)
    
    ctx.scale(ptpmm, ptpmm)

    set_font_face_from_file(ctx, 'assets/HelveticaNeue.ttc')
    
    if paper == 'a4':
        draw_a4_master(ctx, format, map_href)
        ctx.translate(19, 24)
    
    elif paper == 'letter':
        draw_letter_master(ctx, format, map_href)
        ctx.translate(21, 18)

    ctx.set_line_width(.25 * mmppt)
    ctx.set_source_rgb(*md_gray)
    ctx.set_dash([3 * mmppt])

    reps = {'4up': 4, '2up-fridge': 2, 'poster': 0}
    
    if reps[format]:
        card_img, mark_point = get_map_image(bbox, 84, 39, mark)
        
    for i in range(reps[format]):
    
        # dashed outlines
        ctx.move_to(0, 61)
        ctx.line_to(0, 0)
        ctx.line_to(173, 0)
        ctx.line_to(173, 61)
        #ctx.move_to(86, 0)
        #ctx.line_to(86, 61)
        ctx.stroke()
    
        # two card sides and contents
        draw_card_left(ctx, recipient, sender, text, sender_is_recipient)
        ctx.translate(86.5, 0)

        draw_card_right(ctx, card_img, mark_point, emergency, place)
        ctx.translate(-86.5, 61)

    if format == '4up':
        # bottom dashed outline
        ctx.move_to(0, 0)
        ctx.line_to(172, 0)
        ctx.stroke()

    elif format == '2up-fridge':
        # prepare to draw sideways
        ctx.translate(0, 122.5)
        ctx.rotate(-pi/2)

        ctx.rectangle(0, 0, 122.5, 173)
        ctx.stroke()

        poster_img, mark_point = get_map_image(bbox, 109, 77, mark)
        draw_small_poster(ctx, poster_img, mark_point, emergency, place, recipient, sender, text, sender_is_recipient)

    elif format == 'poster':
        ctx.rectangle(0, 0, 173, 245)
        ctx.stroke()

        poster_img, mark_point = get_map_image(bbox, 153, 108, mark)
        draw_large_poster(ctx, poster_img, mark_point, emergency, place, recipient, sender, text, sender_is_recipient)

    surf.finish()
    chmod(filename, 0644)
    return filename
开发者ID:DEKOR01,项目名称:safetymaps,代码行数:84,代码来源:compose.py

示例12: do_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [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

示例13: _paint_panel

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import rectangle [as 别名]

#.........这里部分代码省略.........
                    ctx.set_source_rgb(0, 0, 0)
                    num = d_i.strftime("%d-%m-%Y %H")

                    x -= (int(d_i.strftime("%H")) * 3600 - tz) / kx

                    tw, th = ctx.text_extents(num)[2:4]
                    tx = x - tw // 2
                    ctx.move_to(tx, height - bottom + th + 5)
                    if tx - tx_prev > tw:
                        ctx.show_text(num)
                        tx_prev = tx
                        ctx.set_source_rgb(*(color_y_line_date))
                    else:
                        ctx.set_source_rgb(*(color_y_line))
                    if x >= left and x < width:
                        ctx.move_to(x, 0)
                        ctx.line_to(x, height - bottom)
                        ctx.stroke()
                    sc = space_count
                sc -= 1
        except Exception as e:
            pass

        # Рисуем верхний и правый бордер

        ctx.set_source_rgb(*color_border)
        ctx.move_to(left, 0)
        ctx.line_to(width, 0)
        ctx.line_to(width, height - bottom)
        ctx.stroke()

        # Рисуем сами графики

        ctx.rectangle(left, 0, width - left, height)
        ctx.clip()

        is_first = True
        currVarID = -1
        prevX = -1

        if typ == 0:  # Линейная
            for ind in range(4):
                """
                if len(chart_data[ind]) > 0:
                    for i in range(len(chart_data[ind]) - 1):
                        chart_data[ind][i] = list(chart_data[ind][i])
                        r1 = chart_data[ind][i]
                        r2 = chart_data[ind][i + 1]
                        chart_data[ind][i][0] += (r2[0] - r1[0]) / 2
                        chart_data[ind][i][1] += (r2[1] - r1[1]) / 2
                """
                ctx.set_source_rgb(*colors[ind])
                is_first = True
                for row in chart_data[ind]:
                    x = (row[0] - min_x) / kx + left
                    y = height - bottom - (row[1] - min_y) / ky

                    if is_first:
                        ctx.move_to(x, y)
                    else:
                        if row[0] - prevX > 10000:
                            ctx.move_to(x, y)
                        else:
                            ctx.line_to(x, y)

                    prevX = row[0]
开发者ID:SolitonNew,项目名称:pyhome,代码行数:70,代码来源:page5_1.py


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