[DIFF] an honest-to-god configurable statusbar for TKUI

Eliezer Flores <[email protected]> Wed, 04 Jan 2006 21:35:49 -0500
Newsgroups gmane.comp.games.mud.client.lyntin
Message-ID <[email protected]>
Okies, this should be my last TKUI diff for a bit. But before we get 
onto business, let's get a coupla things out of the way.

- for the love of God, just call me Eli. Noone calls me Eliezer. Mainly 
because they can't pronounce it except for my momma when she's angry ;)
- I've got a nifty add-on module that I'd like to submit. It works in 
conjuction with a mysql database to calculate paths between two points 
(i.e. you define a->b, b->c, c->d and #findpath {a} {d} and it executes 
the associated scripts of a->b, b->c, c->d. Except it uses an actual 
pathfinding algorithm (Dijkstra's if you must know) so it can handle 
branching paths i.e. if you have a->b, b->c, b->d, b->e, c->f, d->f, 
e->f , #findpath {a} {f} will recognize it can go through c,d or e on 
the way to f and will take the path that is the "lightest" (as you can 
weight paths). It's meant to be some example code and i'm sure people 
would like or use it as a solid starting point for similiar addons. So 
who should I send it to?

But this diff adds the following features from the cvs tkui.py:
- allows tkui to run on os x (previous diff)
- adds a number of visual configuration commands (to change font, color, 
remap ansi colors and the like) (previous diff)
- adds configurable statusbar. It appears above the text entry area and 
you can turn it off and on. It also adds support commands that allows 
you to add elements (static or variable), configure the visual 
appearance of those elements. The cool thing: if you add a variable 
element and the variable changes, it automatically updates. Woot!

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,100
< """
---
 >   """
 > 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
 >
 > To bind function key and numpad bindings, create an alias for the
 > symbol.  For example:
85a102,103
 >    #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,205c240,248
<       fnt = tkFont.Font(family="Fixedsys", size=12)
<
---
 >       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')
 >     # testing making a configurable status bar
207,209c250
<     self._entry = CommandEntry(self._tk, self, fg='white', bg='black',
<                                insertbackground='yellow', font=fnt,
<                                insertwidth='2')
---
 >    
211c252
<
---
 >    
212a254,256
 >     self._statusframe = Frame(self._tk)
 >     self._statusframe.pack(side='bottom', fill='x')
 >    
213a258
 >     self._statusbar = StatusBar(self._statusframe, self)
215,216c260,263
<     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,222c268,269
<     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)
241c288,300
<
---
 >    
 >     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)
249c308,326
<
---
 >     # visual configurations commands
 >     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=")
 >     # statusbar commands
 >     exported.add_command("turnstatus", statusbar_cmd, "status:boolean")
 >     exported.add_command("addlbl", add_static_cmd, \
 >                           "text fg= bg= position:int=-1")
 >     exported.add_command("rmelement", remove_element_cmd, "name=")
 >     exported.add_command("addvar", add_variable_cmd, \
 >                           "name fg= bg= position:int=-1 value=")
 >                          
 >     exported.add_command("setvar", setvariable_cmd, "name value=")
 >     exported.add_command("confelement", configure_element_cmd, "name 
option value")
309a387,399
 >    
 >   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,320c408,412
<     # 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 )):
322c414
<
---
 >      
399a492,512
 >    
 >     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,474d564
<   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
475a566
 >      
478,489c569,573
<     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,538c618,629
<
<     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)
 >    
568a660,672
 >     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)
569a674
 >      
632d736
<
646a751,756
 >   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"
 >
648c758,759
<     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):
653c764,765
<     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,659c770,771
<     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):
663c775,776
<     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):
668c781,782
<     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):
673c787,788
<     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):
678c793,794
<     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):
683c799,800
<     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):
688c805,806
<     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,837c954,955
<     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,869d963
<   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,879c966,968
<     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)
970c1059
<     self._txt = ScrolledText(self._frame, fg="white", bg="black",
---
 >     self._txt = ScrolledText(self._frame, fg=DEFAULT_TK_FOREGROUND, 
bg=DEFAULT_TK_BACKGROUND,
993a1083,1179
 >    
 > class StatusBar:
 >   """The status bar class handles all the details of managing the 
status bar
 >   """
 >   def __init__(self, frame, ui):
 >     self._frame = frame
 >     self._ui = ui
 >     self._labels = {}
 >     self._order = []
 >     self._variables = {}
 >     self.addLabel("Empty Status bar", fg = "white", bg ="black")
 >     exported.hook_register("variable_change_hook", self._check_variable)
 >    
 >   def addLabel(self, text, fg, bg, position = -1):
 >     """adds a label element to the status bar"""
 >     lbl = Label(self._frame, font=self._ui._basefont, fg=fg, bg=bg, 
text=text)
 >     self._addElement(name=text, position = position, lbl=lbl)
 >      
 >      
 >    
 >   def addVariable(self, varname, fg, bg, position = 0, defval=''):
 >     """adds a variable element to the status bar"""
 >     var = StringVar()
 >     self._variables[varname] = var
 >     var.set(defval)
 >     lbl = Label(self._frame, font=self._ui._basefont, fg=fg, bg=bg, \
 >                 textvariable=var)
 >     self._addElement(name=varname, position = position, lbl=lbl)
 >    
 >    
 >   def _addElement(self, name, position, lbl):
 >     """this is generic add element routine"""
 >     if name in self._labels.keys():
 >       exported.write_message("The element name, " + name + \
 >                              ", is already in use")
 >     else:
 >       self._labels[name] = lbl
 >       #hide the current elements
 >       for element in self._order:
 >         self._labels[element].pack_forget()
 >       #add new element
 >       if position == -1:
 >         self._order.append(name)
 >       else:
 >         self._order.insert(position, name)
 >       #show elements
 >       for element in self._order:
 >         self._labels[element].pack(side = 'left', anchor='w')
 >        
 >       self._frame.pack_propagate()
 >  
 >   def _check_variable(self,args):
 >     """processes the variable_change_hook"""
 >     var = args["variable"]
 >     if var in self._variables:
 >       self._variables[var].set(args["newvalue"])
 >      
 >   def configureElement(self, var, option, value):
 >     """configures the visual parameters of an element"""
 >     if var in self._labels:
 >       lbl = self._labels[var]
 >       if option in lbl.keys():
 >         lbl[option] = value
 >         self._frame.pack_propagate()
 >  
 >   def removeElement(self,name):
 >     """This removes an element from the status bar"""
 >     if name in self._labels.keys():
 >       self._labels[name].pack_forget()
 >       del self._labels[name]
 >       self._order.remove(name)
 >       if self._variables.has_key(name):
 >         del self._variables[name]
 >  
 >   def setVariable(self, name, value):
 >     """this sets a variable in the status in the status bar"""
 >     if name in self._variables.keys():
 >       self._variables[name].set(value)
 >     else:     
 >       exported.write_message("There is no variable '%s' in the status 
bar" \
 >                               % name)
 >  
 >   def ElementList(self):
 >     """This returns a list containing all the names of the elements 
in statusbar
 >     """
 >     return self._order
 >        
 > # utility functions
 >
 > 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.
994a1181,1182
 >   @param name: either an rgb value or a name
 >   @type  name: string
995a1184,1198
 >   @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"
 >      
1024c1227
<       line = "%s%s%s\n" % (ansi.get_color("b blue"),
---
 >       line = "%s%s%s\n" % (ansi.get_color(myui.color_message_error),
1028c1231
<       line = "%s%s%s" % (ansi.get_color("b blue"),
---
 >       line = "%s%s%s" % (ansi.get_color(myui.color_message_error),
1033c1236
<     if myui._do_i_echo == 1:
---
 >     if myui._do_i_echo == 1 and myui._suppresslocalecho == 0:
1035c1238
<         line = "%s%s%s\n" % (ansi.get_color("b blue"),
---
 >         line = "%s%s%s\n" % 
(ansi.get_color(myui.color_message_userdata),
1039c1242
<         line = "%s%s%s" % (ansi.get_color("b blue"),
---
 >         line = "%s%s%s" % (ansi.get_color(myui.color_message_userdata),
1043c1246
<       # if echo is not on--we don't print this
---
 >       # if echo is not on or is suppressed--we don't print this
1048c1251,1253
<       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"))
1050c1255,1257
<       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"))
1092d1298
<
1101c1307
<           fg = "37"
---
 >           fg = "default_as_fg"
1108a1315
 >        
1110c1317
<           fg = "30"
---
 >           fg = "screen_as_fg"
1115c1322
<           bg = "47"
---
 >           bg = "default_as_bg"
1118c1325
<
---
 >        
1129,1130c1336
<         format.append(bg)
<
---
 >         format.append(bg)
1145a1352,1419
 > 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
 >    
1149c1423,1425
<   properly.
---
 >   properly
 >  
 >   category: ui
1152a1429,1722
 >    
 > 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.color
 >   """
 >   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.color
 >   """
 >   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):
 >   """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):
 >   """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.color
 >   """
 >   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):
 >   """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.ansi
 >   """
 >   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):
 >   """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.ansi
 >   """
 >   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):
 >   """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.ansi
 >   """
 >   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):
 >   """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"])
 >      
 > def statusbar_cmd(ses, args, input):
 >   """This will turn the statusbar on or off
 >  
 >   category: ui.statusbar
 >   """
 >   global myui
 >   if args["status"]==1:
 >     myui._statusframe.pack(side='bottom', fill='x')
 >     exported.hook_register("variable_change_hook", 
myui._statusframe._check_variable)
 >   else: 
 >     myui._statusframe.pack_forget()
 >     exported.hook_unregister("variable_change_hook", 
myui._statusframe._check_variable)
 >    
 > def add_static_cmd(ses, args, input):
 >   """This command adds a static element to the status bar. The bg and 
fg paramters
 >   can being either a TK named color or color in #RRGGBB or 
#RRRRGGGGBBB format.
 >   They default to same as the current screen.
 >  
 >   Position is where in the status bar you want it located. It starts 
with 0 and
 >   goes from left to right. It defaults to -1 which means appends to 
end of
 >   the statusbar.
 >  
 >   Label elements are set-once elements. If you have to change a 
statusbar's
 >   element dynamically, use the the #addvar command
 >  
 >   category: ui.statusbar
 >   """
 >   global myui
 >   if len(args["fg"]) == 0:
 >     fg = myui.color_foreground
 >   else:
 >     fg = args["fg"]
 >    
 >   if len(args["bg"]) == 0:
 >     bg = myui.color_background
 >   else:
 >     bg = args["bg"]
 >    
 >   position = args["position"]
 >   text = args["text"]
 >   myui._statusbar.addLabel(text, fg, bg, position)
 >  
 > def remove_element_cmd(ses, args, input):
 >   """This removes the element in the name parameter from the status 
bar. If a name
 >   parameter is not passed it givens the current list of elements as 
they appear
 >   on the status bar
 >  
 >   category: ui.statusbar
 >   """
 >   global myui
 >   name = args["name"]
 >   if len(name)==0:
 >     elements = myui._statusbar.ElementList()
 >     if len(elements) > 0:
 >       exported.write_message("The status bar contains the following 
elements: "\
 >         + ", ".join(elements), ses)
 >     else:
 >       exported.write_message("The status bar is empty", ses)
 >      
 >   elif name in myui._statusbar._labels.keys():   
 >     myui._statusbar.removeElement(name)
 >   else:
 >     exported.write_error("There is no element named " + name + \
 >                           " in the status bar", ses)
1153a1724,1782
 > def add_variable_cmd(ses, args, input):
 >   """This command adds a variable element to the status bar. The bg 
and fg
 >   paramters can being either a TK named color or color in #RRGGBB or
 >   #RRRRGGGGBBB format. They default to same as the current screen.
 >  
 >   Position is where in the status bar you want it located. It starts 
with 0 and
 >   goes from left to right. It defaults to -1 which means appends to 
end of
 >   the statusbar. Value provides the initial value.
 >  
 >   You can update a variable element either by using the #setvar 
command or by
 >   changing the value of the variable.I.e.
 >   #addvar {test}
 >   #variable {test} {this is hella cool}
 >   will put the this is hella cool in the status bar
 >  
 >   category: ui.statusbar
 >   """
 >   global myui
 >   if len(args["fg"]) == 0:
 >     fg = myui.color_foreground
 >   else:
 >     fg = args["fg"]
 >    
 >   if len(args["bg"]) == 0:
 >     bg = myui.color_background
 >   else:
 >     bg = args["bg"]
 >    
 >   position = args["position"]
 >   name = args["name"]
 >   myui._statusbar.addVariable(name, fg, bg, position, args["value"])
 >  
 > def setvariable_cmd(ses, args, input):
 >   """This command sets the value of a variable element in the status bar
 >  
 >   category: ui.statusbar
 >   """
 >   myui._statusbar.setVariable(args["name"], args["value"])
 >  
 > def configure_element_cmd(ses, args, input):
 >   """Use this configure any element (label or variable) parameters. 
You can
 >   learn a bit more about what the options are, you can check out this:
 >    
 >   
http://www.pythonware.com/library/tkinter/introduction/x5258-options.htm
 >  
 >   If you try anything wonky, it will ignore it silently in most cases.
 >  
 >   category: ui.statusbar
 >   """
 >   name = args["name"]
 >   option = args["option"]
 >   value = args["value"]
 >   try:
 >     myui._statusbar.configureElement(name, option, value)
 >   except:
 >     exported.write_error("Error: An error occurred setting the 
element with \
 >     that option, value pair", ses)
 >    
 >   
1158a1788
 >


-------------------------------------------------------
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