curses-based menu module?

Terry Hancock hancock at anansispaceworks.com
Tue Jul 2 06:46:49 EDT 2002


Hi all,

I'm converting a tcsh/csh management script at work
over to Python. It has a lot of CLI-based menus (you
know, the old, really dumb kind), and I was thinking
about replacing these with curses-based menus.

Curses itself seems really easy to use, but is
kind of a low-level interface.  Clearly, I will be
well-served to make a higher-level interface for
creating and using menus.  But I have a couple of
questions:

#1:
Am I reinventing the wheel? Is there already
a high-level interface available (this seems rather
likely, though I haven't found one).

#2:
If not -- does anyone want to discuss a good API
for such a thing? It'd be really handy for installation
and maintenance scripts (such as the one I'm writing).

Right now, I'm thinking of emulating the sort of
things you can easily do with HTML form widgets,
just off the top of my head:

"select" -- select one of several fixed options,
            immediately return selection to the
            caller.

"radio"  -- like select, but with an '*' or 'X'
            cursor that you move with the arrow
            keys -- the selection
            is registered by an "enter" or some
            similar keystroke.

"checkbox"  multiple-selections, like radio otherwise

(and I'm sure there's more possibilities)

The menu would be a class (instance) with __init__
taking a sequence of options, and some optional
keywords to control behavior.  The options would
be tuples with menu-option-text, short-cut key,
and an optional call-back function (if not given,
the option just sets the selection).

There should also be some codes for options which
ought to be confirmed ("You have selected
'reformatting your hard drive' are you really
sure you want to do that?"), etc.

The menu object would be callable, displaying a
curses menu to the user when called, and returning
the selection as a result (callbacks would be
called from within the menu call function).

Anyway, that's the idea -- I don't want to go into
any more detail until I know that this doesn't
already exist. But I'm willing to discuss it and
come up with a real API which I could then
implement, and make generally available.

Cheers,
Terry

-- 
------------------------------------------------------
Terry Hancock
hancock at anansispaceworks.com       
Anansi Spaceworks                 
http://www.anansispaceworks.com 
P.O. Box 60583                     
Pasadena, CA 91116-6583
------------------------------------------------------





More information about the Python-list mailing list