source: libcaca/trunk/python/examples/frames.py @ 4802

Last change on this file since 4802 was 4802, checked in by alxf, 3 years ago

Add support for python3 to python bindings.

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# frames        canvas frame switching features
5# Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
6#
7# This file is a Python port of "examples/frames.c"
8# which is:
9# Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
10#               All Rights Reserverd
11#
12# This library is free software. It comes without any warranty, to
13# the extent permitted by applicable law. You can redistribute it
14# and/or modify it under the terms of the Do What The Fuck You Want
15# To Public License, Version 2, as published by Sam Hocevar. See
16# http://sam.zoy.org/wtfpl/COPYING for more details.
17#
18
19import sys
20
21import caca
22from caca.canvas import Canvas, CanvasError
23from caca.display import Display, DisplayError, Event
24
25def main():
26    """ Main function. """
27
28    try:
29        cv = Canvas(0, 0)
30    except CanvasError as err:
31        sys.stderr.write("%s\n" % err)
32        sys.exit(2)
33
34    for idx in range(1, 200):
35        cv.create_frame(idx)
36
37    sys.stderr.write("canvas created, size is %dx%d\n" \
38                        % (cv.get_width(), cv.get_height()))
39
40    cv.set_size(150, 80)
41    sys.stderr.write("canvas expanded, size is %dx%d\n" \
42                        % (cv.get_width(), cv.get_height()))
43
44    for idx in range(0, 16):
45        cv.set_frame(idx)
46        cv.set_color_ansi(caca.COLOR_WHITE, idx)
47        cv.fill_box(0, 0, 40, 15, ':')
48        cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
49        cv.put_str((idx * 5) // 2, idx, "カカ")
50        cv.set_color_ansi(caca.COLOR_DEFAULT, caca.COLOR_TRANSPARENT)
51
52    cv.set_size(41, 16)
53    sys.stderr.write("canvas shrinked, size is %dx%d\n" \
54                        % (cv.get_width(), cv.get_height()))
55
56    try:
57        dp = Display(cv)
58    except DisplayError as err:
59        sys.stderr.write("%s\n" % err)
60        sys.exit(2)
61
62    dp.set_time(50000)
63    sys.stderr.write("display attached, size is %dx%d\n" \
64                        % (cv.get_width(), cv.get_height()))
65
66    n = 0
67    while not dp.get_event(caca.EVENT_KEY_PRESS, Event(), 0):
68        cv.set_frame(n % 16)
69        dp.refresh()
70        n += 1
71
72if __name__ == "__main__":
73    main()
74
Note: See TracBrowser for help on using the repository browser.