diff --git a/twander.py b/twander.py index 387898e..5ac5045 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.73 2002/11/22 22:29:00 tundra Exp $" +RCSID = "$Id: twander.py,v 1.74 2002/11/23 03:15:43 tundra Exp $" VERSION = RCSID.split()[2] @@ -16,11 +16,26 @@ import os from socket import getfqdn import sys +import time from Tkinter import * from tkMessageBox import showerror, showwarning from tkSimpleDialog import askstring +# Imports conditional on OS + +# Set OS type - this allows us to trigger OS-specific code +# where needed. + +OSNAME = os.name + + +if OSNAME == 'posix': + import grp + import pwd + + + #----------------------------------------------------------# # Variables User Might Change # #----------------------------------------------------------# @@ -39,6 +54,7 @@ QUITPROG = '' # Quit the program READCONF = '' # Re-read the configuration file REFRESH = '' # Refresh screen +TOGDETAIL = '' # Toggle detail view # Directory Navigation @@ -92,13 +108,6 @@ FWT = "bold" -##### -# Enable Warnings -##### - -WARN = TRUE - - #------------------- Nothing Below Here Should Need Changing ------------------# @@ -114,6 +123,20 @@ # Don't need to define TRUE & FALSE - they are defined in the Tkinter module + +##### +# Defaults +##### + + +DETAILVIEW = TRUE # File details on +WARN = TRUE # Warnings on + + + + + + ##### # Constants ##### @@ -122,11 +145,6 @@ REFRESHINT = 1000 # Interval (ms) for automatic refresh -# Set OS type - this allows us to trigger OS-specific code -# where needed. - -OSNAME = os.name - ##### # General Literals ##### @@ -398,6 +416,10 @@ # Bind handler of "Refresh Screen" self.DirList.bind(REFRESH, RefreshDirList) + # Bind handler of "Toggle Detail" + self.DirList.bind(TOGDETAIL, KeyToggleDetail) + + # Directory Navigation # Bind handler for "Change Directory" @@ -550,6 +572,19 @@ # End of 'KeyQuitProg()' +##### +# Event Handler: Toggle Detail View +##### + +def KeyToggleDetail(event): + global DETAILVIEW + + DETAILVIEW = not DETAILVIEW + RefreshDirList(event) + +# End of 'KeyToggleDetail()' + + #------------------- Directory Navigation -----------------# @@ -837,16 +872,54 @@ fList.sort() - # Go get details for everything in current directory + # If user has not requested detailed display, we're done + if not DETAILVIEW: + return dList + fList - for entry in (dList + fList): - fullname = os.path.join(currentdir, entry) + # Detailed display requested, do the work + + all = dList + fList + detlist = [] + for index in range(len(all)): try: - UI.Details[entry] = os.stat(fullname) - except: - UI.Details[entry] = "NO DETAILS FOUND" + stinfo = os.stat(os.path.join(currentdir, all[index])) + detlist.append("") - return dList + fList + # Mode + detlist[index] += str(stinfo[0]) + (11 - len(str(stinfo[0]))) * " " + + # Number of links to entry + detlist[index] += str(stinfo[3]) + ( 5 - len(str(stinfo[3]))) * " " + + # Get 1st 8 characters of owner and group names on unix + if OSNAME == 'posix': + owner = pwd.getpwuid(stinfo[4])[0][:8] + group = grp.getgrgid(stinfo[5])[0][:8] + + # Default names for all other OSs + else: + owner = 'unknown' + group = 'unknown' + + # Add them to the detail + + detlist[index] += owner + (9 - len(owner)) * " " + detlist[index] += group + (9 - len(group)) * " " + + # Length + detlist[index] += str(stinfo[6]) + (11 - len(str(stinfo[6]))) * " " + + # Ctime + ftime = " ".join(time.ctime(stinfo[9]).split()[1:]) + detlist[index] += ftime + (21 - len(ftime)) * " " + + # File name + detlist[index] += all[index] + + except: + detlist[index] = all[index] + + return detlist # End of 'BuildDirList()' @@ -1022,9 +1095,6 @@ # And current location UI.CurrentDir = "" -# And file details dictionary -UI.Details = {} - # And the flag indicating new directory selected UI.NewDirEntered = FALSE