diff --git a/twander.py b/twander.py index 3ed5a1f..b3aeccc 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ PROGNAME = "twander" -RCSID = "$Id: twander.py,v 1.70 2002/11/21 21:06:58 tundra Exp $" +RCSID = "$Id: twander.py,v 1.71 2002/11/21 22:59:16 tundra Exp $" VERSION = RCSID.split()[2] @@ -147,7 +147,8 @@ CMDKEY = r'&' # Command key delimiter COMMENT = r"#" # Comment character DIRNAME = r'[DIRECTORY]' # Substitution field in config files -FILENAME = r'[FILE]' # Substitution field in config files +FILE = r'[FILE]' # Substitution field in config files +FILES = r'[FILES]' # Ditto ENVIRO = r'$' # Introduces environment variables @@ -358,7 +359,7 @@ foreground = FCOLOR, background = BCOLOR, font=(FNAME, FSZ, FWT), - selectmode=BROWSE, + selectmode=EXTENDED, exportselection=0, xscrollcommand=self.hSB.set, yscrollcommand=self.vSB.set, @@ -450,17 +451,32 @@ ##### + # Return tuple of all selected items + ##### + + def AllSelection(self): + sellist = [] + + for entry in self.DirList.curselection(): + sellist.append(self.DirList.get(entry)) + + return sellist + + # End of method 'twanderUI.AllSelection()' + + + ##### # Return name of currently selected item ##### - def CurrentSelection(self): + def LastSelection(self): index = self.DirList.curselection() if index: return self.DirList.get(index[-1]) else: return "" - # End of method 'twanderUI.CurrentSelection()' + # End of method 'twanderUI.LastSelection()' ##### @@ -504,7 +520,13 @@ # Replace runtime-determined tokens - cmd = cmd.replace(FILENAME, UI.CurrentSelection()) + cmd = cmd.replace(FILE, UI.LastSelection()) + + fstring = "" + for selected in UI.AllSelection(): + fstring += selected + " " + + cmd = cmd.replace(FILES, fstring) cmd = cmd.replace(DIRNAME, UI.CurrentDir) # Actually execute the command @@ -535,7 +557,7 @@ newpath = askstring(pCHPATH, pENPATH) if newpath: LoadDirList(newpath) - SetSelection(0,0) + KeySelTop(event) UI.DirList.focus() # End of 'ChangeDir()' @@ -604,7 +626,7 @@ def KeySelNext(event): next = UI.DirList.index(ACTIVE) + 1 - SetSelection(next, next) + SetSelection((str(next),), next) # End of 'KeySelNext()' @@ -615,7 +637,7 @@ def KeySelPrev(event): prev = UI.DirList.index(ACTIVE) - 1 - SetSelection(prev, prev) + SetSelection((str(prev),), prev) # End of 'KeySelPrev()' @@ -626,11 +648,11 @@ def KeySelEnd(event): - # We just pass a really large number and - # let the called routines bounds checking - # do the work. + # Get current number of items in listbox + sz = UI.DirList.size() - SetSelection(100000, 100000) + # And setup to last item accordingly + SetSelection((str(sz),), sz) # End of 'KeySelEnd()' @@ -640,7 +662,7 @@ ##### def KeySelTop(event): - SetSelection(0, 0) + SetSelection(('0',),0) # End of 'KeySelTop()' @@ -653,7 +675,7 @@ SAVE = TRUE # Get current selection. If none, just return, otherwise process - selected = UI.CurrentSelection() + selected = UI.LastSelection() if not selected: return @@ -699,7 +721,7 @@ # won't try to operate on an item selected in a # previous directory - SetSelection(0, 0) + KeySelTop(event) # File selected with a double-click # If we're running Win32, use OS association to try and run it. @@ -829,10 +851,8 @@ # Get current selection and active - selindex = UI.DirList.curselection() - if selindex: - selindex = int(selindex[-1]) - selected = UI.CurrentSelection() + sellist = UI.DirList.curselection() + selected = UI.LastSelection() active = UI.DirList.index(ACTIVE) @@ -856,7 +876,7 @@ # strange Tkinter behavior. if UI.NewDirEntered: - SetSelection(0,0) + KeySelTop(args) UI.NewDirEntered = FALSE # Otherwise, preserve the values across refreshes @@ -869,7 +889,7 @@ selindex = newlist.index(selected) # Restore active item - SetSelection(selindex, active) + SetSelection(sellist, active) # Restore scroll positions @@ -892,23 +912,21 @@ # Get current maximum index maxindex = UI.DirList.size() - 1 - # And bounds check/adjust the value desired + # And bounds check/adjust - if selection > maxindex: - selection = maxindex if active > maxindex: active = maxindex - if selection < 0: - selection = 0 - if active < 0: - active = 0 + # Set desired selected items, if any - # Select specified item - make active selection track this - UI.DirList.select_set(selection) + if selection: + for entry in selection: + UI.DirList.select_set(entry) + UI.DirList.see(selection[-1]) + + # Now set the active entry UI.DirList.activate(active) - UI.DirList.see(selection) # End of 'SetSelection()' @@ -1008,7 +1026,7 @@ # Initialize the UI directory listing LoadDirList(STARTDIR) -SetSelection(0, 0) +KeySelTop(None) # And start the periodic polling of the widget UI.poll()