diff --git a/twander.py b/twander.py index b987add..4caf6ed 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.51 2002/11/14 04:04:46 tundra Exp $" +RCSID = "$Id: twander.py,v 1.52 2002/11/14 21:29:53 tundra Exp $" VERSION = RCSID.split()[2] @@ -35,6 +35,7 @@ GOUP = '' KEYPRESS = '' QUITPROG = '' +READCONF = '' SELECTKEY = '' SELECTMOUSE = '' @@ -201,16 +202,23 @@ ##### # Parse & Process The Configuraton File +# This is called once at program start time +# and again any time someone hits the READCONF key +# while the program is running. ##### -def ParseRC(): - +def ParseConfFile(*args): + global UI + try: cf = open(CONF) except: ErrMsg(eOPEN % CONF) sys.exit(1) + # Cleanout any old + UI.rcfile = {} + # Process and massage the configuration file for line in cf.read().splitlines(): @@ -254,19 +262,19 @@ else: key = fields[0][keypos+1].lower() - if key in rcfile: # This is a Python 2.2 or later idiom + if key in UI.rcfile: # This is a Python 2.2 or later idiom ErrMsg(eDUPKEY % fields[0]) # Duplicate key found cf.close() sys.exit(1) # Save command name and command using key as index - rcfile[key] = ["".join(fields[0].split(CMDKEY)), + UI.rcfile[key] = ["".join(fields[0].split(CMDKEY)), " ".join(fields[1:]) ] cf.close() -# End of 'ParseRC()' +# End of 'ParseConfFile()' ##### @@ -345,6 +353,9 @@ # Bind handler for "Up Dir" root.bind(GOUP, KeyUpDir) + # Bind handler of "Read Config File" + root.bind(READCONF, ParseConfFile) + # Bind handler for "Item Select" root.bind(SELECTKEY, DirListHandler) @@ -659,7 +670,7 @@ # get its associated string and # execute the command. - cmd = rcfile.get(event.char.lower(), ["",""])[1] + cmd = UI.rcfile.get(event.char.lower(), ["",""])[1] # cmd == null means no matching command key - do nothing # Otherwise, replace config tokens with actual file/dir names @@ -726,11 +737,6 @@ ErrMsg(eNOCONF % CONF) sys.exit(1) -# Parse contents into dictionary - -rcfile = {} -ParseRC() - # Create an instance of the UI UIroot = Tk() UI = twanderUI(UIroot) @@ -758,6 +764,10 @@ # Initialize directory stack UI.lastdir = [] +# Parse contents into dictionary + +ParseConfFile() + # Canonicalize UI.rootdir UI.rootdir = os.path.abspath(UI.rootdir) + PSEP