annotate Lib/curses/__init__.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 3a6ca89ef76d
children 3e26c9033306 9c96c3adbcd1 52900f205e6e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12911
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1 """curses
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
3 The main package for curses support for Python. Normally used by importing
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
4 the package, and perhaps a particular module inside it.
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
5
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
6 import curses
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
7 from curses import textpad
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
8 curses.initwin()
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
9 ...
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 17317
diff changeset
10
12911
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
11 """
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
12
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
13 __revision__ = "$Id$"
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
14
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
15 from _curses import *
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
16 from curses.wrapper import wrapper
45457
ba359b6c33c3 #1119331: ncurses will just call exit() if the terminal name isn't found.
Andrew M. Kuchling <amk@amk.ca>
parents: 32736
diff changeset
17 import os as _os
45517
3a6ca89ef76d Use file descriptor for real stdout
Andrew M. Kuchling <amk@amk.ca>
parents: 45457
diff changeset
18 import sys as _sys
12911
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
19
13022
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
20 # Some constants, most notably the ACS_* ones, are only added to the C
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
21 # _curses module's dictionary after initscr() is called. (Some
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
22 # versions of SGI's curses don't define values for those constants
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
23 # until initscr() has been called.) This wrapper function calls the
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
24 # underlying C initscr(), and then copies the constants from the
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
25 # _curses module to the curses package's dictionary. Don't do 'from
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
26 # curses import *' if you'll be needing the ACS_* constants.
12911
3cee0d75191e Add contents of curses package
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
27
13022
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
28 def initscr():
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
29 import _curses, curses
45457
ba359b6c33c3 #1119331: ncurses will just call exit() if the terminal name isn't found.
Andrew M. Kuchling <amk@amk.ca>
parents: 32736
diff changeset
30 # we call setupterm() here because it raises an error
ba359b6c33c3 #1119331: ncurses will just call exit() if the terminal name isn't found.
Andrew M. Kuchling <amk@amk.ca>
parents: 32736
diff changeset
31 # instead of calling exit() in error cases.
45517
3a6ca89ef76d Use file descriptor for real stdout
Andrew M. Kuchling <amk@amk.ca>
parents: 45457
diff changeset
32 setupterm(term=_os.environ.get("TERM", "unknown"),
3a6ca89ef76d Use file descriptor for real stdout
Andrew M. Kuchling <amk@amk.ca>
parents: 45457
diff changeset
33 fd=_sys.__stdout__.fileno())
13022
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
34 stdscr = _curses.initscr()
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
35 for key, value in _curses.__dict__.items():
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
36 if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
37 setattr(curses, key, value)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 17317
diff changeset
38
13022
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
39 return stdscr
87ece127cba2 Add wrapper for initscr() to copy the ACS_ and LINES,COLS bindings
Andrew M. Kuchling <amk@amk.ca>
parents: 12911
diff changeset
40
17317
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
41 # This is a similar wrapper for start_color(), which adds the COLORS and
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
42 # COLOR_PAIRS variables which are only available after start_color() is
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
43 # called.
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 17317
diff changeset
44
17317
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
45 def start_color():
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
46 import _curses, curses
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
47 retval = _curses.start_color()
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
48 if hasattr(_curses, 'COLORS'):
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
49 curses.COLORS = _curses.COLORS
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
50 if hasattr(_curses, 'COLOR_PAIRS'):
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
51 curses.COLOR_PAIRS = _curses.COLOR_PAIRS
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 17317
diff changeset
52 return retval
17317
310066b992f2 Bug #412086, reported by Peter Wilson: The _curses module doesn't
Andrew M. Kuchling <amk@amk.ca>
parents: 13781
diff changeset
53
13781
ad390240efb3 Added Python function to emulate the ncurses has_key() function.
Andrew M. Kuchling <amk@amk.ca>
parents: 13022
diff changeset
54 # Import Python has_key() implementation if _curses doesn't contain has_key()
ad390240efb3 Added Python function to emulate the ncurses has_key() function.
Andrew M. Kuchling <amk@amk.ca>
parents: 13022
diff changeset
55
ad390240efb3 Added Python function to emulate the ncurses has_key() function.
Andrew M. Kuchling <amk@amk.ca>
parents: 13022
diff changeset
56 try:
ad390240efb3 Added Python function to emulate the ncurses has_key() function.
Andrew M. Kuchling <amk@amk.ca>
parents: 13022
diff changeset
57 has_key
ad390240efb3 Added Python function to emulate the ncurses has_key() function.
Andrew M. Kuchling <amk@amk.ca>
parents: 13022
diff changeset
58 except NameError:
ad390240efb3 Added Python function to emulate the ncurses has_key() function.
Andrew M. Kuchling <amk@amk.ca>
parents: 13022
diff changeset
59 from has_key import has_key