本文整理汇总了Python中caca.canvas.Canvas类的典型用法代码示例。如果您正苦于以下问题:Python Canvas类的具体用法?Python Canvas怎么用?Python Canvas使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Canvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_draw_thin_triangle
def test_draw_thin_triangle(self):
""" module canvas: Canvas.draw_thin_triangle()
"""
cv = Canvas(10, 10)
self.assertEqual(0, cv.draw_thin_triangle(0, 0, 2, 2, 4, 0))
self.assertRaises(CanvasError, cv.draw_thin_triangle,
0, 0, 2, 2, 4, '#')
示例2: test_fill_ellipse
def test_fill_ellipse(self):
""" module canvas: Canvas.fill_ellipse()
"""
cv = Canvas(10, 10)
self.assertEqual(0, cv.fill_ellipse(5, 5, 3, 3, '#'))
self.assertRaises(CanvasError, cv.fill_ellipse, 0, 0, 3, '#', '#')
self.assertRaises(CanvasError, cv.fill_ellipse, 0, 0, 3, 3, 0)
示例3: test_fill_box
def test_fill_box(self):
""" module canvas: Canvas.fill_box()
"""
cv = Canvas(10, 10)
self.assertEqual(0, cv.fill_box(0, 0, 2, 2, '#'))
self.assertRaises(CanvasError, cv.fill_box, 0, 0, 2, '#', '#')
self.assertRaises(CanvasError, cv.fill_box, 0, 0, 2, 2, 0)
示例4: test_remove_dirty_rect
def test_remove_dirty_rect(self):
""" module canvas: Canvas.remove_dirty_rect()
"""
cv = Canvas(10, 10)
cv.add_dirty_rect(4, 4, 2, 2)
self.assertEqual(0, cv.remove_dirty_rect(4, 4, 2, 2))
self.assertRaises(CanvasError, cv.remove_dirty_rect, 11, 11, 20, 20)
示例5: test_draw_circle
def test_draw_circle(self):
""" module canvas: Canvas.draw_circle()
"""
cv = Canvas(10, 10)
self.assertEqual(0, cv.draw_circle(5, 5, 3, '#'))
self.assertRaises(CanvasError, cv.draw_circle, 0, 0, '#', '#')
self.assertRaises(CanvasError, cv.draw_circle, 0, 0, 3, 0)
示例6: test_draw_thin_line
def test_draw_thin_line(self):
""" module canvas: Canvas.draw_thin_line()
"""
cv = Canvas(10, 1)
cv.draw_thin_line(0, 0, 10, 1)
self.assertEqual("-" * 10, cv.export_to_memory("utf8").strip('\n'))
self.assertRaises(CanvasError, cv.draw_thin_line, 0, "a", 10, 1)
示例7: test_enable_dirty_rect
def test_enable_dirty_rect(self):
""" module canvas: Canvas.enable_dirty_rect()
"""
cv = Canvas()
self.assertRaises(CanvasError, cv.enable_dirty_rect)
cv.disable_dirty_rect()
self.assertEqual(0, cv.enable_dirty_rect())
示例8: main
def main():
""" Main function. """
if len(sys.argv) < 3:
sys.stderr.write("Usage: %s <figfont file> <word>\n" \
% os.path.basename(sys.argv[0]))
sys.exit(2)
try:
cv = Canvas(0, 0)
except CanvasError as err:
sys.stderr.write("%s\n" % err)
sys.exit(2)
if cv.set_figfont(sys.argv[1]):
sys.stderr.write("Could not open font...\n")
sys.exit(2)
if sys.version_info[0:2] >= (3,0):
word = sys.argv[2]
else:
word = codecs.decode(sys.argv[2], "utf8")
for c in word:
cv.put_figchar(c)
sys.stderr.write(cv.export_to_memory("utf8"))
示例9: test_draw_thin_polyline
def test_draw_thin_polyline(self):
""" module canvas: Canvas.draw_thin_polyline()
"""
cv = Canvas(10, 10)
self.assertEqual(0, cv.draw_thin_polyline([(0, 0), (2, 2),
(5, 2), (0, 0)]))
self.assertRaises(CanvasError, cv.draw_thin_polyline, [])
self.assertRaises(CanvasError, cv.draw_thin_polyline, [0, 1, 2, 4])
示例10: test_set_handle
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")
示例11: test_gotoxy
def test_gotoxy(self):
""" module canvas: Canvas.gotoxy()
"""
cv = Canvas(10, 10)
cv.gotoxy(5, 5)
self.assertEqual((5, 5), (cv.wherex(), cv.wherey()))
self.assertRaises(CanvasError, cv.gotoxy, "a", 9)
self.assertRaises(CanvasError, cv.gotoxy, 9, "a")
示例12: test_set_size
def test_set_size(self):
""" module canvas: Canvas.set_size()
"""
cv = Canvas(0, 0)
cv.set_size(1234, 1001)
self.assertEqual((1234, 1001), (cv.get_width(), cv.get_height()))
self.assertRaises(CanvasError, cv.set_size, "a", 12)
self.assertRaises(CanvasError, cv.set_size, 12, "a")
示例13: test_fill_triangle
def test_fill_triangle(self):
""" module canvas: Canvas.fill_triangle()
"""
cv = Canvas(10, 10)
self.assertEqual(0, cv.fill_triangle(0, 0, 2, 2, 4, 0, '#'))
self.assertRaises(CanvasError, cv.fill_triangle,
0, 0, 2, 2, 4, '#', '#')
self.assertRaises(CanvasError, cv.fill_triangle,
0, 0, 2, 2, 4, 0, 0)
示例14: test_put_char
def test_put_char(self):
""" module canvas: Canvas.put_char()
"""
cv = Canvas(10, 1)
self.assertEqual(1, cv.put_char(0, 0, "z"))
self.assertEqual(1, cv.put_char(1, 0, "é"))
self.assertEqual("z", cv.get_char(0, 0))
self.assertEqual("é", cv.get_char(1, 0))
self.assertRaises(CanvasError, cv.put_char, "a", 1, 2)
self.assertRaises(CanvasError, cv.put_char, "a", 1, "b")
示例15: test_printf
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")