diff --git a/twander.py b/twander.py index fb8aa86..0ce8fca 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.89 2003/01/31 23:08:14 tundra Exp $" +RCSID = "$Id: twander.py,v 2.90 2003/02/03 22:46:07 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -128,6 +128,35 @@ SELKEY = '' # Select item w/keyboard MOUSESEL = '' # Select item w/mouse +# Program Memories + +MEMCLR1 = '' +MEMCLR2 = '' +MEMCLR3 = '' +MEMCLR4 = '' +MEMCLR5 = '' +MEMCLR6 = '' +MEMCLR7 = '' +MEMCLR8 = '' +MEMCLR9 = '' +MEMCLR10 = '' +MEMCLR11 = '' +MEMCLR12 = '' + +MEMCLRALL = '' # Clear all memories + +MEMSET1 = '' # Set program memories +MEMSET2 = '' +MEMSET3 = '' +MEMSET4 = '' +MEMSET5 = '' +MEMSET6 = '' +MEMSET7 = '' +MEMSET8 = '' +MEMSET9 = '' +MEMSET10 = '' +MEMSET11 = '' +MEMSET12 = '' ##### # GUI Defaults @@ -238,6 +267,8 @@ KB = 1024 # 1 KB constant MB = KB * KB # 1 MB constant GB = MB * KB # 1 GB constant +NUMFUNCKEY = 12 # Number of function keys +NUMPROGMEM = 12 # Number of program memories POLLINT = 20 # Interval (ms) the poll routine should run PSEP = os.sep # Character separating path components SHOWDRIVES = '\\\\' # Logical directory name for Win32 Drive Lists @@ -437,6 +468,18 @@ DSELECTION = r'[DSELECTION]' DSELECTIONS = r'[DSELECTIONS]' HASH = r'[HASH]' +MEM1 = r'[MEM1]' +MEM2 = r'[MEM2]' +MEM3 = r'[MEM3]' +MEM4 = r'[MEM4]' +MEM5 = r'[MEM5]' +MEM6 = r'[MEM6]' +MEM7 = r'[MEM7]' +MEM8 = r'[MEM8]' +MEM9 = r'[MEM9]' +MEM10 = r'[MEM10]' +MEM11 = r'[MEM11]' +MEM12 = r'[MEM12]' PROMPT = r'[PROMPT:' SELECTION = r'[SELECTION]' SELECTIONS = r'[SELECTIONS]' @@ -524,14 +567,26 @@ # 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 +# Nibble #1 + +DEBUGVARS = (1<<0) # Dump internal variables +DEBUGSYMS = (1<<1) # Dump symbol table +DEBUGCTBL = (1<<2) # Dump command table +DEBUGKEYS = (1<<3) # Dump key bindings + +# Nibble #2 + DEBUGCMDS = (1<<4) # Dump command execution string -DEBUGKEYS = (1<<5) # Dump key bindings -DEBUGDIRS = (1<<6) # Dump directory stack contents as it changes -DEBUGHIST = (1<<7) # Dump contents of Command History stack after command execution +DEBUGDIRS = (1<<5) # Dump directory stack contents as it changes +DEBUGHIST = (1<<6) # Dump contents of Command History stack after command execution +DEBUGMEM = (1<<7) # Dump contents of program memories as they change + +# Nibble #3 + +DEBUGRSRV1 = (1<<8) # Reserved for future use +DEBUGRSRV2 = (1<<9) +DEBUGRSRV3 = (1<<10) +DEBUGQUIT = (1<<11) # Dump debug info and quit program # Debug Strings @@ -543,6 +598,8 @@ dHIST = "COMMAND HISTORY STACK" dINTVAR = hINTVBLS dKEYBINDS = hKEYS +dMEM = "CONTENTS OF MEMORY %s" +dMEMALL = "CONTENTS OF ALL PROGRAM MEMORIES" dNULL = "None" dOPTVAR = hOPTVBLS dSYMTBL = hUSERVBLS @@ -554,6 +611,7 @@ dKEYWIDTH = 16 dOPTIONWIDTH = 16 dSCWIDTH = 6 +dTWOUPWIDTH = 50 dUSRVBLWIDTH = 16 # List of internal program variables to dump during debug sessions @@ -572,14 +630,18 @@ " or PROGDIR/." + PROGNAME + ")", " -d level set debugging level (default: 0, debugging off)", " Bit Assignments:", - " 0 - Dump Requested Debug Information And Exit Immediately", - " 1 - Dump Internal Program Variables And User-Settable Options", - " 2 - Dump User-Defined Variables", - " 3 - Dump Command Definitions", - " 4 - Display, Do Not Execute, Commands When Invoked", - " 5 - Dump Key Bindings And Directory Shortcut Assignments", - " 6 - Dump Directory Stack As It Changes", - " 7 - Dump Command History Stack After Command Executes", + " 0 - Dump Internal Options & User-Settable Options (0x001)", + " 1 - Dump User-Defined Variables (0x002)", + " 2 - Dump Command Definitions (0x004)", + " 3 - Dump Key Bindings (0x008)", + " 4 - Display, Do Not Execute, Commands When Invoked (0x010)", + " 5 - Dump Directory Stack As It Changes (0x020)", + " 6 - Dump Command History Stack After Command Executes (0x040)", + " 7 - Dump Contents Of Program Memories As They Change (0x080)", + " 8 - Reserved", + " 9 - Reserved", + " 10 - Reserved", + " 11 - Dump Requested Debug Information And Exit Immediately (0x800)", " -h print this help information", " -q quiet mode - no warnings (default: warnings on)", " -r turn off automatic content refreshing (default: refresh on)", @@ -719,7 +781,32 @@ "PGLFT":PGLFT, "RUNCMD":RUNCMD, "SELKEY":SELKEY, - "MOUSESEL":MOUSESEL + "MOUSESEL":MOUSESEL, + "MEMCLR1":MEMCLR1, + "MEMCLR2":MEMCLR2, + "MEMCLR3":MEMCLR3, + "MEMCLR4":MEMCLR4, + "MEMCLR5":MEMCLR5, + "MEMCLR6":MEMCLR6, + "MEMCLR7":MEMCLR7, + "MEMCLR8":MEMCLR8, + "MEMCLR9":MEMCLR9, + "MEMCLR10":MEMCLR10, + "MEMCLR11":MEMCLR11, + "MEMCLR12":MEMCLR12, + "MEMCLRALL":MEMCLRALL, + "MEMSET1":MEMSET1, + "MEMSET2":MEMSET2, + "MEMSET3":MEMSET3, + "MEMSET4":MEMSET4, + "MEMSET5":MEMSET5, + "MEMSET6":MEMSET6, + "MEMSET7":MEMSET7, + "MEMSET8":MEMSET8, + "MEMSET9":MEMSET9, + "MEMSET10":MEMSET10, + "MEMSET11":MEMSET11, + "MEMSET12":MEMSET12, } # Set all the program options to their default values @@ -862,9 +949,9 @@ # Get shortcut number sc = int(name.split(DIRSC)[1]) - # Process if 1-12 + # Process if in range - if 0 < sc < 13: + if 0 < sc < NUMFUNCKEY + 1: # Ignore attempts to redefine a shortcut within the config file @@ -1339,7 +1426,7 @@ self.DirList.bind(self.KeyBindings["PGLFT"], KeyPageLeft) ### - # Execute commands + # Execute Commands ### # Bind handler for "Run Command" @@ -1351,6 +1438,38 @@ # Bind handler for "Mouse Select" self.DirList.bind(self.KeyBindings["MOUSESEL"], MouseDblClick) + + ### + # Memory Keys - All Features Bound To A Common Handler + ### + + self.DirList.bind(self.KeyBindings["MEMCLR1"], lambda event : KeyMemHandler(mem=1, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR2"], lambda event : KeyMemHandler(mem=2, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR3"], lambda event : KeyMemHandler(mem=3, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR4"], lambda event : KeyMemHandler(mem=4, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR5"], lambda event : KeyMemHandler(mem=5, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR6"], lambda event : KeyMemHandler(mem=6, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR7"], lambda event : KeyMemHandler(mem=7, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR8"], lambda event : KeyMemHandler(mem=8, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR9"], lambda event : KeyMemHandler(mem=9, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR10"], lambda event : KeyMemHandler(mem=10, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR11"], lambda event : KeyMemHandler(mem=11, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLR12"], lambda event : KeyMemHandler(mem=12, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMCLRALL"], lambda event : KeyMemHandler(mem=13, clear=TRUE)) + self.DirList.bind(self.KeyBindings["MEMSET1"], lambda event : KeyMemHandler(mem=1)) + self.DirList.bind(self.KeyBindings["MEMSET2"], lambda event : KeyMemHandler(mem=2)) + self.DirList.bind(self.KeyBindings["MEMSET3"], lambda event : KeyMemHandler(mem=3)) + self.DirList.bind(self.KeyBindings["MEMSET4"], lambda event : KeyMemHandler(mem=4)) + self.DirList.bind(self.KeyBindings["MEMSET5"], lambda event : KeyMemHandler(mem=5)) + self.DirList.bind(self.KeyBindings["MEMSET6"], lambda event : KeyMemHandler(mem=6)) + self.DirList.bind(self.KeyBindings["MEMSET7"], lambda event : KeyMemHandler(mem=7)) + self.DirList.bind(self.KeyBindings["MEMSET8"], lambda event : KeyMemHandler(mem=8)) + self.DirList.bind(self.KeyBindings["MEMSET9"], lambda event : KeyMemHandler(mem=9)) + self.DirList.bind(self.KeyBindings["MEMSET10"], lambda event : KeyMemHandler(mem=10)) + self.DirList.bind(self.KeyBindings["MEMSET11"], lambda event : KeyMemHandler(mem=11)) + self.DirList.bind(self.KeyBindings["MEMSET12"], lambda event : KeyMemHandler(mem=12)) + + ##### # Function Keys ##### @@ -1984,7 +2103,6 @@ #---------------------- Execute Commands -------------------# - ##### # Event Handler: Run Manually Entered Command #### @@ -2165,6 +2283,46 @@ # End of 'FuncKeypress()' +#-------------------- Memory Features --------------------# + +##### +# Event Handler: Menu-Related Features Handled By Single Handler +##### + +def KeyMemHandler(mem, clear=FALSE): + global UI + + # Clearing Memory + if clear: + + # Clear all + if mem == NUMPROGMEM + 1: + UI.ProgMem = [[], [], [], [], [], [], [], [], [], [], [], []] + + # Clear specific location + if 0 < mem < NUMPROGMEM + 1: + UI.ProgMem[mem-1] = [] + + # Saving to memory + else: + for x in UI.AllSelection(): + UI.ProgMem[mem-1].append(StripPSEP(os.path.abspath(x))) + + if DEBUGLEVEL & DEBUGMEM: + if 0 < mem < NUMPROGMEM + 1: + PrintDebug(dMEM % mem, UI.ProgMem[mem-1]) + else: + PrintDebug(dMEMALL, UI.ProgMem) + + + # Inhibit further processing of keystroke so Tkinter + # defaults like Alt-F10 don't take hold. + + return "break" + +# End of 'KeyMemHandler() + + #-------------- Handler Utility Functions -----------------# ##### @@ -2797,6 +2955,21 @@ cmd = cmd.replace(SELECTION, QUOTECHAR + selection + QUOTECHAR) cmd = cmd.replace(SELECTIONS, selections) + # Process references to program memories + + for x in range(NUMPROGMEM): + + # Only do this if there is a reference to the memory in + # question. This keeps the program from needlessly + # churning on long lists of memory contents which are not needed. + + vblref = "[MEM%s]" % str(x+1) + if cmd.count(vblref): + s = "" + for m in UI.ProgMem[x]: + s += QUOTECHAR + m + QUOTECHAR + " " + cmd = cmd.replace(vblref, s) + return cmd # End of 'ProcessBuiltIns()' @@ -3155,10 +3328,37 @@ def GetKeyBindings(): debuginfo = [] - for key in UI.KeyBindings.keys(): - debuginfo.append(PadString(key, dKEYWIDTH) + UI.KeyBindings[key]) + + # Get sorted list of all function names + kb = UI.KeyBindings.keys() + kb.sort() - debuginfo.sort() + # Make sure it is of even length, so we can format 2-at-a-time + if len(kb) % 2: + kb.append("") + + # Now setup two lists - 1st and last half respectively + m = len(kb)/2 + l1 = kb[:m] + l2 = kb[m:] + + # Format the bindings for output, 2 per line + x = 0 + while(x < m): + + k1 = l1[x] + v1 = UI.KeyBindings[k1] + k2 = l2[x] + if k2: + v2 = UI.KeyBindings[k2] + else: + v2 = "" + + s1 = PadString(k1, dKEYWIDTH) + v1 + s2 = PadString(k2, dKEYWIDTH) + v2 + debuginfo.append(PadString(s1, dTWOUPWIDTH) + s2) + x += 1 + return debuginfo # End of 'GetKeyBindings()' @@ -3222,6 +3422,8 @@ # Setup Built-In Variables UI.BuiltIns = {DIR:"", DSELECTION:"", DSELECTIONS:"", HASH:"", + MEM1:"", MEM2:"", MEM3:"", MEM4:"", MEM5:"", MEM6:"", + MEM7:"", MEM8:"", MEM9:"", MEM10:"", MEM11:"", MEM12:"", PROMPT:"", SELECTION:"", SELECTIONS:"", YESNO:""} # Options (and their default values) which can be set in the configuration file @@ -3257,6 +3459,10 @@ # Initialize Command History data structures ClearHistory(None) +# Initialize Storage For Program Memories + +UI.ProgMem = [[], [], [], [], [], [], [], [], [], [], [], []] + # Need mutex to serialize on widget updates UI.DirListMutex = mutex.mutex()