本文整理汇总了Python中caca.canvas.Canvas.set_handle方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.set_handle方法的具体用法?Python Canvas.set_handle怎么用?Python Canvas.set_handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caca.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.set_handle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_handle
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import set_handle [as 别名]
def test_set_handle(self):
""" module canvas: Canvas.set_handle()
"""
cv = Canvas(10, 5)
self.assertEqual(0, cv.set_handle(3, 3))
self.assertEqual((3, 3), (cv.get_handle_x(), cv.get_handle_y()))
self.assertRaises(CanvasError, cv.set_handle, "a", 1)
self.assertRaises(CanvasError, cv.set_handle, 1, "a")
示例2: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import set_handle [as 别名]
def main():
""" Main function. """
try:
cv = Canvas(0, 0)
dp = Display(cv)
except (CanvasError, DisplayError) as err:
sys.stderr.write("%s\n" % err)
sys.exit(2)
sprite = Canvas(0, 0)
sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
sprite.import_from_memory(THE_PIG, "text")
sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2)
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
cv.put_str(0, 0, "Centered sprite")
cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas())
dp.refresh()
dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
sys.exit(0)