diff --git a/twander.py b/twander.py index 4536960..55a2ff5 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.43 2003/01/04 19:00:50 tundra Exp $" +RCSID = "$Id: twander.py,v 2.44 2003/01/04 22:52:13 tundra Exp $" VERSION = RCSID.split()[2] @@ -35,7 +35,6 @@ OSNAME = os.name -DriveList = [] if OSNAME == 'nt': try: from win32api import GetLogicalDriveStrings as GetDrives @@ -80,6 +79,7 @@ DIRROOT = '' # Goto root directory DIRSTART = '' # Goto starting directory DIRUP = '' # Go up one directory level +DRIVELIST = '' # On Win32, display Drive List View if possible MOUSEBACK = '' # Go back one directory with mouse MOUSEUP = '' # Go up one directory with mouse @@ -235,7 +235,7 @@ COMMANDMENU = 'Commands' # Title for Command Menu button DIRMENU = 'Directories' # Title for Directory Menu button PSEP = os.sep # Character separating path components - +SHOWDRIVES = '\\\\' # Logical directory name for Win32 Drive Lists ##### # Configuration File Related Literals @@ -337,7 +337,7 @@ DebugVars = ["RCSID", "OSNAME", "HOSTNAME", "OPTIONS", "STARTDIR", "HOME", "CONF", "HEIGHT", "WIDTH", "BCOLOR", "FCOLOR", "FNAME", "FSZ", "FWT", "AUTOREFRESH", "DEBUGLEVEL", "WARN", "PSEP", - "QUOTECHAR", "POLLINT", "REFRESHINT", "DriveList"] + "QUOTECHAR", "POLLINT", "REFRESHINT"] ##### @@ -454,6 +454,7 @@ "DIRROOT":DIRROOT, "DIRSTART":DIRSTART, "DIRUP":DIRUP, + "DRIVELIST":DRIVELIST, "MOUSEBACK":MOUSEBACK, "MOUSEUP":MOUSEUP, "SELALL":SELALL, @@ -909,6 +910,9 @@ # Bind handler for "Up Dir" self.DirList.bind(self.KeyBindings["DIRUP"], KeyUpDir) + # Bind handler for "Display Drive View" + self.DirList.bind(self.KeyBindings["DRIVELIST"], KeyDriveList) + # Bind handler for "Mouse Back Dir" self.DirList.bind(self.KeyBindings["MOUSEBACK"], KeyBackDir) @@ -981,8 +985,17 @@ def AllSelection(self): sellist = [] + # On Win32 Systems a Drive List View is always forced + # to display with no details. So we have to consider this + # when figuring out where the selection name begins. + + if self.CurrentDir == SHOWDRIVES: + nameindex = 0 + else: + nameindex = self.NameFirst + for entry in self.DirList.curselection(): - sellist.append(self.DirList.get(entry)[UI.NameFirst:].split(SYMPTR)[0]) + sellist.append(self.DirList.get(entry)[nameindex:].split(SYMPTR)[0]) return sellist @@ -995,9 +1008,16 @@ def LastInSelection(self): + # As above in AllSelection() + + if self.CurrentDir == SHOWDRIVES: + nameindex = 0 + else: + nameindex = self.NameFirst + index = self.DirList.curselection() if index: - return self.DirList.get(index[-1])[UI.NameFirst:].split(SYMPTR)[0] + return self.DirList.get(index[-1])[nameindex:].split(SYMPTR)[0] else: return "" @@ -1205,6 +1225,7 @@ def ChangeDir(event): newpath = askstring(pCHPATH, pENPATH) + if newpath: LoadDirList(newpath) KeySelTop(event) @@ -1277,8 +1298,28 @@ if UI.CurrentDir != os.path.abspath(PSEP): LoadDirList(UI.CurrentDir + "..") + # Unless we're running on Win32 and we are able to do + # a Drive List View + + elif OSNAME == 'nt' and GetWin32Drives(): + LoadDirList(SHOWDRIVES) + # End of 'KeyUpDir()' +##### +# Event Handler: Display Drive List View On Win32, If Possible +##### + +def KeyDriveList(event): + + # This is only possible on Win32 and if there is a list of + # drives available - i.e, If Win32All is installed + + if OSNAME == 'nt' and GetWin32Drives(): + LoadDirList(SHOWDRIVES) + +# End of 'KeyDriveList() + #---------------------- Selection Keys ---------------------# @@ -1463,9 +1504,21 @@ if not selected: return + # If we're on Win32 and we just selected ".." from the root of + # a drive, request a display of the Drive List. LoadDirList() + # will check to see if there is anything in the Drive List and + # do nothing if it is empty (which happens if the user has not + # installed the Win32All package). + + if OSNAME=='nt' and \ + os.path.abspath(UI.CurrentDir) == os.path.abspath(UI.CurrentDir + selected): + + LoadDirList(SHOWDRIVES, save=TRUE) + UI.MouseNewDir = TRUE + # If selection is a directory, move there and list contents. - if os.path.isdir(os.path.join(UI.CurrentDir, selected)): + elif os.path.isdir(os.path.join(UI.CurrentDir, selected)): # On Unix, don't follow links pointing back to themselves @@ -1531,12 +1584,33 @@ def LoadDirList(newdir, save=TRUE): - # Get path into canonical form - newdir = os.path.abspath(newdir) + # Transform double forward-slashes into a single + # forward-slash. This keeps the Directory Stack + # and Visited lists sane under Unix and prevents + # Win32 from attempting to enter a Drive List View + # when the user enters this string but Win32All has + # not been loaded. - # Make sure newdir properly terminated - if newdir[-1] != PSEP: - newdir += PSEP + if newdir == '//': + newdir = '/' + + # Get path into canonical form unless we're trying + # to display a Win32 Drive List + + if newdir != SHOWDRIVES: + newdir = os.path.abspath(newdir) + + # Make sure newdir properly terminated + if newdir[-1] != PSEP: + newdir += PSEP + + # User has requested a Drive List View. Make sure we're + # running on Win32 and see the feature is available. If + # not available (which means Win32All is not installed), + # just ignore and return, doing nothing. + + elif OSNAME != 'nt' or not GetWin32Drives(): + return # Check right now to see if we can read # the directory. If not, at least we @@ -1597,7 +1671,12 @@ UI.DirList.insert(END, x) # Also move the program context to the new directory - os.chdir(newdir) + # for everything except a Drive List View. In that case + # the program context remains in the directory from + # which the Drive List View was selected + + if newdir != SHOWDRIVES: + os.chdir(newdir) # Keep list of all unique directories visited in the Directory Menu @@ -1635,25 +1714,38 @@ dList, fList = [], [] - # Walk the directory separate subdirs and files - for file in os.listdir(currentdir): - if os.path.isdir(os.path.join(currentdir, file)): - dList.append(file + PSEP) - else: - fList.append(file) + # Two possible cases have to be handled: + # A normal directory read and a Drive List View + # under Win32. - # Put each in sorted order + # Normal directory reads + if currentdir != SHOWDRIVES: + + # Walk the directory separate subdirs and files + for file in os.listdir(currentdir): + if os.path.isdir(os.path.join(currentdir, file)): + dList.append(file + PSEP) + else: + fList.append(file) + + # Put each in sorted order + + dList.sort() + fList.sort() + + + # Entry to move up one directory is always first, + # no matter what the sort. This is necessary because + # OSs like Win32 like to use '$' in file names which + # sorts before "." + + dList.insert(0, ".." + PSEP) + + # The user requested Drive List View. This is always displayed + # without details, so we can return directly from here. - dList.sort() - fList.sort() - - - # Entry to move up one directory is always first, - # no matter what the sort. This is necessary because - # OSs like Win32 like to use '$' in file names which - # sorts before "." - - dList.insert(0, ".." + PSEP) + else: + return GetWin32Drives() # If user has not requested detailed display, we're done if not UI.DetailsOn: @@ -1976,10 +2068,6 @@ ErrMsg(eBADROOT % STARTDIR) sys.exit(1) -# Initialize The Drive List On Win32 -if OSNAME == 'nt': - DriveList = GetWin32Drives() - # Get starting directory into canonical form STARTDIR = os.path.abspath(STARTDIR)