tests/curses_keycodes.py
author Radek Brich <radek.brich@devl.cz>
Sun, 27 Jan 2013 23:51:59 +0100
changeset 70 db2eab0beb45
parent 65 5f0697950f15
child 110 cf3d49cdd6e2
permissions -rwxr-xr-x
Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack. Application: Add overridable startup() method. Fix Widget draw clipping.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/python
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import curses
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
import locale
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
locale.setlocale(locale.LC_ALL,"")
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
def doStuff(screen):
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
    screen.addstr('termname: %s\n' % curses.termname())
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    screen.keypad(0)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
    screen.scrollok(1)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
    curses.nl()
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
    while True:
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        c = screen.getch()
65
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    17
        s = ''
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
        screen.nodelay(1)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
        while c != -1:
65
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    21
            try:
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    22
                s += chr(c)
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    23
            except ValueError:
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    24
                s += '?'
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
            screen.addstr('0x%02x,' % c)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
            c = screen.getch()
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
        screen.nodelay(0)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
65
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    29
        screen.addstr(' %r\n' % s)
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
        screen.refresh()
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
curses.wrapper(doStuff)