tests/curses_getkey.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: 20
diff changeset
     1
#!/usr/bin/python3
20
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
import curses
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
locale.setlocale(locale.LC_ALL, "")
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
def doStuff(stdscr):
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
  message = "Press 'q' to quit.\n"
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
  stdscr.addstr(0, 0, message, 0)
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
  while True:
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
    c = stdscr.getkey() # pauses until a key's hit
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
    if c == 'q':
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
      break
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
    stdscr.addstr('%s %r\n' % (c, c))
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
472a753664f9 Update utf8 character input to Python3. Reorganize tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
curses.wrapper(doStuff)