diff --git a/twander.py b/twander.py index 3f4363a..68e51c3 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.47 2002/11/13 09:46:26 tundra Exp $" +RCSID = "$Id: twander.py,v 1.48 2002/11/13 23:17:16 tundra Exp $" VERSION = RCSID.split()[2] @@ -162,7 +162,6 @@ #----------------------------------------------------------# -FILESELECTED = "" LASTDIR = [] STARTDIR = "" @@ -265,9 +264,6 @@ def UpdateDirList(): - # Update the window title - UIroot.title(PROGNAME + " " + VERSION + " " + ROOTDIR) - # Clear out the old contents UI.DirList.delete(0,END) @@ -371,46 +367,22 @@ ##### -# Determine if a file or directory selected. -# Returns TRUE for directory, FALSE for file. -# Side-Effect: global FILESELECTED set to filename or "" -##### - -def IsDirSelected(selected): - global FILESELECTED - - FILESELECTED = "" - - if selected[0] == DIR_LDELIM and selected[-1] == DIR_RDELIM: - FILESELECTED = "" # Directory selected - return TRUE - else: - FILESELECTED = selected # File was selected - return FALSE - -# End of 'IsDirSelected()' - - -##### # Process Current Selection ##### def DirListHandler(event): - global FILESELECTED, ROOTDIR + global ROOTDIR - index = event.widget.curselection() - - # If nothing is currently selected, we have no futher work - if not index: + # Get current selection. If none, just return, otherwise process + selected = UI.CurrentSelection() + if not selected: return - - selected = UI.DirList.get(index) # If selection is a directory, move there and list contents. # We examine this by checking the string for the directory # delimiter characters previously inserted in BuildDirList() - if IsDirSelected(selected): + if selected[0] == DIR_LDELIM and selected[-1] == DIR_RDELIM: # Strip off delimiters to get real name selected = selected[1:-1] @@ -443,11 +415,14 @@ UI.DirList.selection_set(('0',)) - # File was selected. Save its full name for later use. + # File selected else: pass -# End of 'Process Selection()' + # Update the window title + UI.UpdateTitle(UIroot) + +# End of 'DirListHandler()' #----------------------------------------------------------# @@ -523,7 +498,7 @@ self.DirList.focus() -# End if class '__init__' + # End if method 'twanderUI.__init__()' ##### @@ -534,9 +509,42 @@ def poll(self): RefreshDirList() - self.DirList.after(2000, self.poll) + self.DirList.after(1000, self.poll) + + # End of method 'twanderUI.poll()' + ##### + # Return name of currently selected item + ##### + + def CurrentSelection(self): + index = self.DirList.curselection() + if index: + return self.DirList.get(index) + else: + return "" + + # End of method 'twanderUI.CurrentSelection()' + + + ##### + # Update title bar with most current information + ##### + + def UpdateTitle(self, mainwin): + + # Get current selection + selected = self.CurrentSelection() + + # Only append selection if it is a file + if selected[0] == DIR_LDELIM and selected[-1] == DIR_RDELIM: + selected = "" + + # Update the titlebar + mainwin.title(PROGNAME + " " + VERSION + " " + ROOTDIR + selected) + + # End of method 'twanderUI.UpdateTitle()' # End of class definition, 'twanderUI' @@ -560,11 +568,23 @@ # Restore current selection and active entry + # 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 + + maxindex = UI.DirList.size() - 1 + if number > maxindex: + number = maxindex + if active >maxindex: + active = maxindex + UI.DirList.select_set(number) UI.DirList.see(number) UI.DirList.activate(active) + # Update the window title + UI.UpdateTitle(UIroot) # End of 'RefreshDirList() @@ -642,7 +662,7 @@ if cmd: # Replace runtime-determined tokens - cmd = cmd.replace(FILENAME, FILESELECTED) + cmd = cmd.replace(FILENAME, UI.CurrentSelection()) cmd = cmd.replace(DIRNAME, ROOTDIR) # Actually execute the command