File: player.py

package info (click to toggle)
python-asciimatics 1.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,488 kB
  • sloc: python: 15,713; sh: 8; makefile: 2
file content (42 lines) | stat: -rwxr-xr-x 1,506 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import sys
import logging
from asciimatics.effects import Print
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from asciimatics.renderers import AnsiArtPlayer, AsciinemaPlayer, SpeechBubble
from asciimatics.exceptions import ResizeScreenError

logging.basicConfig(filename="debug.log", level=logging.DEBUG)


def demo(screen, scene):
    with AsciinemaPlayer("test.rec", max_delay=0.1) as player, \
            AnsiArtPlayer("fruit.ans") as player2:
        screen.play(
            [
                Scene(
                    [
                        Print(screen, player, 0, speed=1, transparent=False),
                        Print(screen,
                              SpeechBubble("Press space to see ansi art"),
                              y=screen.height - 3, speed=0, transparent=False)
                    ], -1),
                Scene(
                    [
                        Print(screen, player2, 0, speed=1, transparent=False),
                        Print(screen,
                              SpeechBubble("Press space to see asciinema"),
                              y=screen.height - 3, speed=0, transparent=False)
                    ], -1)
            ],
            stop_on_resize=True, start_scene=scene, allow_int=True)


last_scene = None
while True:
    try:
        Screen.wrapper(demo, catch_interrupt=False, arguments=[last_scene])
        sys.exit(0)
    except ResizeScreenError as e:
        last_scene = e.scene