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