diff --git a/twander.py b/twander.py index 3ee68a9..a4ce4d6 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.198 2006/12/14 07:23:06 tundra Exp $" +RCSID = "$Id: twander.py,v 3.199 2006/12/14 19:10:57 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -601,6 +601,8 @@ ##### ASSIGN = "=" # Assignment for variable definitions +ASSOCDFLT = "*" # Name for default association action +ASSOCIATE = "ASSOC" # Association keyword CONF = "" # Config file user selected with -c option COMMENT = r"#" # Comment introducer string ENVVBL = r'$' # Symbol denoting an environment variable @@ -741,6 +743,7 @@ WEBSITE = "Homepage:\n\nhttp://www.tundraware.com/Software/twander" ABOUT = "%s %s\n\nCopyright %s %s\n%s\n\n%s\n\n%s" % (PROGNAME, VERSION, CPRT, DATE, OWNER, RIGHTS, WEBSITE) hABOUT = 'About' +hASSOC = 'Associations' hCOMMANDS = 'Command Definitions' hINTVBLS = 'Internal Program Variables' hKEYS = 'Keyboard Assignments' @@ -824,12 +827,13 @@ # Nibble #3 DEBUGWILD = (1<<8) # Dump contents of wildcard stack as it changes -DEBUGRSRV2 = (1<<9) # Reserved for future use -DEBUGRSRV3 = (1<<10) +DEBUGASSOC = (1<<9) # Dump association table +DEBUGRSRV3 = (1<<10) # Reserved for future use DEBUGQUIT = (1<<11) # Dump debug info and quit program # Debug Strings +dASSOC = "ASSOCIATIONS" dCMD = "COMMAND" dCMDTBL = hCOMMANDS dDIRSTK = "DIRECTORY STACK" @@ -851,6 +855,7 @@ # Debug Formatting +dASSOCWIDTH = 10 dCMDWIDTH = 20 dCOLNUM = 3 dCOLWIDTH = 50 @@ -885,8 +890,8 @@ " 6 - Dump Command History Stack After Command Executes (0x040)", " 7 - Dump Contents Of Program Memories As They Change (0x080)", " 8 - Dump Contents Of Filter/Selection Wildcard Lists As They Change (0x100)", - " 9 - Reserved", - " 10 - Reserved", + " 9 - Dump Association Table (0x200)", + " 10 - Reserved (0x400)", " 11 - Dump Requested Debug Information And Exit Immediately (0x800)", " -h print this help information", " -q quiet mode - no warnings (default: warnings on)", @@ -1166,6 +1171,8 @@ global CONF, UI, ConditionalStack # Cleanout any old configuration data + + UI.Associations = {} UI.CmdTable = {} UI.Commands = [] UI.ConfigVisited = [] @@ -1762,10 +1769,10 @@ UI.SymTable[name] = val ### - # Command Definitions + # Command Definitions And Associations ### - elif len(fields[0]) == 1: + elif (len(fields[0]) == 1) or (fields[0] == ASSOCIATE): # Must have at least 3 fields for a valid command definition if len(fields) < 3: @@ -1780,6 +1787,12 @@ if not cmd: return + # Store associations for use at execution time + + if cmdkey == ASSOCIATE: + UI.Associations[cmdname] = cmd + return + # Add the command entry to the command table. # If the key is a duplicate, the older definition is # overwritten. @@ -1923,11 +1936,12 @@ # Update the cascading submenus # We iterate across tuples of (Menu Name, Menu Variable, List Of Items) - for mname, mvbl, mlist in ((hUSERVBLS, UI.UserVbls, GetUserVbls()), - (hCOMMANDS, UI.CmdDefs, GetCommandTable()), - (hINTVBLS, UI.IntVbls, GetIntVars()), + for mname, mvbl, mlist in ((hINTVBLS, UI.IntVbls, GetIntVars()), (hOPTVBLS, UI.OptVbls, GetOptions()), (hKEYS, UI.Keys, FormatMultiColumn(UI.KeyBindings)), + (hUSERVBLS, UI.UserVbls, GetUserVbls()), + (hCOMMANDS, UI.CmdDefs, GetCommandTable()), + (hASSOC, UI.Assocs, GetAssocTable()) ): mvbl.delete(0,END) @@ -2141,12 +2155,12 @@ # Setup the cascading submenus - self.UserVbls = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) - self.CmdDefs = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) self.IntVbls = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) self.OptVbls = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) self.Keys = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) - self.DirSCs = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) + self.UserVbls = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) + self.CmdDefs = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) + self.Assocs = Menu(self.HelpBtn.menu, foreground=MFCOLOR, background=MBCOLOR, font=(MFNAME, MFSZ, MFWT)) # Setup the Directory Listing and Scrollbars @@ -3592,11 +3606,33 @@ # We know what to do on Win32 and Unix. We ignore # the selection elsewhere. - elif OSPLATFORM == 'win32': - ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected), '', ResolveBuiltIns=False, UseStartDir=True) + elif (OSPLATFORM == 'win32') or (OSNAME == 'posix'): - elif OSNAME == 'posix': - ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected), '', ResolveBuiltIns=False) + # Set OS-Specific command invocation options + + if OSPLATFORM == 'win32': + usestartdir=True + else: + usestartdir=False + + # Create absolute path to selected command + + selected = os.path.join(os.path.abspath(UI.CurrentDir), selected) + + # Apply any relevant association information + + assocfound = False + for assoc in UI.Associations: + if selected.endswith(assoc): + selected = UI.Associations[assoc] + assocfound = True + + if not assocfound and (ASSOCDFLT in UI.Associations): + selected = UI.Associations[ASSOCDFLT] + + # And execute the command + + ExecuteCommand(selected, '', ResolveVars=True, ResolveBuiltIns=True, UseStartDir=usestartdir) return 'break' @@ -4986,6 +5022,11 @@ # User-Settable options PrintDebug(dOPTVAR, GetOptions()) + # Associations Table + + if DEBUGLEVEL & DEBUGASSOC: + PrintDebug(dASSOC, GetAssocTable()) + # If we just wanted debug output, quit now if DEBUGLEVEL & DEBUGQUIT: sys.exit() @@ -5088,6 +5129,22 @@ ##### +# Return List Of Association Table Entries +##### + +def GetAssocTable(): + + debuginfo = [] + for assocname in UI.Associations: + debuginfo.append(PadString(assocname, dASSOCWIDTH) + UI.Associations[assocname]) + + debuginfo.sort() + return debuginfo + +# End of 'GetAssocTable()' + + +##### # Return List Of Command Table Entries ##### @@ -5247,6 +5304,11 @@ # Prepare storage for key bindings UI.KeyBindings = {} + +# Storage For Associations + +UI.Associations = {} + # Initialize list of all directories visited UI.AllDirs = []