本文整理汇总了Python中caca.canvas.Canvas.printf方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.printf方法的具体用法?Python Canvas.printf怎么用?Python Canvas.printf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caca.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.printf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import printf [as 别名]
def main():
""" Main function. """
try:
cv = Canvas(80, 24)
dp = Display(cv)
except (CanvasError, DisplayError) as err:
sys.stderr.write("%s\n" % err)
sys.exit(127)
cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
cv.clear()
for i in range(0, 16):
if i >= 8:
y = i + 3
else:
y = i + 2
cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
cv.printf(3, y, "ANSI %i", i)
for j in range(0, 16):
if j >= 8:
x = 13 + (j * 4)
else:
x = 12 + (j * 4)
if i >= 8:
y = i + 3
else:
y = i + 2
cv.set_color_ansi(i, j)
cv.put_str(x, y, "Aaホ")
cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
cv.put_str(3, 20, "This is bold This is blink This is italics This is underline")
cv.set_attr(caca.STYLE_BOLD)
cv.put_str(3 + 8, 20, "bold")
cv.set_attr(caca.STYLE_BLINK)
cv.put_str(3 + 24, 20, "blink")
cv.set_attr(caca.STYLE_ITALICS)
cv.put_str(3 + 41, 20, "italics")
cv.set_attr(caca.STYLE_UNDERLINE)
cv.put_str(3 + 60, 20, "underline")
dp.refresh()
dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
示例2: test_printf
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import printf [as 别名]
def test_printf(self):
""" module canvas: Canvas.printf()
"""
word1, word2 = "test", "string"
cv = Canvas(10, 1)
self.assertEqual(10, cv.printf(0, 0, "%s%s", word1, word2))
liststring = []
for i in range(0, 10):
liststring.append(cv.get_char(i, 0))
self.assertEqual("teststring", "".join(liststring))
self.assertRaises(CanvasError, cv.printf, 0, 0, 111)
self.assertRaises(CanvasError, cv.printf, 0, "z", "abc %s", "def")