[Python-bugs-list] [ python-Bugs-412086 ] curses module is missing some color vars

noreply@sourceforge.net noreply@sourceforge.net
Thu, 05 Apr 2001 09:09:47 -0700


Bugs item #412086, was updated on 2001-03-28 20:07
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=412086&group_id=5470

Category: Python Library
Group: None
>Status: Closed
Priority: 5
Submitted By: Peter Wilson (pabw)
Assigned to: A.M. Kuchling (akuchling)
Summary: curses module is missing some color vars

Initial Comment:
The _curses modules doesn't define COLORS or COLOR_PAIRS until after start_color() is called.

Adding a start_color() wrapper to curses/__init__.py along the same lines as the wrapper around initscr() fixes this.
(And I don't knowof or use any other variables that get dynamically added...)

def start_color():
    import _curses, curses  
    # This import is from the initscr() wrapper
    val = _curses.start_color()

    if _curses.__dict__.has_key('COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    if _curses.__dict__.has_key('COLORS'):
        curses.COLORS = _curses.COLORS

    return val

-------

# Or, it's simple avoid the import in a function-level scope...
# If this version is used, then the initscr() wrapper should probably be changed to match.

import sys

def start_color():
    # If this code gets called, then these modules are guaranteed to exist:
    curses = sys.module['curses']
    _curses = sys.module['_curses']

    val = _curses.start_color()
    
    if _curses.__dict__.has_key('COLOR_PAIRS'):
        curses.COLOR_PAIRS = _curses.COLOR_PAIRS
    if _curses.__dict__.has_key('COLORS'):
        curses.COLORS = _curses.COLORS

    return val


----------------------------------------------------------------------

>Comment By: A.M. Kuchling (akuchling)
Date: 2001-04-05 09:09

Message:
Logged In: YES 
user_id=11375

Good point!  Fixed in revision 1.4 of curses/__init__.py,
using a 
slightly modified version of your first patch.  Thanks!

initscr() and start_color() are the only functions which add
more 
variables to the module dictionary, so no additional
wrappers 
should be necessary.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=412086&group_id=5470