diff --git a/twander.py b/twander.py index d2db799..21b4aae 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.60 2002/11/17 19:46:08 tundra Exp $" +RCSID = "$Id: twander.py,v 1.61 2002/11/18 08:00:00 tundra Exp $" VERSION = RCSID.split()[2] @@ -36,13 +36,13 @@ 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 -DIRPREV = '' # Goto previous directory +DIRPREV = '' # Goto previous directory DIRSTART = '' # Goto starting directory DIRUP = '' # Go up one directory level @@ -50,8 +50,8 @@ SELNEXT = '' # Select next item SELPREV = '' # Select previous item -SELFIRST = '' # Select top item -SELLAST = '' # Select bottom item +SELEND = '' # Select bottom item +SELTOP = '' # Select top item SELKEY = '' # Select item w/keyboard SELMOUSE = '' # Select item w/mouse @@ -395,6 +395,8 @@ # Bind handler of "Read Config File" self.DirList.bind(READCONF, ParseConfFile) + # Bind handler of "Refresh Screen" + self.DirList.bind(REFRESH, RefreshDirList) # Directory Navigation @@ -423,10 +425,10 @@ self.DirList.bind(SELPREV, KeySelPrev) # Bind handler for "First Item" - self.DirList.bind(SELFIRST, KeySelFirst) + self.DirList.bind(SELTOP, KeySelTop) # Bind handler for "Last Item" - self.DirList.bind(SELLAST, KeySelLast) + self.DirList.bind(SELEND, KeySelEnd) # Bind handler for "Item Select" self.DirList.bind(SELKEY, DirListHandler) @@ -448,7 +450,7 @@ def poll(self): RefreshDirList() - self.DirList.after(250, self.poll) + self.DirList.after(5000, self.poll) # End of method 'twanderUI.poll()' @@ -614,7 +616,7 @@ ##### def KeySelNext(event): - print "KeySelNext()" + SetSelection(UI.DirList.index(ACTIVE) + 1) # End of 'KeySelNext()' @@ -624,29 +626,34 @@ ##### def KeySelPrev(event): - print "KeySelPrev()" + SetSelection(UI.DirList.index(ACTIVE) - 1) # End of 'KeySelPrev()' ##### -# Event Handler: Select First Item -##### - -def KeySelFirst(event): - print "KeySelFirst()" - -# End of 'KeySelFirst()' - - -##### # Event Handler: Select Last Item ##### -def KeySelLast(event): - print "KeySelLast()" +def KeySelEnd(event): -# End of 'KeySelLast()' + # We just pass a really large number and + # let the called routines bounds checking + # do the work. + + SetSelection(100000) + +# End of 'KeySelEnd()' + + +##### +# Event Handler: Select First Item +##### + +def KeySelTop(event): + SetSelection(0) + +# End of 'KeySelTop()' ##### @@ -838,7 +845,9 @@ # So ... we just need to save the active index. active=UI.DirList.index(ACTIVE) - + selindex=UI.DirList.curselection() + + # Clear out the old contents UI.DirList.delete(0,END) @@ -850,24 +859,48 @@ # Make sure they are still in range singe we # may have fewer items after the refresh. # If out of range, just set to last item in list - + + SetSelection(active) + +# End of 'RefreshDirList() + + +##### +# Set a particular selection - does bounds checking +##### + +def SetSelection(index): + + # Clear all current selection(s) + UI.DirList.selection_clear(0, END) + + # Get current maximum index maxindex = UI.DirList.size() - 1 - if active >maxindex: - active = maxindex - - UI.DirList.selection_clear(0, maxindex) - UI.DirList.select_set(active) - UI.DirList.see(active) + # And bounds check/adjust the value desired - UI.DirList.activate(active) + if index > maxindex: + index = maxindex + + if index < 0: + index = 0 + + # Select specified item - make active selection track this + UI.DirList.activate(index) + UI.DirList.select_set(index) + + # And make sure it is visible within the current window + UI.DirList.see(index) + + # And force a visual update + UI.DirList.pack() # We have to update the title because the selection # may have changed. UI.UpdateTitle(UIroot) -# End of 'RefreshDirList() +# End of 'SetSelection()' #----------------------------------------------------------#