本文整理汇总了Python中cairo.Context.restore方法的典型用法代码示例。如果您正苦于以下问题:Python Context.restore方法的具体用法?Python Context.restore怎么用?Python Context.restore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.restore方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
context.save()
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()
context.restore()
super().on_draw(widget, context)
示例2: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [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()
示例3: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
context.save()
context.set_source_rgb(*self.background_color)
self.shape.draw_on_context(context)
context.fill_preserve()
context.set_source_rgb(0,0,0)
context.set_line_width(1)
context.stroke()
context.restore()
super().on_draw(widget, context)
示例4: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
for b in self._buttons:
b.set_shape_from_context(context)
shapes = [b.shape for b in self._buttons]
context.save()
context.select_font_face("", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
xb, yb, w, h, xa, ya = context.text_extents(self.title)
width = max(shape.width for shape in shapes)
width = max(width, xa)
container_width = self.container_size[0]
translation = Point(0, self.distance)
if container_width > width:
translation += Point((container_width)/2, 0)
else:
translation += Point(width/2, 0)
context.move_to(translation.x - xa/2, h + 2 * self.distance)
context.show_text(self.title)
context.restore()
height = h + self.distance * 3
for b in self._buttons:
height += b.shape.height + self.distance
self.min_size = width + 2 * self.distance, height + self.distance
start_point = context.get_current_point()
translation += Point(0, h + self.distance * 3)
context.translate(translation.x, translation.y)
distance_offset = Point(0, self.distance)
for b in self._buttons:
context.move_to(*start_point)
b.set_translate(translation.x, translation.y)
context.save()
b.on_draw(widget, context)
context.restore()
to_translate = Point(distance_offset.x,
distance_offset.y + b.shape.height)
context.translate(to_translate.x, to_translate.y)
translation += to_translate
示例5: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [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)
示例6: layout
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
def layout(self, context: cairo.Context):
if not self.is_shape_set:
context.save()
context.set_font_size(self.font_size)
generator = (context.text_extents(chr(letter) * 10)
for letter in range(ord('A'), ord('Z') + 1))
context.restore()
sizes = [(xa, h) for xb, yb, w, h, xa, ya in generator]
max_height = 0
for w, h in sizes:
max_height = max(h, max_height)
width = self.width
height = self.padding * 3 + max_height
self.shape = DrawableRectangle(Point(0, 0), width, height)
示例7: MapSurface
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
class MapSurface(object):
"""wrapper to render the map to svg/png"""
def __init__(self, hexmap=None, filename=None, width=None, height=None, size=None):
self.hexmap = hexmap
if self.hexmap is None:
raise ValueError("No map was passed to {}".format(self.__class__.__name__))
self.surface_name = filename or "test.svg"
self.size = size or 32.0
self.surface_width = width
if self.surface_width is None:
self.surface_width = (self.hexmap.map.cols + .5) * self.size * SQRT3
self.surface_height = height
if self.surface_height is None:
self.surface_height = (self.hexmap.map.rows * 1.5 + .25) * self.size
self.layer = []
# build base map
self.surface = SVGSurface(self.surface_name + ".svg", self.surface_width, self.surface_height)
self.context = Context(self.surface)
# background: magenta
self.context.save()
self.context.set_source_rgb(1.0, 0.0, 1.0)
self.context.paint()
self.context.restore()
def add_layer(self, renderer_cls, position=None):
if not position:
self.layer.append(renderer_cls(self))
else:
self.layer.insert(position, renderer_cls(self))
def render(self):
print "Rendering {} ({}x{})".format(self.surface_name, self.surface_width, self.surface_height)
for renderer in self.layer:
renderer.render()
def finalise(self, with_png=False):
print "finalising:"
if with_png is True:
print "PNG"
self.surface.write_to_png(self.surface_name + ".png")
print "SVG"
self.surface.finish()
print "DONE!"
示例8: _highlight_border
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [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()
示例9: layout
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
def layout(self, context: cairo.Context):
super().layout(context)
context.save()
self.__plus_button.layout(context)
context.restore()
self.__minus_button.min_height = self.__plus_button.shape.height
context.save()
self.__minus_button.layout(context)
context.restore()
plus_shape = self.__plus_button.shape
minus_shape = self.__minus_button.shape
self.__minus_button.set_translate(self.padding, self.padding/2)
self.__plus_button.set_translate(
self.padding + minus_shape.width + self.padding,
self.padding/2
)
self.shape = DrawableRectangle(
Point(0, 0),
plus_shape.width + minus_shape.width + 3 * self.padding,
self.padding + max(plus_shape.height, minus_shape.height)
)
示例10: layout
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
def layout(self, context: cairo.Context):
for child in self.list:
if child.visible:
context.save()
child.layout(context)
context.restore()
示例11: elif
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
i += 1
elif (CODES[i] == CURVE3):
ctx.curve_to(VERTS[i][0],VERTS[i][1],
VERTS[i+1][0],VERTS[i+1][1], # undocumented
VERTS[i+1][0],VERTS[i+1][1])
i += 2
elif (CODES[i] == CURVE4):
ctx.curve_to(VERTS[i][0],VERTS[i][1],
VERTS[i+1][0],VERTS[i+1][1],
VERTS[i+2][0],VERTS[i+2][1])
i += 3
ctx.fill_preserve()
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(6)
ctx.stroke()
ctx.restore()
scale2 = (height_s - 2.0 * MARGIN)/rows
ctx.set_source_surface(Z, 0, 0)
pattern = ctx.get_source()
SurfacePattern.set_filter(pattern, FILTER_BEST)
scalematrix = Matrix()
scalematrix.scale(1.0/scale2, 1.0/scale2)
scalematrix.translate(-( width_s/2.0 - width *scale2 /2.0 ), -MARGIN)
pattern.set_matrix(scalematrix)
ctx.set_source_rgba (0, 0, 0, 0.7)
ctx.mask(pattern)
ctx.fill()
示例12: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import restore [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
self.min_size = 200, 150
super().on_draw(widget, context)
context.save()
context.set_font_size(self.font_size)
if self._table_extents is None:
self._update_table_extents(context)
skip = max(self.skip, 0)
how_many = self.how_many
table_extents = self._table_extents
title_extents = self._table_extents.title_extents
expected_height = title_extents.total_height + self.margin
entries = self.entries
base = skip
up_to = skip
over = False
while up_to < len(entries) and not over:
expected_height += table_extents[up_to].total_height
over = expected_height >= self._max_height
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()
#.........这里部分代码省略.........