demos/02_curses.py
author Radek Brich <radek.brich@devl.cz>
Wed, 26 Mar 2014 21:26:39 +0100
changeset 92 b97c4e25ed6d
parent 85 6828c5b16087
child 95 05392e369ede
permissions -rwxr-xr-x
Configure logging for demos.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
83
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
92
b97c4e25ed6d Configure logging for demos.
Radek Brich <radek.brich@devl.cz>
parents: 85
diff changeset
     3
import demobase
83
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
from tuikit.core.buffer import Buffer
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
from tuikit.driver.curses import CursesDriver
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
85
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
     9
colors = ('blue', 'green', 'cyan', 'red',
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    10
          'magenta', 'brown', 'lightgray', 'gray',
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    11
          'lightblue', 'lightgreen', 'lightcyan', 'lightred',
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    12
          'lightmagenta', 'yellow', 'white')
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    13
83
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
buffer = Buffer(16, 8)
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
buffer.fill(c='#')
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
buffer.hline(1, 1, 14, c='-')
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
buffer.hline(1, 6, 14, c='-')
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
buffer.vline(7, 2, 4, c='|')
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
buffer.puts(8, 4, 'Hello!')
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
buffer.frame()
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
85
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    22
buffer2 = Buffer(30, 10)
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    23
buffer2.setattr('white on black')
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    24
buffer2.frame()
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    25
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    26
for idx, color in enumerate(colors):
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    27
    buffer2.setattr(color)
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    28
    buffer2.puts(3 + 12 * (idx // 8), 1 + idx % 8, color)
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    29
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    30
buffer3 = Buffer(30, 10)
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    31
buffer3.setattr('white on black')
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    32
buffer3.frame()
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    33
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    34
for idx, color in enumerate(colors[:8]):
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    35
    buffer3.setattr('black on {}'.format(color))
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    36
    buffer3.puts(2, 1 + idx, ' '+color.ljust(10))
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    37
    buffer3.setattr('{}, underline, bold'.format(color))
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    38
    buffer3.puts(15, 1 + idx, ' '+color.ljust(10))
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    39
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    40
buffer3.setattr('lightgray, blink')
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    41
buffer3.puts(3, 8, 'blink')
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    42
83
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
driver = CursesDriver()
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
with driver:
ebe732b9ef19 Refactor Driver, CursesDriver: init, close, draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
    driver.draw(buffer)
85
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    46
    driver.draw(buffer2, 20, 00)
6828c5b16087 Add colors to curses demo.
Radek Brich <radek.brich@devl.cz>
parents: 84
diff changeset
    47
    driver.draw(buffer3, 20, 10)
84
04dfb5ddf031 Refactor Driver, CursesDriver: draw, setattr, input.
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
    48
    driver.flush()
04dfb5ddf031 Refactor Driver, CursesDriver: draw, setattr, input.
Radek Brich <radek.brich@devl.cz>
parents: 83
diff changeset
    49
    driver.getevents()