__init__.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """curses
  2. The main package for curses support for Python. Normally used by importing
  3. the package, and perhaps a particular module inside it.
  4. import curses
  5. from curses import textpad
  6. curses.initwin()
  7. ...
  8. """
  9. __revision__ = "$Id: __init__.py 36560 2004-07-18 06:16:08Z tim_one $"
  10. from _curses import *
  11. from curses.wrapper import wrapper
  12. # Some constants, most notably the ACS_* ones, are only added to the C
  13. # _curses module's dictionary after initscr() is called. (Some
  14. # versions of SGI's curses don't define values for those constants
  15. # until initscr() has been called.) This wrapper function calls the
  16. # underlying C initscr(), and then copies the constants from the
  17. # _curses module to the curses package's dictionary. Don't do 'from
  18. # curses import *' if you'll be needing the ACS_* constants.
  19. def initscr():
  20. import _curses, curses
  21. stdscr = _curses.initscr()
  22. for key, value in _curses.__dict__.items():
  23. if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
  24. setattr(curses, key, value)
  25. return stdscr
  26. # This is a similar wrapper for start_color(), which adds the COLORS and
  27. # COLOR_PAIRS variables which are only available after start_color() is
  28. # called.
  29. def start_color():
  30. import _curses, curses
  31. retval = _curses.start_color()
  32. if hasattr(_curses, 'COLORS'):
  33. curses.COLORS = _curses.COLORS
  34. if hasattr(_curses, 'COLOR_PAIRS'):
  35. curses.COLOR_PAIRS = _curses.COLOR_PAIRS
  36. return retval
  37. # Import Python has_key() implementation if _curses doesn't contain has_key()
  38. try:
  39. has_key
  40. except NameError:
  41. from has_key import has_key