[DIFF] tkui enhancements galore

Eliezer Flores <[email protected]> Tue, 03 Jan 2006 02:33:12 -0500
Newsgroups gmane.comp.games.mud.client.lyntin
Message-ID <[email protected]>
This is the diff for a slew of tkui enhancements. They mainly center 
around changing aspects of the tkui like colors, fonts, and the like. 
The new commands are all gathered under the ui help category. It also 
adds two #config items: useboldfont and suppresslocalecho. As far as an 
under-the-hood enhancement, I added the ability to ansi-fy  messages of 
type LTDATA. The diff also covers the mods necessary to get the tkui on 
os x since I diff against the cvs.  Be forewarned, it's a long one.

Index: lyntin40/lyntin/ui/tkui.py
===================================================================
RCS file: /cvsroot/lyntin/lyntin40/lyntin/ui/tkui.py,v
retrieving revision 1.25
diff -r1.25 tkui.py
16c16
< import os, tkFont, types, Queue
---
 > import os, tkFont, types, Queue, sys
20a21
 > from lyntin.modules import modutils
73a75,79
 >  - extra commands to configure the interface (see #help ui)
 >  - useboldfont, suppresslocalecho config items for extra prettiness
 > """
 > if sys.platform != 'darwin':
 >   HELP_TEXT = HELP_TEXT + """
84c90,97
< """
---
 >   """
 > else:
 >   HELP_TEXT = HELP_TEXT + """
 >  - cmd-u removal of text
 >  - cmd-c copy from the text buffer and cmd-v paste into the command
 >    buffer
 >  - cmd-t autotyper
 >  - NamedWindow handling
85a99,103
 > To bind function key and numpad bindings, create an alias for the
 > symbol.  For example:
 >
 >    #alias {VK_NUMPAD2} {south}
 >   """
128c146,149
< DEFAULT_COLOR[ansi.PLACE_FG] = 37
---
 > DEFAULT_COLOR[ansi.PLACE_FG] = 30
 >
 >
 >
178a200,211
 >     # define default foreground and background color. It is a string 
that
 >     # represents the a TK i.e. a tk named color or an rgb color in 
#RRGGBB or
 >     # #RRRRGGGGBBBB
 >    
 >     self.color_foreground = "black" # I like black on white
 >     self.color_background = "white"
 >     self.color_caret = "blue"
 >     # the colors are named colors from the ansi module. These colors 
are parsed by
 >     # ansi.get_color so you can get jiggy with it ;)
 >     self.color_message_error = "b black,blue,bold"
 >     self.color_message_userdata = "b black,blue,bold"
 >     self.color_message_ltdata = "default"
190a224
 >     self._suppresslocalecho = 1
202c236,238
<       fnt = tkFont.Font(family="Courier", size=12)
---
 >       self._basefont = tkFont.Font(name="basefont", family="Courier", 
size=12)
 >       self._boldfont = tkFont.Font(name="boldfont", family="Courier", 
size=12, weight=tkFont.BOLD)
 >      
204,209c240,247
<       fnt = tkFont.Font(family="Fixedsys", size=12)
<
<
<     self._entry = CommandEntry(self._tk, self, fg='white', bg='black',
<                                insertbackground='yellow', font=fnt,
<                                insertwidth='2')
---
 >       self._basefont = tkFont.Font(name="basefont", 
family="Fixedsys", size=12)
 >       self._boldfont = tkFont.Font(name="boldfont", 
family="Fixedsys", size=12, weight=tkFont.BOLD)
 >    
 >     fnt = self._basefont
 >     self._entry = CommandEntry(self._tk, self, fg=self.color_foreground,
 >                                      bg=self.color_background,
 >                                      insertbackground=self.color_caret,
 >                                font=fnt, insertwidth='2')
215,216c253,254
<     self._txt = ScrolledText(self._topframe, fg='white',
<                              bg='black', font=fnt, height=20)
---
 >     self._txt = ScrolledText(self._topframe, fg=self.color_foreground,
 >                              bg=self.color_background, font=fnt, 
height=20)
221,222c259,260
<     self._txtbuffer = ScrolledText(self._topframe, fg='white',
<                                    bg='black', font=fnt, height=20)
---
 >     self._txtbuffer = ScrolledText(self._topframe, 
fg=self.color_foreground,
 >                                    bg=self.color_background, 
font=fnt, height=20)
241c279,291
<
---
 >    
 >     tc = config.BoolConfig("useboldfont", 1, 1, "If useboldfont is 
on, in "
 >           "addition to using the appropriate color, it will also 
attempt to use"
 >           " the bolded version of the current font. Cool beans. ")
 >     exported.add_config("useboldfont", tc)
 >    
 >     tc = config.BoolConfig("supresslocalecho", 1, 1, "If 
suppresslocalecho is "
 >       "on, it will suppress local echo even if mudecho is on 
.Apparently, you "
 >       "DO NOT want to use mudecho to turn off localecho because it 
impacts "
 >       "telnet negotiations on login. Don't worry, frankly it confuses 
me too.\n"
 >       "I added this option because turning off mudecho turns the text 
entry "
 >       "area into a password field which irritated the living bejesus 
out of me")
 >     exported.add_config("supresslocalecho", tc)
249c299,306
<
---
 >     exported.add_command("defaultcolor", default_color_cmd, "name=")
 >     exported.add_command("screencolor", screencolor_cmd, "name=")
 >     exported.add_command("remapcolor", remap_cmd, "ID= color=")
 >     exported.add_command("caretcolor", caretcolor_cmd, "color=")
 >     exported.add_command("erroransi", erroransi_cmd, "ansi=")
 >     exported.add_command("useransi", useransi_cmd, "ansi=")
 >     exported.add_command("ltansi", ltansi_cmd, "ansi=")
 >     exported.add_command("changefont", changefont_cmd, "name= size=")
309a367,379
 >    
 >   def getTextWidgetList(self):
 >     """
 >     This simply returns a list composed of text widgets. Mainly used 
to make all
 >     the changes in colors, fonts, etc uniform across text widgets.
 >     """
 >     results =[]
 >     results.append(self._txt)
 >     results.append(self._txtbuffer)
 >     for v in self._windows.itervalues():
 >       results.append(v._txt)
 >      
 >     return results
318,320c388,392
<     # kludge so that ctrl-c doesn't get caught allowing windows
<     # users to copy the buffer....
<     if tkevent.keycode == 17 or tkevent.keycode == 67:
---
 >     # kludge so that ctrl-c doesn't get caught allowing windows users 
to copy
 >     # the buffer. It also allows OS X user to cut using cmd-c. 
 >     if tkevent.keycode == 17 or tkevent.keycode == 67 or \
 >         (sys.platform=='darwin' and (tkevent.keycode == 524387 or \
 >         tkevent.keycode == 256 )):
322c394
<
---
 >      
399a472,492
 >    
 >     elif name == "useboldfont":
 >       if newvalue == 1:
 >         usefont = self._boldfont
 >       else:
 >         usefont = self._basefont
 >               
 >       widgetlist = self.getTextWidgetList()
 >       for k in fg_color_codes.keys():
 >         if k.startswith("b"):
 >           for widget in widgetlist:
 >             widget.tag_config(k, font = usefont)
 >            
 >       for k in bg_color_codes.keys():
 >         if k.startswith("b"):
 >           for widget in widgetlist:
 >             widget.tag_config(k, font = usefont)
 >            
 >     elif name == "supresslocalecho":
 >       self._suppresslocalecho = newvalue
 >        
452,474d544
<   def convertColor(self, name):
<     """
<     Tk has this really weird color palatte.  So I switched to using
<     color names in most cases and rgb values in cases where I couldn't
<     find a good color name.
<
<     This method allows me to specify either an rgb or a color name
<     and it converts the color names to rgb.
<
<     @param name: either an rgb value or a name
<     @type  name: string
<
<     @returns: the rgb color value
<     @rtype: string
<     """
<     if name.startswith("#"):
<       return name
<
<     rgb = self._tk._getints(self._tk.tk.call('winfo', 'rgb', 
self._txt, name))
<     rgb = "#%02x%02x%02x" % (rgb[0]/256, rgb[1]/256, rgb[2]/256)
<     print name, "converted to: ", rgb
<
<     return rgb
475a546
 >      
478,489c549,553
<     for ck in fg_color_codes.keys():
<       color = self.convertColor(fg_color_codes[ck])
<       self._txt.tag_config(ck, foreground=color)
<       self._txtbuffer.tag_config(ck, foreground=color)
<
<     for ck in bg_color_codes.keys():
<       self._txt.tag_config(ck, background=bg_color_codes[ck])
<       self._txtbuffer.tag_config(ck, background=bg_color_codes[ck])
<
<     self._txt.tag_config("u", underline=1)
<     self._txtbuffer.tag_config("u", underline=1)
<
---
 >     globalInitColorTags(self._txt, self.color_foreground, 
self.color_background,
 >                         self._basefont, self._boldfont, 1)
 >     globalInitColorTags(self._txtbuffer, self.color_foreground,
 >                     self.color_background, self._basefont, 
self._boldfont, 1)
 >    
534,538c598,609
<
<     self.bind("<Control-KeyPress-t>", self.startAutotyper)
<     self.bind("<Control-KeyPress-u>", self.callKillLine)
<     self.bind("<Control-KeyPress-Up>", self.callPushInputStack)
<     self.bind("<Control-KeyPress-Down>", self.callPopInputStack)
---
 >     #bind the keys correctly for OS X
 >     if sys.platform=='darwin':
 >       self.bind("<M1-KeyPress-t>", self.startAutotyper)
 >       self.bind("<M1-KeyPress-u>", self.callKillLine)
 >       self.bind("<M1-KeyPress-Up>", self.callPushInputStack)
 >       self.bind("<M1-KeyPress-Down>", self.callPopInputStack)
 >     else:
 >       self.bind("<Control-KeyPress-t>", self.startAutotyper)
 >       self.bind("<Control-KeyPress-u>", self.callKillLine)
 >       self.bind("<Control-KeyPress-Up>", self.callPushInputStack)
 >       self.bind("<Control-KeyPress-Down>", self.callPopInputStack)
 >    
568a640,652
 >     elif sys.platform=='darwin':
 >       # this section is for systems running OS X (which =='darwin')
 >       self.bind("<M1-KeyPress-q>", self.callMacShutdown)
 >       self.bind("<KeyPress-8>", self.callKP8)
 >       self.bind("<KeyPress-6>", self.callKP6)
 >       self.bind("<KeyPress-4>", self.callKP4)
 >       self.bind("<KeyPress-2>", self.callKP2)
 >       self.bind("<KeyPress-9>", self.callKP9)
 >       self.bind("<KeyPress-7>", self.callKP7)
 >       self.bind("<KeyPress-5>", self.callKP5)
 >       self.bind("<KeyPress-3>", self.callKP3)
 >       self.bind("<KeyPress-1>", self.callKP1)
 >       self.bind("<KeyPress-KP_Enter>", self.createInputEvent)
569a654
 >      
632d716
<
646a731,736
 >   def callMacShutdown(self, tkevent):
 >     """ Handles cmd-q for os x (darwin) platform. Shuts it down."""
 >     # handle all the function keys except F1
 >     self._partk.quit()
 >     return "break"
 >
648c738,739
<     if tkevent.keycode == 105 or os.name=='posix':
---
 >     if tkevent.keycode == 105 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 6029369):
653c744,745
<     if tkevent.keycode == 104 or os.name=='posix':
---
 >     if tkevent.keycode == 104 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5963832):
658,659c750,751
<     if tkevent.keycode == 103 or os.name=='posix':
<       if self._executeBinding("VK_NUMPAD7") == 1:
---
 >     if tkevent.keycode == 103 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5832759):
663c755,756
<     if tkevent.keycode == 102 or os.name=='posix':
---
 >     if tkevent.keycode == 102 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5767222):
668c761,762
<     if tkevent.keycode == 101 or os.name=='posix':
---
 >     if tkevent.keycode == 101 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5701685):
673c767,768
<     if tkevent.keycode == 100 or os.name=='posix':
---
 >     if tkevent.keycode == 100 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5636148):
678c773,774
<     if tkevent.keycode == 99 or os.name=='posix':
---
 >     if tkevent.keycode == 99 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5570611):
683c779,780
<     if tkevent.keycode == 98 or os.name=='posix':
---
 >     if tkevent.keycode == 98 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5505074):
688c785,786
<     if tkevent.keycode == 97 or os.name=='posix':
---
 >     if tkevent.keycode == 97 or (os.name=='posix' and 
sys.platform!='darwin') \
 >         or (sys.platform=='darwin' and tkevent.keycode == 5439537):
836,837c934,935
<     self._txt = ScrolledText(self._tk, fg="white", bg="black",
<                              font=fnt, height=20)
---
 >     self._txt = ScrolledText(self._tk, fg=master.color_foreground, 
 >                              bg=master.color_background, font=fnt, 
height=20)
846,869d943
<   def convertColor(self, name):
<     """
<     Tk has this really weird color palatte.  So I switched to using
<     color names in most cases and rgb values in cases where I couldn't
<     find a good color name.
<
<     This method allows me to specify either an rgb or a color name
<     and it converts the color names to rgb.
<
<     @param name: either an rgb value or a name
<     @type  name: string
<
<     @returns: the rgb color value
<     @rtype: string
<     """
<     if name[0] == "#":
<       return name
<
<     rgb = self._tk._getints(self._tk.tk.call('winfo', 'rgb', 
self._txt, name))
<     rgb = "#%02x%02x%02x" % (rgb[0]/256, rgb[1]/256, rgb[2]/256)
<     print name, "converted to: ", rgb
<
<     return rgb
<
872,879c946,948
<     for ck in fg_color_codes.keys():
<       color = self.convertColor(fg_color_codes[ck])
<       self._txt.tag_config(ck, foreground=color)
<
<     for ck in bg_color_codes.keys():
<       self._txt.tag_config(ck, background=bg_color_codes[ck])
<
<     self._txt.tag_config("u", underline=1)
---
 >     globalInitColorTags(self._txt, self._parent.color_foreground,
 >       self._parent.color_background, self._parent._basefont,
 >       self._parent._boldfont, 1)
970c1039
<     self._txt = ScrolledText(self._frame, fg="white", bg="black",
---
 >     self._txt = ScrolledText(self._frame, fg=DEFAULT_TK_FOREGROUND, 
bg=DEFAULT_TK_BACKGROUND,
994a1064
 > # utility functions
995a1066,1092
 > def convertColor(name, textpane):
 >   """
 >   Tk has this really weird color palatte.  So I switched to using
 >   color names in most cases and rgb values in cases where I couldn't
 >   find a good color name.
 >
 >   This method allows me to specify either an rgb or a color name
 >   and it converts the color names to rgb.
 >
 >   @param name: either an rgb value or a name
 >   @type  name: string
 >
 >   @returns: the rgb color value
 >   @rtype: string
 >   """
 >   if name.startswith("#"):
 >     return name
 >   try:
 >     rgb = textpane.winfo_rgb(name)
 >     rgb = "#%02x%02x%02x" % (rgb[0]/256, rgb[1]/256, rgb[2]/256)
 >     print name, "converted to: ", rgb
 >
 >     return rgb
 >   except:
 >     exported.write_error("Color " + name + " is invalid. Substituting 
with black")
 >     return "#000000"
 >      
1024c1121
<       line = "%s%s%s\n" % (ansi.get_color("b blue"),
---
 >       line = "%s%s%s\n" % (ansi.get_color(myui.color_message_error),
1028c1125
<       line = "%s%s%s" % (ansi.get_color("b blue"),
---
 >       line = "%s%s%s" % (ansi.get_color(myui.color_message_error),
1033c1130
<     if myui._do_i_echo == 1:
---
 >     if myui._do_i_echo == 1 and myui._suppresslocalecho == 0:
1035c1132
<         line = "%s%s%s\n" % (ansi.get_color("b blue"),
---
 >         line = "%s%s%s\n" % 
(ansi.get_color(myui.color_message_userdata),
1039c1136
<         line = "%s%s%s" % (ansi.get_color("b blue"),
---
 >         line = "%s%s%s" % (ansi.get_color(myui.color_message_userdata),
1043c1140
<       # if echo is not on--we don't print this
---
 >       # if echo is not on or is suppressed--we don't print this
1048c1145,1147
<       line = "# %s\n" % line[:-1].replace("\n", "\n# ")
---
 >       line = "%s# %s%s\n" % (ansi.get_color(myui.color_message_ltdata),
 >                             line[:-1].replace("\n", "\n# "),
 >                             ansi.get_color("default"))
1050c1149,1151
<       line = "# %s" % line.replace("\n", "\n# ")
---
 >       line = "%s# %s%s" % (ansi.get_color(myui.color_message_ltdata),
 >                           line.replace("\n", "\n# "),
 >                           ansi.get_color("default"))
1092d1192
<
1101c1201
<           fg = "37"
---
 >           fg = "default_as_fg"
1108a1209
 >        
1110c1211
<           fg = "30"
---
 >           fg = "screen_as_fg"
1115c1216
<           bg = "47"
---
 >           bg = "default_as_bg"
1118c1219
<
---
 >        
1129,1130c1230
<         format.append(bg)
<
---
 >         format.append(bg)
1145a1246,1313
 > def globalInitColorTags(textpane, fg, bg, basefont, boldfont, 
usebold):   
 >     """ Sets up Tk tags for the text widget (fg/bg/u).
 >   @param textpane: the text widget who's formatting tags are being 
initialized
 >   @type  textpane: TK text widget
 >
 >   @param fg: the default color as a TK color name or #RRGGBB or 
#RRRRGGGGBBBB
 >   @type  fg: string
 >
 >   @param bg: the background color as a TK color name or #RRGGBB or 
#RRRRGGGGBBBB
 >   @type  bg: string
 >  
 >   @param basefont: the non-bold version of the current font
 >   @type  basefont: tk font widget
 >  
 >   @param boldfont: the bold version of the current font
 >   @type  boldfont: tk font widget
 >  
 >   @param usebold: whether or not to actually use a bold font for the 
bold colors
 >   @type  boldfont: int, 1 for yes, 0 for no
 >
 >     """
 >    
 >     fnt = tkFont.nametofont(textpane["font"]).copy()
 >    
 >     fnt.config(weight = tkFont.BOLD)
 >     for ck in fg_color_codes.keys():
 >       color = convertColor(fg_color_codes[ck], textpane)
 >       if ck.startswith("b") and usebold == 1:
 >         textpane.tag_config(ck, foreground = color, font = boldfont)
 >       else:
 >         textpane.tag_config(ck, foreground = color, font = basefont)
 >
 >     for ck in bg_color_codes.keys():
 >       color = convertColor(bg_color_codes[ck], textpane)
 >       if ck.startswith("b") and usebold == 1:
 >         textpane.tag_config(ck, background = color, font = boldfont)
 >       else:
 >         textpane.tag_config(ck, background = color, font = basefont)
 >
 >     textpane.tag_config("u", underline=1)
 >     # remember these the default color is not necessarily represented 
by an ansi
 >     # color code so we use this tag for the default color. We need 
two versions
 >     # to handle the inverse code properly
 >     color = convertColor(fg, textpane)
 >     textpane.tag_config("default_as_fg", foreground = color, font = 
basefont)
 >     textpane.tag_config("default_as_bg", background = color, font = 
basefont)
 >
 >     # do the same for the screen (think of it as the default 
background color
 >     color = convertColor(bg, textpane)
 >     textpane.tag_config("screen_as_fg", foreground = color, font = 
basefont)
 >     textpane.tag_config("screen_as_bg", background = color, font = 
basefont) 
 >
 > def printAnsiAttributes(name, attributes):
 >   """This function simple prints out the ansi attributes in the 
attributes
 >   argument. Name gives a normalized description of what attributes 
are being
 >   described. It is shared amongst all the #XXXXansi commands. 
Honestly, if I
 >   understood introspection better, I would take advantage of it to 
standardized
 >   the processing rather than the ol' cut'n'paste
 >   """
 >   if attributes.find(",") == -1:
 >     exported.write_message("The ansi attribute for %s is %s" % (name, 
attributes))
 >   else:
 >     attrlist = [x.strip() for x in attributes.split(",")]
 >     attrlist.sort
 >     exported.write_message("The ansi attribute for %s are: %s" % 
(name, ", ".join(attrlist)))
 >
 > ## command functions
 >    
1149c1317,1319
<   properly.
---
 >   properly
 >  
 >   category: ui
1152a1323,1564
 >    
 > def default_color_cmd(ses, args, input):
 >   """
 >   This changes the default color of text. It takes a string parameter 
that can be
 >   an RBG value in #RRGGBB or #RRRRGGGGBBBB. In lieu of an RGB 
parameter it can
 >   also take a valid TK color name. If your interested in the TK 
palette you can
 >   learn a bit more at
 >   
http://www.pythonware.com/library/tkinter/introduction/widget-styling.htm
 >   and
 >   http://wiki.tcl.tk/3538
 >  
 >   Without any parameters, it tells you the current default color.
 >    
 >   category: ui
 >   """
 >   global myui
 >   color = args["name"]
 >   if len(color)==0:
 >     exported.write_message("Default foreground color is " + 
myui.color_foreground)
 >   else:
 >     myui.color_foreground = color
 >     converted_color = convertColor(color, myui._txt)
 >     for textpane in myui.getTextWidgetList():
 >       textpane.tag_config("default_as_fg", foreground = converted_color)
 >       textpane.tag_config("default_as_bg", background = converted_color)
 >       textpane.config(foreground = converted_color)
 >      
 >     exported.write_message("Default foreground color is now " + color)
 >    
 > def screencolor_cmd(ses, args, input):
 >   """
 >   This changes the color of the screen. It takes a string parameter 
that can be
 >   an RBG value in #RRGGBB or #RRRRGGGGBBBB. In lieu of an RGB 
parameter it can
 >   also take a valid TK color name. If your interested in the TK 
palette you can
 >   learn a bit more at
 >   
http://www.pythonware.com/library/tkinter/introduction/widget-styling.htm
 >   and
 >   http://wiki.tcl.tk/3538
 >  
 >   Without any parameters, it tells you the current screen color.
 >    
 >   category: ui
 >   """
 >   global myui
 >   color = args["name"]
 >   if len(color)==0:
 >     exported.write_message("The screen color is " + 
myui.color_background)
 >   else:
 >     myui.color_background = color
 >     converted_color = convertColor(color, myui._txt)
 >     for textpane in myui.getTextWidgetList():
 >       textpane.tag_config("screen_as_fg", foreground = converted_color)
 >       textpane.tag_config("screen_as_bg", background = converted_color)
 >       textpane.config(background = converted_color)
 >
 >     exported.write_message("The screen color is now " + color)
 >
 > def remap_cmd(ses, args, input):
 >   """
 >   #remap ansi={}, color={}
 >   This remaps an ansi color to any RGB color you choose. The ansi 
parameter
 >   can be either a number 30-37 for foreground colors or 40-47 for 
background
 >   colors. You can prepend 'b' before the number for the bolded or hi 
version of
 >   the color. The color parameter either takes a TK color name or a 
color in
 >   #RRGGBB or #RRRRGGGGBBBB format.
 >  
 >   Note: The hi or bolded version of background colors are in fact the 
foreground
 >   color when that background color is reversed. You can see this 
effect clearly
 >   by entering #remap to see the listing.
 >  
 >   If you leave it out color argument. it will show you the code for 
the current
 >   color. If you leave out both arguments, it will show you the 
complete list of
 >   colors.
 >  
 >   category: ui
 >   """
 >   global myui
 >   if len(args["ID"])==0:
 >     exported.write_message("Foreground Colors")
 >     keylist = fg_color_codes.keys()
 >     keylist.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
 >     for k in keylist:
 >         v = fg_color_codes[k]
 >         exported.write_message(k + " is mapped to " + chr(27) + "[" +\
 >         k.replace("b", "1;") + "m" + v  + chr(27) + "[0m")
 >     
 >     exported.write_message("\nBackground Colors")   
 >     keylist = bg_color_codes.keys()
 >     keylist.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
 >     for k in keylist:
 >         v = bg_color_codes[k]
 >         exported.write_message(k + " is mapped to " + chr(27) + "[" +\
 >         k.replace("b", "7;1;") + "m" + v  + chr(27) + "[0m")
 >  
 >   else:
 >     ansi_code = args["ID"]
 >     ansi_is_in = 0
 >     if ansi_code in fg_color_codes:
 >       ansi_is_in = 1
 >     elif ansi_code in fg_color_codes:  
 >       ansi_is_in = 2
 >    
 >     if ansi_is_in == 0:
 >       exported.write_error(ansi_code + " is not a valid color ID")
 >     else:
 >       # if color argument is present, we process
 >       if len(args["color"]) != 0:
 >         color = convertColor(args["color"], myui._txt)
 >         if ansi_is_in == 1:
 >           fg_color_codes[ansi_code] = color
 >           for textpane in myui.getTextWidgetList():
 >             textpane.tag_config(ansi_code, foreground = color)
 >          
 >         else:
 >           bg_color_codes[ansi_code] = color
 >           for textpane in myui.getTextWidgetList():
 >             textpane.tag_config(ansi_code, background = color)
 >          
 >       #either way we print the mapping
 >       if ansi_is_in == 1:
 >         exported.write_message(ansi_code + " is mapped to " + chr(27) 
+ "[" \
 >         + ansi_code.replace("b", "1;") + "m"  + 
fg_color_codes[ansi_code] \
 >         + chr(27) + "[0m")
 >        
 >       else:
 >         exported.write_message(ansi_code + " is mapped to " + chr(27) 
+ "[" \
 >         +  ansi_code.replace("b", "1;") + "m"  + 
bg_color_codes[ansi_code] \
 >         + chr(27) + "[0m")
 >      
 > def caretcolor_cmd(ses, args, input):
 >   """#caretcolor_cmd color={}
 >  
 >   This function changes the caret color in the text entry area. The 
color can be
 >   any TK color name or a color in #RRGGBB or #RRRRGGGGBBBB format.
 >    
 >   Without an argument, it shows the current caret color
 >  
 >   category: ui
 >   """
 >   global myui
 >   if len(args["color"]) == 0:
 >     exported.write_message("The current caret color is " + 
myui.color_caret)
 >   else:
 >     myui.color_caret = args["color"]
 >     color = convertColor(args["color"], myui._txt)
 >     myui._entry.config(insertbackground = color)
 >    
 > def erroransi_cmd(ses, args, input):
 >   """#erroransi ansi={}
 >  
 >   This function defines the ansi parameters that are used when 
displaying error
 >   messages. The ansi parameter is a list of the applicable ansi 
attributes i.e
 >   #erroransi {blue, reverse, bold}. Valid ansi attributes (drawn from 
ansi.py
 >   are:
 >    
 >     bold, underline, blink, reverse, black, red, green, yellow, blue, 
magenta,
 >     cyan, white, grey, light red, light green, light yellow, light blue,
 >     light magenta, light cyan, light white, b black, b red, b green, 
b yellow,
 >     b blue, b magenta, b cyan, b white or default
 >  
 >   If entered without the argument, the current attributes are shown
 >  
 >   category: ui
 >   """
 >   global myui
 >   if len(args["ansi"]) == 0:
 >     printAnsiAttributes("an error message", myui.color_message_error)
 >   else:
 >     attrs =[x.strip().lower() for x in args["ansi"].split(",") if 
ansi.STYLEMAP.has_key(x.strip().lower())]
 >     myui.color_message_error = ",".join(attrs)
 >    
 > def useransi_cmd(ses, args, input):
 >   """#useransi ansi={}
 >  
 >   This function defines the ansi parameters that are used when 
displaying user
 >   messages. The ansi parameter is a list of the applicable ansi 
attributes i.e
 >   #useransi {blue, reverse, bold}. Valid ansi attributes (drawn from 
ansi.py
 >   are:
 >    
 >     bold, underline, blink, reverse, black, red, green, yellow, blue, 
magenta,
 >     cyan, white, grey, light red, light green, light yellow, light blue,
 >     light magenta, light cyan, light white, b black, b red, b green, 
b yellow,
 >     b blue, b magenta, b cyan, b white or default
 >  
 >   If entered without the argument, the current attributes are shown
 >  
 >   category: ui
 >   """
 >   global myui
 >   if len(args["ansi"]) == 0:
 >     printAnsiAttributes("a user message", myui.color_message_userdata)
 >   else:
 >     # this list comprehension drops invalid ansi attributes
 >     attrs =[x.strip().lower() for x in args["ansi"].split(",") if 
ansi.STYLEMAP.has_key(x.strip().lower())]
 >     myui.color_message_userdata = ",".join(attrs)
 >    
 > def ltansi_cmd(ses, args, input):
 >   """#ltansi ansi={}
 >  
 >   This function defines the ansi parameters that are used when displaying
 >   messages from lyntin. The ansi parameter is a list of the 
applicable ansi
 >   attributes i.e. #ltansi {blue, reverse, bold}. Valid ansi 
attributes (drawn
 >   from ansi.py
 >   are:
 >    
 >     bold, underline, blink, reverse, black, red, green, yellow, blue, 
magenta,
 >     cyan, white, grey, light red, light green, light yellow, light blue,
 >     light magenta, light cyan, light white, b black, b red, b green, 
b yellow,
 >     b blue, b magenta, b cyan, b white or default
 >  
 >   If entered without the argument, the current attributes are shown
 >  
 >   category: ui
 >   """
 >   global myui
 >   if len(args["ansi"]) == 0:
 >     printAnsiAttributes("a lyntin message", myui.color_message_ltdata)
 >   else:
 >     # this list comprehension drops invalid ansi attributes
 >     attrs =[x.strip().lower() for x in args["ansi"].split(",") if 
ansi.STYLEMAP.has_key(x.strip().lower())]
 >     myui.color_message_ltdata = ",".join(attrs)
 >
 > def changefont_cmd(ses, args, input):
 >   """#changefont name={} size={}
 >   This command changes the font and/or size. Without arguments shows 
the current
 >   font description. Interestingly, positive numbers for size 
correspond to point
 >   sizes where as a negative number correspond to pixel height, per 
TKinter docs.
 >  
 >   category: ui
 >   """
 >   global myui
 >   if len(args["name"])==0 and len(args["size"])==0:
 >     exported.write_message("The current font is " + 
myui._basefont["family"] + \
 >     ", " + str(myui._basefont["size"]) + "pt")
 >   else:
 >     if len(args["size"]) !=0:
 >       myui._basefont.config(size = args["size"])
 >       myui._boldfont.config(size = args["size"])
 >      
 >     if len(args["name"]) !=0:
 >       myui._basefont.config(family = args["name"])
 >       myui._boldfont.config(family = args["name"])



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click