diff --git a/twander.py b/twander.py index b2bf0df..92607f0 100755 --- a/twander.py +++ b/twander.py @@ -1,12 +1,22 @@ #!/usr/bin/env python # twander - Wander around the file system -# Copyright (c) 2002 TundraWare Inc. All Rights Reserved. +# Copyright (c) 2002-2003 TundraWare Inc. All Rights Reserved. # For Updates See: http://www.tundraware.com/Software/twander +# Program Information + PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.67 2003/01/17 21:37:22 tundra Exp $" +RCSID = "$Id: twander.py,v 2.68 2003/01/18 02:38:22 tundra Exp $" VERSION = RCSID.split()[2] +# Copyright Information + +DATE = "2002-2003" +CPRT = chr(169) +OWNER = "TundraWare Inc." +RIGHTS = "All Rights Reserved" +COPYRIGHT = "Copyright %s %s %s %s. " % (CPRT, DATE, OWNER, RIGHTS) + #----------------------------------------------------------# # Imports # @@ -23,7 +33,7 @@ import time from Tkinter import * -from tkMessageBox import askyesno, showerror, showwarning +from tkMessageBox import askyesno, showerror, showinfo, showwarning from tkSimpleDialog import askstring ##### @@ -253,12 +263,10 @@ # General Literals ##### -COMMANDMENU = 'Commands' # Title for Command Menu button -DIRMENU = 'Directories' # Title for Directory Menu button -HISTMENU = 'History' # Title for History Menu button PSEP = os.sep # Character separating path components SHOWDRIVES = '\\\\' # Logical directory name for Win32 Drive Lists + ##### # GUI-Related Contsants #### @@ -311,9 +319,28 @@ ##### -# Error, Information, & Warning Messages +# Menu, Error, Information, & Warning Messages ##### +# Menu-Related Strings + +# Menu Button Titles + +COMMANDMENU = 'Commands' # Title for Command Menu button +DIRMENU = 'Directories' # Title for Directory Menu button +HISTMENU = 'History' # Title for History Menu button +HELPMENU = 'Help' # Title for Help Menu button + +# Help Menu-Related + +hABOUT = 'About' +hCOMMANDS = 'Command Definitions' +hKEYS = 'Keyboard Assignments' +hDIRSC = 'Directory Shortcuts' +hUSERVBLS = 'User-Defined Variables' +hVBLSOPTS = 'Internal Variables & Options' + + # Errors eBADROOT = " %s Is Not A Directory" @@ -392,7 +419,7 @@ # Usage Information ##### -uTable = [PROGNAME + " " + VERSION + " - Copyright 2002, TundraWare Inc., All Rights Reserved\n", +uTable = [PROGNAME + " " + VERSION + " - %s\n" % COPYRIGHT, "usage: " + PROGNAME + " [-bcdfhnqrstvwxy] [startdir] where,\n", " startdir name of directory in which to begin (default: current dir)", " -b color background color (default: black)", @@ -864,6 +891,20 @@ self.HistBtn.menu = Menu(self.HistBtn) self.HistBtn.pack(side=LEFT, padx=MENUPADX) + # Setup the Help Menu + + self.HelpBtn = Menubutton(self.mBar, text=HELPMENU, underline=2, state=DISABLED) + self.HelpBtn.menu = Menu(self.HelpBtn) + self.HelpBtn.pack(side=LEFT, padx=MENUPADX) + + # Setup the cascading submenus + + self.UserVbls = Menu(self.HelpBtn.menu, font=(FNAME, FSZ, "bold")) + self.CmdDefs = Menu(self.HelpBtn.menu, font=(FNAME, FSZ, "bold")) + self.VblsOpts = Menu(self.HelpBtn.menu, font=(FNAME, FSZ, "bold")) + self.Keys = Menu(self.HelpBtn.menu, font=(FNAME, FSZ, "bold")) + self.DirSCs = Menu(self.HelpBtn.menu, font=(FNAME, FSZ, "bold")) + # Setup the Directory Listing and Scrollbars self.hSB = Scrollbar(root, orient=HORIZONTAL) @@ -1276,6 +1317,10 @@ elif event.char == 'h': button = UI.HistBtn + # Help Menu + elif event.char == 'l': + button = UI.HelpBtn + # Unrecognized - Ignore else: return "break" @@ -1814,7 +1859,7 @@ else: try: if (OSNAME == 'posix') and not USETHREADS: - os.system(newcmd) + os.system(newcmd + " &") else: thread.start_new_thread(os.system, (newcmd,)) except: @@ -2380,6 +2425,118 @@ ##### +# Process Options +##### + +def ProcessOptions(): + global UI + + # Start in detailed mode unless details are inhibited + UI.SetDetailedView(~NODETAILS) + + # Rebind all the handlers + UI.BindAllHandlers() + + # Set the Command Menu Contents, if any, + # and enable the menu if it has entries. + # If no commands are defined, warn the user. + + if UI.CmdBtn.menu.index(END): + UI.CmdBtn['menu'] = UI.CmdBtn.menu + UI.CmdBtn.configure(state=NORMAL) + else: + WrnMsg(wNOCMDS) + + # Any user-set options have now been read, set the GUI + + for i in (UI.CmdBtn, UI.DirBtn, UI.HistBtn, UI.HelpBtn): + i.config(font=(FNAME, FSZ, "bold")) + i.menu.config(font=("courier", FSZ, "bold")) + + UI.DirList.config(font=(FNAME, FSZ, FWT), + foreground=FCOLOR, background=BCOLOR, + height=HEIGHT, width=WIDTH) + + # Make sure menus conform to max lengths (which may have changed). + + UpdateMenu(UI.DirBtn, UI.AllDirs, MAXDIR, LoadDirList, sort=TRUE) + UpdateMenu(UI.HistBtn, UI.CmdHist, MAXHIST, KeyRunCommand, fakeevent=TRUE) + + ##### + # Initialize Help Menu with latest information + ##### + + # Clear out existing content + + UI.HelpBtn.config(state=DISABLED) + UI.HelpBtn.menu.delete(0,END) + + + # 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()), + (hVBLSOPTS, UI.VblsOpts, GetIntVars() + GetOptions()), + (hKEYS, UI.Keys, GetKeyBindings()), + (hDIRSC, UI.DirSCs, GetDirShortcuts())): + mvbl.delete(0,END) + + for l in mlist: + mvbl.add_command(label=l, command=None) + UI.HelpBtn.menu.add_cascade(label=mname, menu=mvbl) + + # Setup the About item + + UI.HelpBtn.menu.add_command(label=hABOUT, command=lambda title=hABOUT, + text="%s %s\n\nCopyright %s %s\n%s\n\n%s" % \ + (PROGNAME, VERSION, CPRT, DATE, OWNER, RIGHTS) \ + : showinfo(title, text)) + + # Enable the menu content + + UI.HelpBtn['menu'] = UI.HelpBtn.menu + UI.HelpBtn.config(state=NORMAL) + + + ##### + # Dump requested debug information + ##### + + # Keyboard Assignments + if int(DEBUGLEVEL) & DEBUGKEYS: + + # Keyboard Bindings + PrintDebug(dKEYBINDS, GetKeyBindings()) + + # Function Keys (Directory Shortcuts) + PrintDebug(dFUNCKEYS, GetDirShortcuts()) + + # User-Defined Variables + if int(DEBUGLEVEL) & DEBUGSYMS: + PrintDebug(dSYMTBL, GetUserVbls()) + + # Command Definitions + if int(DEBUGLEVEL) & DEBUGCTBL: + PrintDebug(dCMDTBL, GetCommandTable()) + + # Internal Program Variables AndOptions + if int(DEBUGLEVEL) & DEBUGVARS: + + # Internal variabled + PrintDebug(dINTVAR, GetIntVars()) + + # User-Settable options + PrintDebug(dOPTVAR, GetOptions()) + + # If we just wanted debug output, quit now + if int(DEBUGLEVEL) & DEBUGQUIT: + sys.exit() + +# End of 'ProcessOptions()' + + +##### # Add An Entry To The List Of All Directories Visited # Do this only if it is not already on the list and # observe the MAXDIR variable to keep list length bounded. @@ -2467,110 +2624,105 @@ # End of 'UpdateMenu()' +#---------------- Debug Support Functions -----------------# + + ##### -# Process Options +# Return List Of Command Table Entries ##### -def ProcessOptions(): - global UI - - # Start in detailed mode unless details are inhibited - UI.SetDetailedView(~NODETAILS) +def GetCommandTable(): - # Rebind all the handlers - UI.BindAllHandlers() + debuginfo = [] + for key in UI.CmdTable.keys(): + name = UI.CmdTable[key][0] + cmd = UI.CmdTable[key][1] + debuginfo.append(key + " " + name + " " * (16-len(name)) + cmd) - # Set the Command Menu Contents, if any, - # and enable the menu if it has entries. - # If no commands are defined, warn the user. - - if UI.CmdBtn.menu.index(END): - UI.CmdBtn['menu'] = UI.CmdBtn.menu - UI.CmdBtn.configure(state=NORMAL) - else: - WrnMsg(wNOCMDS) + return debuginfo - # Any user-set options have now been read, set the GUI - - for i in (UI.CmdBtn, UI.DirBtn, UI.HistBtn): - i.config(font=(FNAME, FSZ, "bold")) - i.menu.config(font=("courier", FSZ, "bold")) - - UI.DirList.config(font=(FNAME, FSZ, FWT), - foreground=FCOLOR, background=BCOLOR, - height=HEIGHT, width=WIDTH) - - # Make sure menus conform to max lengths (which may have changed). - - UpdateMenu(UI.DirBtn, UI.AllDirs, MAXDIR, LoadDirList, sort=TRUE) - UpdateMenu(UI.HistBtn, UI.CmdHist, MAXHIST, KeyRunCommand, fakeevent=TRUE) - - - ##### - # Dump requested debug information - ##### - - if int(DEBUGLEVEL) & DEBUGKEYS: - - debuginfo = [] - - # Command keys - for key in UI.KeyBindings.keys(): - debuginfo.append(key + " " * (10-len(key)) + UI.KeyBindings[key]) - debuginfo.sort() - PrintDebug(dKEYBINDS, debuginfo) - - debuginfo = [] - - # Function Keys (Directory Shortcuts) - for x in range(len(UI.FuncKeys)): - key = "F" + str(x+1) - debuginfo.append(key + " " * (10-len(key)) + UI.FuncKeys[x]) - - PrintDebug(dFUNCKEYS, debuginfo) - - if int(DEBUGLEVEL) & DEBUGSYMS: - - debuginfo = [] - for sym in UI.SymTable.keys(): - debuginfo.append(sym + " " * (16-len(sym)) + UI.SymTable[sym]) - - debuginfo.sort() - PrintDebug(dSYMTBL, debuginfo) - - if int(DEBUGLEVEL) & DEBUGCTBL: - - debuginfo = [] - for key in UI.CmdTable.keys(): - name = UI.CmdTable[key][0] - cmd = UI.CmdTable[key][1] - debuginfo.append(key + " " + name + " " * (16-len(name)) + cmd) - - PrintDebug(dCMDTBL, debuginfo) - - # Dump program variable during debug sessions - if int(DEBUGLEVEL) & DEBUGVARS: - - debuginfo = [] - for v in DebugVars: - debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) - - PrintDebug(dINTVAR, debuginfo) - - debuginfo = [] - for l in (UI.OptionsBoolean, UI.OptionsNumeric, UI.OptionsString): - for v in l: - debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) - - debuginfo.sort() - PrintDebug(dOPTVAR, debuginfo) +# End of 'GetCommandTable()' - # If we just wanted debug output, quit now - if int(DEBUGLEVEL) & DEBUGQUIT: - sys.exit() +##### +# Return List Of Current Directory Shortcuts +##### -# End of 'ProcessOptions()' +def GetDirShortcuts(): + + debuginfo = [] + for x in range(len(UI.FuncKeys)): + key = "F" + str(x+1) + debuginfo.append(key + " " * (10-len(key)) + UI.FuncKeys[x]) + + return debuginfo + +# End of 'GetDirShortcuts()' + + +##### +# Return List Of Internal Variables +##### + +def GetIntVars(): + + debuginfo = [] + for v in DebugVars: + debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) + + return debuginfo + +# End of 'GetIntVars()' + + +##### +# Return List Of Current Key Bindings +##### + +def GetKeyBindings(): + + debuginfo = [] + for key in UI.KeyBindings.keys(): + debuginfo.append(key + " " * (10-len(key)) + UI.KeyBindings[key]) + + debuginfo.sort() + return debuginfo + +# End of 'GetKeyBindings()' + + +##### +# Return List Of User-Settable Options +##### + +def GetOptions(): + + debuginfo = [] + for l in (UI.OptionsBoolean, UI.OptionsNumeric, UI.OptionsString): + for v in l: + debuginfo.append(v + " " * (12-len(v)) + (str(eval(v)) or dNULL)) + + debuginfo.sort() + return debuginfo + +# End of 'GetOptions()' + + +##### +# Return List Of User-Defined Variables +##### + +def GetUserVbls(): + + debuginfo = [] + for sym in UI.SymTable.keys(): + debuginfo.append(sym + " " * (16-len(sym)) + UI.SymTable[sym]) + + debuginfo.sort() + + return debuginfo + +# End of 'GetUserVbls()' #----------------------------------------------------------#