本文整理匯總了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)