tests/curses_keycodes.py
author Radek Brich <radek.brich@devl.cz>
Sun, 15 Feb 2015 12:52:46 +0100
changeset 115 b4ff7392003a
parent 110 cf3d49cdd6e2
permissions -rwxr-xr-x
GridLayout: basic implementation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
110
cf3d49cdd6e2 Add cursesw driver, using curses get_wch() for unicode input. It alse has enabled keypad() to let curses interpret control keys and mouse input.
Radek Brich <radek.brich@devl.cz>
parents: 65
diff changeset
     1
#!/usr/bin/python3
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
import curses
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
locale.setlocale(locale.LC_ALL,"")
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
def doStuff(screen):
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
    screen.addstr('termname: %s\n' % curses.termname())
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
    screen.keypad(0)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    screen.scrollok(1)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
    curses.nl()
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
    while True:
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
        c = screen.getch()
65
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    16
        s = ''
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
        screen.nodelay(1)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
        while c != -1:
65
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    20
            try:
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    21
                s += chr(c)
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    22
            except ValueError:
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    23
                s += '?'
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
            screen.addstr('0x%02x,' % c)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
            c = screen.getch()
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
        screen.nodelay(0)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
65
5f0697950f15 DriverCurses: Add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    28
        screen.addstr(' %r\n' % s)
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
        screen.refresh()
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
curses.wrapper(doStuff)