diff --git a/twander.py b/twander.py index 3f9b245..dd1edc9 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.37 2002/12/31 01:17:56 tundra Exp $" +RCSID = "$Id: twander.py,v 2.38 2003/01/02 17:19:46 tundra Exp $" VERSION = RCSID.split()[2] @@ -156,7 +156,7 @@ AUTOREFRESH = TRUE # Automatically refresh the directory display -DEBUG = FALSE # Debugging on +DEBUGLEVEL = 0 # No debug output WARN = TRUE # Warnings on ##### @@ -188,6 +188,16 @@ Button4Mask = (1<<11) Button5Mask = (1<<12) +# Debug Levels + +DEBUGQUIT = (1<<0) # Dump debug info and quit program +DEBUGVARS = (1<<1) # Dump internal variables +DEBUGSYMS = (1<<2) # Dump symbol table +DEBUGCTBL = (1<<3) # Dump command table +DEBUGCMDS = (1<<4) # Dump command execution string +DEBUGKEYS = (1<<5) # Dump key bindings +DEBUGDIRS = (1<<6) # Dump directory stack contents as it changes + # Stat-Related Constants @@ -266,6 +276,7 @@ dCMD = "COMMAND: " dCMDTBL = "" +dHEADER = "twander Debug Dump Run On: %s\n" dINTVAR = "" dKEYBINDS = "" dNULL = "None" @@ -304,7 +315,7 @@ wCONFOPEN = "Cannot Open Configuration File:\n%s\n\n%s" wMOUSEBIND = "Cannot Rebind A Mouse Button Combination.\nIgnoring Line %s:\n\n%s" wNOCMDS = "Running With No Commands Defined!" -wSYMBACK = " Symbolic Link %s Points Back To Own Directory" +wSYMBACK = "Symbolic Link %s Points Back To Own Directory" wWARN = "WARNING" @@ -457,17 +468,19 @@ # Close the config file cf.close() - # Set the Command Menu Contents, if any, - # and enable the menu if it has entries + # and enable the menu if it has entries. + # If no commands are defined, warn the user. UI.CmdBtn.configure(state=DISABLED) if UI.CmdBtn.menu.index(END): UI.CmdBtn['menu'] = UI.CmdBtn.menu UI.CmdBtn.configure(state=NORMAL) + else: + WrnMsg(wNOCMDS) # Dump tables if we're debugging - if DEBUG: + if int(DEBUGLEVEL) & DEBUGKEYS: print dKEYBINDS + "\n" keylist = [] @@ -480,6 +493,8 @@ print key + " " * (10-len(key)) + UI.KeyBindings[key] print + if int(DEBUGLEVEL) & DEBUGSYMS: + print dSYMTBL + "\n" syms = [] for sym in UI.SymTable.keys(): @@ -490,6 +505,8 @@ print sym + " " * (16-len(sym)) + UI.SymTable[sym] print + if int(DEBUGLEVEL) & DEBUGCTBL: + print dCMDTBL + "\n" for key in UI.CmdTable.keys(): name = UI.CmdTable[key][0] @@ -1036,7 +1053,8 @@ # but only if there are commands defined. if UI.CmdBtn.menu.index(END): - UI.CmdBtn.menu.tk_popup(UI.DirList.winfo_pointerx(), UI.DirList.winfo_pointery()) + x, y = UI.DirList.winfo_pointerxy() + UI.CmdBtn.menu.tk_popup(x, y) # End of 'ContextMenu()' @@ -1100,8 +1118,8 @@ # Just dump command if we're debugging - if DEBUG: - print dCMD, cmd + if int(DEBUGLEVEL) & DEBUGCMDS: + print dCMD, cmd, '\n' # Otherwise,actually execute the command else: @@ -1516,6 +1534,8 @@ if save and UI.CurrentDir: UI.LastDir.append(UI.CurrentDir) + if int(DEBUGLEVEL) & DEBUGDIRS: + print UI.LastDir, '\n' # And select new directory to visit UI.CurrentDir = newdir @@ -1836,7 +1856,7 @@ # Command line processing try: - opts, args = getopt.getopt(sys.argv[1:], '-b:c:df:hn:qrs:tvw:x:y:') + opts, args = getopt.getopt(sys.argv[1:], '-b:c:d:f:hn:qrs:tvw:x:y:') except getopt.GetoptError: Usage() sys.exit(1) @@ -1849,7 +1869,9 @@ if opt == "-c": CONF = os.path.abspath(val) if opt == "-d": - DEBUG = TRUE + DEBUGLEVEL = val + if int(DEBUGLEVEL): + print dHEADER % time.asctime() if opt == "-f": FCOLOR = val if opt == "-h": @@ -1880,10 +1902,10 @@ DebugVars = ["RCSID","OSNAME", "STARTDIR", "HOME", "CONF", "HEIGHT", "WIDTH", "BCOLOR", "FCOLOR", "FNAME", "FSZ", "FWT", - "AUTOREFRESH", "DEBUG", "WARN", "PSEP", "QUOTECHAR", "POLLINT", "REFRESHINT"] + "AUTOREFRESH", "DEBUGLEVEL", "WARN", "PSEP", "QUOTECHAR", "POLLINT", "REFRESHINT"] # Dump program variable during debug sessions -if DEBUG: +if int(DEBUGLEVEL) & DEBUGVARS: print dINTVAR + "\n" for v in DebugVars: print v + " " * (12-len(v)) + (str(eval(v)) or dNULL) @@ -1962,6 +1984,10 @@ # And start the periodic polling of the widget UI.poll() +# If we just wanted debug output, quit now +if int(DEBUGLEVEL) & DEBUGQUIT: + sys.exit() + # Run the program interface UIroot.mainloop()