[Tutor] calculator
Andrei Kulakov
ak@silmarill.org
Tue, 28 Aug 2001 14:16:17 -0400
On Tue, Aug 28, 2001 at 02:07:22PM -0400, Ignacio Vazquez-Abrams wrote:
> On Tue, 28 Aug 2001, Andrei Kulakov wrote:
>
> > Is it just me, or are alphanumeric menus much nicer, i.e.:
> >
> > menu = {
> > 'c': circlearea,
> > 'a': squarearea,
> > 'r': rectanglearea,
> > 'o': squareroot,
> > 'a': addnumbers
> > }
> >
> > And that letter is colorized in the menu? This is very easy
> > to do and much friendlier UI - gtk and qt, take a hike ;P.
>
> Oh, I absolutely agree that letters are better; I was just trying to work
> within the framework that had been created.
>
> As for coloured letters... if somebody's still using numbers in their menu,
> then I doubt that they're ready for curses ;)
No need for 'em :-) Here's a lil function I cooked up:
(colorize("red", "Test") prints Test in red, colorize(("red", "yellow"),"Test")
uses yellow background).
enable_color = 1
if sys.environ["TERM"] == "xterm":
xterm = 1
def colorize(color, text):
"""Return colorized text"""
col_dict = {
"black" : "30m",
"red" : "31m",
"green" : "32m",
"brown" : "33m",
"blue" : "34m",
"purple" : "35m",
"cyan" : "36m",
"lgray" : "37m",
"gray" : "1;30m",
"lred" : "1;31m",
"lgreen" : "1;32m",
"yellow" : "1;33m",
"lblue" : "1;34m",
"pink" : "1;35m",
"lcyan" : "1;36m",
"white" : "1;37m",
}
bg = "0m"
if type(color) == type(""):
# In xterm, brown comes out as yellow..
if xterm and color == "yellow": color = "brown"
fg = col_dict[color]
elif type(color) == type(()):
f, b = color[0], color[1]
if f == "yellow" and xterm: f = "brown"
if b == "yellow": b = "brown"
fg = col_dict[f]
try: bg = col_dict[b].replace('3', '4', 1)
except KeyError: pass
if enable_color:
return "\033[%s\033[%s%s\033[0m" % (bg, fg, text)
else:
return text
>
> --
> Ignacio Vazquez-Abrams <ignacio@openservices.net>
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org