diff --git a/twander.py b/twander.py index 6fffff3..d5e0b27 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ # For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.56 2003/01/13 22:06:09 tundra Exp $" +RCSID = "$Id: twander.py,v 2.57 2003/01/14 22:05:09 tundra Exp $" VERSION = RCSID.split()[2] @@ -471,7 +471,6 @@ UI.CmdTable = {} UI.FuncKeys = ["", "", "", "", "", "", "", "", "", "", "", ""] - UI.OptionsNumeric = ["DEBUGLEVEL", "FSZ", "HEIGHT", "MAXDIR", "MAXHIST", "MAXNESTING", "REFRESHINT", "WIDTH"] UI.SymTable = {} linenum = 0 @@ -560,7 +559,18 @@ else: WrnMsg(wNOCMDS) + # Any user-set options have now been read, set the GUI + + for i in (UI.CmdBtn, UI.DirBtn, UI.HistBtn): + i.config(font=(FNAME, FSZ, "bold")) + i.menu.config(font=("courier", FSZ, "bold")) + + UI.DirList.config(font=(FNAME, FSZ, FWT), + foreground=FCOLOR, background=BCOLOR, + height=HEIGHT, width=WIDTH) + # Dump requested debug information + if int(DEBUGLEVEL) & DEBUGKEYS: debuginfo = [] @@ -599,6 +609,15 @@ PrintDebug(dCMDTBL, debuginfo) + # Dump program variable during debug sessions + if int(DEBUGLEVEL) & DEBUGVARS: + + debuginfo = [] + for v in DebugVars: + debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) + + PrintDebug(dINTVAR, debuginfo) + # End of 'ParseConfFile()' @@ -721,9 +740,22 @@ # Process any option variables + elif name in UI.OptionsBoolean: + val = val.upper() + if val == 'TRUE' or val == 'FALSE': + globals()[name] = eval(val) # !!! Cheater's way to get to global variables. + else: + WrnMsg(wBADVAL % (num, line)) + elif name in UI.OptionsNumeric: try: - globals()[name] = int(val) # !!! Cheater's way to get to global variables. + globals()[name] = int(val) + except: + WrnMsg(wBADVAL % (num, line)) + + elif name in UI.OptionsString: + try: + globals()[name] = val except: WrnMsg(wBADVAL % (num, line)) @@ -2413,6 +2445,12 @@ UI.BuiltIns = {DIR:"", DSELECTION:"", DSELECTIONS:"", HASH:"", PROMPT:"", SELECTION:"", SELECTIONS:""} +# Options which can be set in the configuration file + +UI.OptionsBoolean = ["AUTOREFRESH", "WARN"] +UI.OptionsNumeric = ["DEBUGLEVEL", "FSZ", "HEIGHT", "MAXDIR", "MAXHIST", "MAXNESTING", "REFRESHINT", "WIDTH"] +UI.OptionsString = ["BCOLOR", "FCOLOR", "FNAME", "FWT", "QUOTECHAR", "STARTDIR"] + # Prepare storage for key bindings UI.KeyBindings = {} @@ -2433,10 +2471,19 @@ ##### -# Command line processing - Process any options set in the -# environment first, and then those given on the command line +# Command line processing - Options are set with the +# following priority scheme (lowest to highest): +# +# 1) Defaults coded into the program +# 2) Options set in the configuration file +# 3) Options set in the environment variable +# 4) Options set on the command line +# ##### +# Concatenate any environment variable with the +# command line so the command line takes precedence. + OPTIONS = sys.argv[1:] envopt = os.getenv(PROGNAME.upper()) if envopt: @@ -2448,8 +2495,29 @@ Usage() sys.exit(1) -# Read configuration file in first - this allows -# environment variable and then command line to override its settings later +# If the user wants help or version information, do this first +# so we don't bother with other options processing + +for opt, val in opts: + if opt == "-h": + Usage() + sys.exit(0) + if opt == "-v": + print RCSID + sys.exit(0) + +# Read the debug level before anything else so that any +# subsequent operations will observe this. + +for opt, val in opts: + if opt == "-d": + DEBUGLEVEL = val + if int(DEBUGLEVEL): + print dHEADER % time.asctime() + +# Read configuration file before any other arguments. This allows the +# environment variable and then the command line to override any +# settings in the configuration file. for opt, val in opts: if opt == "-c": @@ -2457,19 +2525,13 @@ ParseConfFile(None) -# Parse the rest of the command line +# Process the rest of the options, if any + for opt, val in opts: if opt == "-b": BCOLOR = val - if opt == "-d": - DEBUGLEVEL = val - if int(DEBUGLEVEL): - print dHEADER % time.asctime() if opt == "-f": FCOLOR = val - if opt == "-h": - Usage() - sys.exit(0) if opt == "-n": FNAME = val if opt == "-q": @@ -2480,9 +2542,6 @@ FSZ = val if opt == "-t": QUOTECHAR = "" - if opt == "-v": - print RCSID - sys.exit(0) if opt == "-w": FWT = val if opt == "-x": @@ -2520,16 +2579,6 @@ # Get starting directory into canonical form STARTDIR = os.path.abspath(STARTDIR) -# Now that all user switches have been read, set GUI options - -for i in (UI.CmdBtn, UI.DirBtn, UI.HistBtn): - i.config(font=(FNAME, FSZ, "bold")) - i.menu.config(font=("courier", FSZ, "bold")) - -UI.DirList.config(font=(FNAME, FSZ, FWT), - foreground=FCOLOR, background=BCOLOR, - height=HEIGHT, width=WIDTH) - # Setup event handlers - We have to do this here just # in case we could not read any config file, which # is when we normally bind the handlers. @@ -2552,16 +2601,6 @@ LoadDirList(STARTDIR) KeySelTop(None) -# Dump program variable during debug sessions -if int(DEBUGLEVEL) & DEBUGVARS: - - debuginfo = [] - for v in DebugVars: - debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) - - PrintDebug(dINTVAR, debuginfo) - - # If we just wanted debug output, quit now if int(DEBUGLEVEL) & DEBUGQUIT: sys.exit()