diff --git a/twander.py b/twander.py index 8036a93..c97df59 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.59 2003/01/15 23:33:58 tundra Exp $" +RCSID = "$Id: twander.py,v 2.60 2003/01/16 01:15:08 tundra Exp $" VERSION = RCSID.split()[2] @@ -23,7 +23,7 @@ import time from Tkinter import * -from tkMessageBox import showerror, showwarning +from tkMessageBox import askyesno, showerror, showwarning from tkSimpleDialog import askstring ##### @@ -291,6 +291,7 @@ PROMPT = r'[PROMPT:' SELECTION = r'[SELECTION]' SELECTIONS = r'[SELECTIONS]' +YESNO = r'[YESNO:' #----------------------------------------------------------# @@ -304,18 +305,12 @@ # Errors -eBADCFGLINE = "Bogus Configuration Entry In Line %s:\n\n%s" -eBADENVVBL = "Environment Variable %s In Line %s Not Set:\n\n%s" eBADROOT = " %s Is Not A Directory" eDIRRD = "Cannot Open Directory : %s --- Check Permissions." -eDUPKEY = "Found Duplicate Command Key '%s' In Line %s:\n\n%s" eERROR = "ERROR" eINITDIRBAD = "Cannot Open Starting Directory : %s - Check Permissions - ABORTING!." eOPEN = "Cannot Open File: %s" -eREDEFVAR = "Variable %s Redefined In Line %s:\n\n%s" eTOOMANY = "You Can Only Specify One Starting Directory." -eUNDEFVBL = "Undefined Variable %s Referenced In Line %s:\n\n%s" -eVBLTOODEEP = "Variable Definition Nested Too Deeply At Line %s:\n\n%s" # Information @@ -331,14 +326,19 @@ # Warnings +wBADCFGLINE = "Ignoring Line %s.\nBogus Configuration Entry:\n\n%s" +wBADENVVBL = "Ignoring Line %s.\nEnvironment Variable %s Not Set:\n\n%s" wBADEXE = "Could Not Execute Command:\n\n%s" -wBADVAL = "Option Assignment Has Bad Righthand Side.\nIgnoring Line %s:\n\n%s" -wCMDKEY = "Configuration File Entry For: \'%s\' Has No Command Key Defined." +wBADRHS = "Ignoring Line %s.\nOption Assignment Has Bad Righthand Side:\n\n%s" wCONFOPEN = "Cannot Open Configuration File:\n%s" -wDIRSCREDEF = "Directory Shortcut Defined More Than Once.\nIgnoring Line %s:\n\n%s" +wDIRSCREDEF = "Ignoring Line %s.\nDirectory Shortcut Defined More Than Once:\n\n%s" +wDUPKEY = "Ignoring Line %s.\nFound Duplicate Command Key '%s':\n\n%s" wLINKBACK = "%s Points Back To Own Directory" wNOCMDS = "Running With No Commands Defined!" -wNOREBIND = "Cannot Rebind This Keyboard Or Mouse Button Combination.\nIgnoring Line %s:\n\n%s" +wNOREBIND = "Ignoring Line %s.\nCannot Rebind This Keyboard Or Mouse Button Combination:\n\n%s" +wREDEFVAR = "Ignoring Line %s.\nVariable %s Redefined:\n\n%s" +wUNDEFVBL = "Ignoring Line %s.\nUndefined Variable %s Referenced:\n\n%s" +wVBLTOODEEP = "Ignoring Line %s.\nVariable Definition Nested Too Deeply:\n\n%s" wWARN = "WARNING" @@ -636,8 +636,8 @@ UI.BuiltIns.has_key('[' + name + ']') or \ UI.BuiltIns.has_key('[' + name): - ErrMsg(eREDEFVAR % (name, num, line)) - sys.exit(1) + WrnMsg(wREDEFVAR % (num, name, line)) + return # Handle Directory Shortcut entries. @@ -654,6 +654,7 @@ if UI.FuncKeys[sc-1]: WrnMsg(wDIRSCREDEF % (num, line)) + return # Everything OK - process the entry else: @@ -675,24 +676,24 @@ if val == 'TRUE' or val == 'FALSE': globals()[name] = eval(val) # !!! Cheater's way to get to global variables. else: - WrnMsg(wBADVAL % (num, line)) + WrnMsg(wBADRHS % (num, line)) + return elif name in UI.OptionsNumeric: try: globals()[name] = int(val) except: - WrnMsg(wBADVAL % (num, line)) + WrnMsg(wBADRHS % (num, line)) + return elif name in UI.OptionsString: # RHS cannot be null if not val: - WrnMsg(wBADVAL % (num, line)) - + WrnMsg(wBADRHS % (num, line)) + return else: - try: - globals()[name] = val - except: - WrnMsg(wBADVAL % (num, line)) + globals()[name] = val + # Process other variable types. # Distinguish between internal program variables and @@ -702,6 +703,7 @@ elif name in UI.KeyBindings.keys(): if name in NOREBIND: WrnMsg(wNOREBIND % (num, line)) + return else: UI.KeyBindings[name] = val else: @@ -715,8 +717,8 @@ # Must have at least 3 fields for a valid command definition if len(fields) < 3: - ErrMsg(eBADCFGLINE % (num, line)) - sys.exit(1) + WrnMsg(wBADCFGLINE % (num, line)) + return else: cmdkey = fields[0] cmdname = fields[1] @@ -741,8 +743,8 @@ # If so, let the user know if REVAR.findall(cmd): - ErrMsg(eVBLTOODEEP % (num, cmd)) - sys.exit(1) + WrnMsg(wVBLTOODEEP % (num, cmd)) + return # Get a list of variable references vbls = REVAR.findall(cmd) @@ -765,6 +767,9 @@ elif x.startswith(PROMPT): vbls.remove(x) + + elif x.startswith(YESNO): + vbls.remove(x) if vbls: for x in vbls: @@ -783,13 +788,13 @@ if envvbl: cmd = cmd.replace(x, envvbl) else: - ErrMsg(eBADENVVBL % (x, num, line)) - sys.exit(1) + WrnMsg(wBADENVVBL % (num, x, line)) + return # Process references to undefined variables else: - ErrMsg(eUNDEFVBL % (x, num, line)) - sys.exit(1) + WrnMsg(wUNDEFVBL % (num, x, line)) + return # No substitutions left to do else: @@ -799,16 +804,15 @@ # Prevent duplicate keys from being entered. if UI.CmdTable.has_key(cmdkey): - ErrMsg(eDUPKEY % (cmdkey, num, line)) - sys.exit(1) + WrnMsg(wDUPKEY % (num, cmdkey, line)) + return else: UI.CmdTable[cmdkey] = [cmdname, cmd] UI.CmdBtn.menu.add_command(label=cmdname + " " * (15-len(cmdname)) + "(" + cmdkey + ")", command=lambda cmd=cmdkey: CommandMenuSelection(cmd)) else: - ErrMsg(eBADCFGLINE % (num, line)) - sys.exit(1) + WrnMsg(wBADCFGLINE % (num, line)) # End of 'ParseLine()' @@ -1366,22 +1370,27 @@ # First do any prompting required - for x in range(cmd.count(PROMPT)): - b = cmd.find(PROMPT) - e = cmd.find("]", b) - prompt = cmd[b + len(PROMPT):e] - val = askstring(name, prompt) + for promptvar, handler, replace in ((YESNO, askyesno, FALSE), (PROMPT, askstring, TRUE)): - # Make sure our program gets focus back - UI.DirList.focus() - - if val: - cmd = cmd.replace(cmd[b:e+1], QUOTECHAR + val + QUOTECHAR) + for x in range(cmd.count(promptvar)): + b = cmd.find(promptvar) + e = cmd.find("]", b) + prompt = cmd[b + len(promptvar):e] + val = handler(name, prompt) - # Null input means the command is being aborted - else: - return - + # Make sure our program gets focus back + UI.DirList.focus() + + if val: + if replace: + cmd = cmd.replace(cmd[b:e+1], QUOTECHAR + val + QUOTECHAR) + else: + cmd = cmd.replace(cmd[b:e+1], '') + + # Null input means the command is being aborted + else: + return + # Now do files & directories # Strip trailing path separators in each case to # give the command author the maximum flexibility possible @@ -2497,7 +2506,7 @@ # Setup Built-In Variables UI.BuiltIns = {DIR:"", DSELECTION:"", DSELECTIONS:"", HASH:"", - PROMPT:"", SELECTION:"", SELECTIONS:""} + PROMPT:"", SELECTION:"", SELECTIONS:"", YESNO:""} # Options which can be set in the configuration file