本文整理汇总了Python中cairo.Context.fill方法的典型用法代码示例。如果您正苦于以下问题:Python Context.fill方法的具体用法?Python Context.fill怎么用?Python Context.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.fill方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_cell
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [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()
示例2: __init__
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [as 别名]
class Canvas:
def __init__(self, width, height):
self.xform = lambda x, y: (x, y)
self.img = ImageSurface(FORMAT_RGB24, width, height)
self.ctx = Context(self.img)
self.ctx.move_to(0, 0)
self.ctx.line_to(width, 0)
self.ctx.line_to(width, height)
self.ctx.line_to(0, height)
self.ctx.line_to(0, 0)
self.ctx.set_source_rgb(1, 1, 1)
self.ctx.fill()
self.width = width
self.height = height
def fit(self, left, top, right, bottom):
xoff = left
yoff = top
xscale = self.width / float(right - left)
yscale = self.height / float(bottom - top)
if abs(xscale) > abs(yscale):
xscale *= abs(yscale) / abs(xscale)
elif abs(xscale) < abs(yscale):
yscale *= abs(xscale) / abs(yscale)
self.xform = lambda x, y: ((x - xoff) * xscale, (y - yoff) * yscale)
def dot(self, x, y, size=4, fill=(.5, .5, .5)):
x, y = self.xform(x, y)
self.ctx.arc(x, y, size/2., 0, 2*pi)
self.ctx.set_source_rgb(*fill)
self.ctx.fill()
def line(self, points, stroke=(.5, .5, .5), width=1):
self.ctx.move_to(*self.xform(*points[0]))
for (x, y) in points[1:]:
self.ctx.line_to(*self.xform(x, y))
self.ctx.set_source_rgb(*stroke)
self.ctx.set_line_cap(LINE_CAP_ROUND)
self.ctx.set_line_width(width)
self.ctx.stroke()
def save(self, filename):
self.img.write_to_png(filename)
示例3: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [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)
示例4: _highlight_border
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [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()
示例5: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
start_x, start_y = context.get_current_point()
context.set_font_size(self.font_size)
context.move_to(0, 0)
if not self.is_shape_set:
self.set_shape_from_context(context)
shape = self.shape
start = shape.start
padding = self.padding
h = shape.height - 2 * padding
label = self.label
context.set_source_rgb(*self.background_color)
shape.draw_on_context(context)
context.fill_preserve()
context.set_line_width(1)
context.set_source_rgb(*self.label_color)
context.stroke()
if self.disabled:
context.set_source_rgba(1, 1, 1, .7)
context.move_to(start.x + padding-1,
start.y + padding + h+1)
context.show_text(label)
context.set_source_rgba(*self.label_color, .9)
else:
context.set_source_rgb(*self.label_color)
context.move_to(start.x + padding,
start.y + padding + h)
context.show_text(label)
if self.disabled:
context.set_source_rgba(1, 1, 1, .7)
context.move_to(0, 0)
shape.draw_on_context(context)
context.fill()
示例6: renderText
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [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)
示例7: ImageSurface
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [as 别名]
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)
drawn_regions = Region()
示例8: range
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [as 别名]
ctx.fill_preserve()
ctx.set_source_rgb(0,1,0)
ctx.stroke()
start, end = 0, 0
for i in range(len(outline.contours)):
end = outline.contours[i]
ctx.new_path()
ctx.set_source_rgb(0,0,1)
for j in range(start, end+1):
if ( Curve_Tag[j] == FT_Curve_Tag_On ):
point = outline.points[j]
ctx.move_to(point[0],point[1])
ctx.arc(point[0], point[1], 40, 0, 2 * math.pi)
ctx.fill()
ctx.new_path()
ctx.set_source_rgb(1,0,0)
for j in range(start, end+1):
if ( Curve_Tag[j] != FT_Curve_Tag_On ):
point = outline.points[j]
ctx.move_to(point[0],point[1])
ctx.arc(point[0], point[1], 10, 0, 2 * math.pi)
ctx.fill()
points = outline.points[start:end+1]
points.append(points[0])
tags = outline.tags[start:end+1]
tags.append(tags[0])
示例9: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [as 别名]
#.........这里部分代码省略.........
if not over:
up_to += 1
while base > 0 and not over:
expected_height += table_extents[base-1].total_height
over = expected_height >= self._max_height
if not over:
base -= 1
how_many = up_to - base
skip = base
self.base = base
entries = self.entries[skip:skip + how_many]
def table_extents_iterator():
return table_extents.iter_over(
skip, how_many
)
start_x, start_y = context.get_current_point()
start_y += title_extents.total_height
h = title_extents.total_height
self.title_height = h
for (index, cell), data in zip(enumerate(title_extents), self.title):
context.save()
offset = title_extents.get_cell_data_left(index)
context.rectangle(start_x + offset, start_y - h, cell.width, 2*h)
context.clip()
context.move_to(
start_x + offset,
start_y
)
context.show_text(data)
context.restore()
# start_y += self.margin
curr_x, curr_y = start_x, start_y# + title_extents.total_height
for line_index, (line_extent, entry) in enumerate(zip(table_extents_iterator(), entries)):
h = line_extent.total_height
curr_y += h
if curr_y + self.margin >= self._max_height:
break
for (cell_index, cell), data in zip(enumerate(line_extent), entry):
context.save()
offset = line_extent.get_cell_data_left(cell_index)
context.rectangle(curr_x + offset, curr_y - h, cell.width, 2*h)
context.clip()
context.move_to(
curr_x + offset,
curr_y
)
context.show_text(data)
context.restore()
curr_x = start_x
end_x = table_extents.entries_width
curr_y = start_y + self.margin
end_y = table_extents.get_height_up_to(skip, how_many) + start_y + self.margin + 1
self.table_height = end_y
self.table_width = end_x
for line in table_extents_iterator():
context.move_to(curr_x, curr_y)
context.line_to(end_x, curr_y)
context.stroke()
curr_y += line.total_height
context.move_to(curr_x, curr_y)
context.line_to(end_x, curr_y)
context.stroke()
curr_x = start_x
curr_y = start_y - 1 + self.margin
if self._how_many > 0:
line = table_extents[0]
for cell in line:
context.move_to(curr_x, curr_y)
context.line_to(curr_x, end_y)
context.stroke()
curr_x += cell.total_width + 2 * self.margin
context.move_to(curr_x, curr_y)
context.line_to(curr_x, end_y)
context.stroke()
if self._to_highlight is not None:
r, g, b = global_constants.highlight
context.set_source_rgba(r, g, b, .6)
index = self._to_highlight
base = start_y + table_extents.get_height_up_to(skip, index) + self.margin
h = table_extents.get_height_of(skip, how_many, index)
context.rectangle(start_x, base, table_extents.entries_width, h)
context.fill()
context.restore()
self._shown = how_many
示例10: _paint_panel
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import fill [as 别名]
#.........这里部分代码省略.........
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]
is_first = False
ctx.stroke()
elif typ == 1: # Точечная
for ind in range(4):
if chart_data[ind]:
ctx.set_source_rgb(*colors[ind])
for row in chart_data[ind]:
x = (row[0] - min_x) / kx + left
y = height - bottom - (row[1] - min_y) / ky
ctx.rectangle(x - 3, y - 3, 6, 6)
ctx.fill()
elif typ == 2: # Столбчатая
cy = height - bottom - (-min_y) / ky
for ind in range(4):
for row in chart_data[ind]:
if currVarID != row[2]:
ctx.fill()
for i in range(4):
if series[i] == row[2]:
ctx.set_source_rgb(*colors[i])
x = (row[0] - min_x) / kx + left
y = height - bottom - (row[1] - min_y) / ky
ctx.rectangle(x - 5, y, 10, cy - y)
currVarID = row[2]
ctx.fill()
else: # Линейчастая
# one_vals = self._get_one_val(series, min_x_q, max_x_q)
one_vals = self._get_one_val(series, x_min_max_values, min_x_q, max_x_q)
for ind in range(4):
if series[ind]:
is_now = True
for r in one_vals[ind]:
if r[4] == 1:
chart_data[ind].insert(0, r)
else:
chart_data[ind] += [r]
is_now = False
if is_now:
if len(chart_data[ind]) > 0:
r = list(chart_data[ind][len(chart_data[ind]) - 1])
r[0] = datetime.datetime.now().timestamp()