diff --git a/twander.py b/twander.py index 22e1fd8..3ed5a1f 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.69 2002/11/21 19:57:06 tundra Exp $" +RCSID = "$Id: twander.py,v 1.70 2002/11/21 21:06:58 tundra Exp $" VERSION = RCSID.split()[2] @@ -35,27 +35,27 @@ # General Program Commands -KEYPRESS = '' # Any keypress (for commands) -QUITPROG = '' # Quit the program -READCONF = '' # Re-read the configuration file -REFRESH = '' # Refresh screen +KEYPRESS = '' # Any keypress (for commands) +QUITPROG = '' # Quit the program +READCONF = '' # Re-read the configuration file +REFRESH = '' # Refresh screen # Directory Navigation -CHANGEDIR = '' # Enter a new path -DIRHOME = '' # Goto $HOME -DIRBACK = '' # Goto previous directory -DIRSTART = '' # Goto starting directory -DIRUP = '' # Go up one directory level +CHANGEDIR = '' # Enter a new path +DIRHOME = '' # Goto $HOME +DIRBACK = '' # Goto previous directory +DIRSTART = '' # Goto starting directory +DIRUP = '' # Go up one directory level # Selection Keys -SELNEXT = '' # Select next item -SELPREV = '' # Select previous item -SELEND = '' # Select bottom item -SELTOP = '' # Select top item -SELKEY = '' # Select item w/keyboard -SELMOUSE = '' # Select item w/mouse +SELNEXT = '' # Select next item +SELPREV = '' # Select previous item +SELEND = '' # Select bottom item +SELTOP = '' # Select top item +SELKEY = '' # Select item w/keyboard +SELMOUSE = '' # Select item w/mouse ##### @@ -125,7 +125,7 @@ ##### HOSTNAME = getfqdn() # Full name of this host -REFRESHINT = 2000 # Interval (ms) for automatic refresh +REFRESHINT = 1000 # Interval (ms) for automatic refresh # Set OS type - this allows us to trigger OS-specific code @@ -535,7 +535,7 @@ newpath = askstring(pCHPATH, pENPATH) if newpath: LoadDirList(newpath) - SetSelection(0) + SetSelection(0,0) UI.DirList.focus() # End of 'ChangeDir()' @@ -603,7 +603,8 @@ ##### def KeySelNext(event): - SetSelection(UI.DirList.index(ACTIVE) + 1) + next = UI.DirList.index(ACTIVE) + 1 + SetSelection(next, next) # End of 'KeySelNext()' @@ -613,7 +614,8 @@ ##### def KeySelPrev(event): - SetSelection(UI.DirList.index(ACTIVE) - 1) + prev = UI.DirList.index(ACTIVE) - 1 + SetSelection(prev, prev) # End of 'KeySelPrev()' @@ -628,7 +630,7 @@ # let the called routines bounds checking # do the work. - SetSelection(100000) + SetSelection(100000, 100000) # End of 'KeySelEnd()' @@ -638,7 +640,7 @@ ##### def KeySelTop(event): - SetSelection(0) + SetSelection(0, 0) # End of 'KeySelTop()' @@ -697,7 +699,7 @@ # won't try to operate on an item selected in a # previous directory - SetSelection(0) + SetSelection(0, 0) # File selected with a double-click # If we're running Win32, use OS association to try and run it. @@ -768,8 +770,13 @@ UI.DirList.insert(END, x) # And update the title to reflect changes - UI.UpdateTitle(UIroot) + UI.UpdateTitle(UIroot) + # Indicate that we've just entered a new directory + # so RefreshDirList does the right thing + + UI.NewDirEntered = TRUE + # End of 'LoadDirList(): @@ -803,7 +810,11 @@ # Go get details for everything in current directory for entry in (dList + fList): - UI.Details[entry] = os.stat(os.path.join(currentdir, entry)) + fullname = os.path.join(currentdir, entry) + try: + UI.Details[entry] = os.stat(fullname) + except: + UI.Details[entry] = "NO DETAILS FOUND" return dList + fList @@ -816,14 +827,15 @@ def RefreshDirList(*args): - # Save location & content of active item + # Get current selection and active selindex = UI.DirList.curselection() if selindex: selindex = int(selindex[-1]) - selected = UI.CurrentSelection() + active = UI.DirList.index(ACTIVE) + # Save current scroll positions xs = UI.hSB.get() @@ -838,14 +850,26 @@ # Save the new directory information UI.DirList.insert(0, *newlist) - # If possible, maintain selection of same *item*. - # If not, maintain same *position* in widget (set above). + # First refresh after a new directory + # entered needs to force selection and + # active to 0. This works around some + # strange Tkinter behavior. - if selected in newlist: - selindex = newlist.index(selected) + if UI.NewDirEntered: + SetSelection(0,0) + UI.NewDirEntered = FALSE - # Restore active item - SetSelection(selindex) + # Otherwise, preserve the values across refreshes + else: + + # If possible, maintain selection of same *item*. + # If not, maintain same *position* in widget (set above). + + if selected in newlist: + selindex = newlist.index(selected) + + # Restore active item + SetSelection(selindex, active) # Restore scroll positions @@ -860,7 +884,7 @@ # Set a particular selection, w/bounds checking ##### -def SetSelection(index): +def SetSelection(selection, active): # Clear all current selection(s) UI.DirList.selection_clear(0, END) @@ -870,17 +894,21 @@ # And bounds check/adjust the value desired - if index > maxindex: - index = maxindex + if selection > maxindex: + selection = maxindex + if active > maxindex: + active = maxindex - if index < 0: - index = 0 + if selection < 0: + selection = 0 + if active < 0: + active = 0 # Select specified item - make active selection track this - UI.DirList.activate(index) - UI.DirList.select_set(index) + UI.DirList.select_set(selection) + UI.DirList.activate(active) - UI.DirList.see(index) + UI.DirList.see(selection) # End of 'SetSelection()' @@ -975,8 +1003,12 @@ # And file details dictionary UI.Details = {} +# And the flag indicating new directory selected +UI.NewDirEntered = FALSE + # Initialize the UI directory listing LoadDirList(STARTDIR) +SetSelection(0, 0) # And start the periodic polling of the widget UI.poll()