本文整理匯總了Python中cairo.Context.get_current_point方法的典型用法代碼示例。如果您正苦於以下問題:Python Context.get_current_point方法的具體用法?Python Context.get_current_point怎麽用?Python Context.get_current_point使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cairo.Context
的用法示例。
在下文中一共展示了Context.get_current_point方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: on_draw
# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import get_current_point [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
示例2: on_draw
# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import get_current_point [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()
示例3: on_draw
# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import get_current_point [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()
#.........這裏部分代碼省略.........