本文整理汇总了Python中cairo.Context.show_text方法的典型用法代码示例。如果您正苦于以下问题:Python Context.show_text方法的具体用法?Python Context.show_text怎么用?Python Context.show_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.show_text方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import show_text [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)
示例2: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import show_text [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
示例3: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import show_text [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
self.set_shape_from_context(context)
shape = self.shape
context.set_line_width(self.line_thickness)
if self.orientation == Orientation.HORIZONTAL:
context.move_to(shape.start.x - self.line_extension, shape.start.y)
context.line_to(shape.start.x + shape.width, shape.start.y)
else:
context.move_to(shape.start.x, shape.start.y - self.line_extension)
context.line_to(shape.start.x, shape.start.y + shape.height)
context.stroke()
for element in self._elements:
context.move_to(*element.position)
context.set_source_rgb(*element.color)
context.show_text(element.label)
示例4: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import show_text [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()
示例5: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import show_text [as 别名]
def on_draw(self, widget: "Widget", context: cairo.Context):
self._set_font(context)
for tl in self.__text_lines:
context.move_to(tl.start.x, tl.start.y)
context.show_text(tl.text)
示例6: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import show_text [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()
#.........这里部分代码省略.........
示例7: _paint_panel
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import show_text [as 别名]
#.........这里部分代码省略.........
ky = (max_y - min_y) / (height - bottom)
if ky == 0:
ky = 1
except:
kx, ky = 1, 1
img = ImageSurface(FORMAT_ARGB32, width, height)
ctx = Context(img)
width -= right
ctx.set_line_width(1)
# Рисуем сетку
ctx.set_font_size(12)
try:
b_w, b_h = ctx.text_extents("00-00-0000")[2:4]
# Метки на оси Y
count = math.ceil(max_y) - math.ceil(min_y)
space_count = math.ceil(count / ((height - bottom) / (b_h * 1.5)))
sc = 0
for i in range(math.ceil(min_y), math.ceil(max_y)):
if sc == 0:
y = height - bottom + (min_y - i) / ky
ctx.set_source_rgb(*(color_x_line))
ctx.move_to(left, y)
ctx.line_to(width, y)
ctx.stroke()
ctx.set_source_rgb(0, 0, 0)
num = str(i)
tw, th = ctx.text_extents(num)[2:4]
ctx.move_to(left - 5 - tw, y + th // 2)
ctx.show_text(num)
sc = space_count
sc -= 1
# Метки на оси Х
x_step = 3600
if interval == "-6 hour" or interval == "-12 hour" or interval == "-1 day":
# Дополнительно метки часов
x_step = 3600
for i in range(math.ceil(min_x / x_step), math.ceil(max_x / x_step)):
x = (i * x_step - min_x) / kx + left
ctx.set_source_rgb(*(color_x_line_2))
ctx.move_to(x, 0)
ctx.line_to(x, height - bottom)
ctx.stroke()
num = datetime.datetime.fromtimestamp(i * x_step).strftime("%H")
tw, th = ctx.text_extents(num)[2:4]
ctx.move_to(x + 2, height - bottom - 3)
ctx.set_source_rgb(*(color_x_line))
ctx.show_text(num)
x_step = 3600 * 24
space_count = 1
count = math.ceil(max_x / x_step) - math.ceil(min_x / x_step)
try:
if (width / count) < b_w:
space_count = 2
except:
pass
sc = 0