diff --git a/twander.py b/twander.py index d7ff8f8..05d24d4 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.176 2005/01/27 10:21:39 tundra Exp $" +RCSID = "$Id: twander.py,v 3.177 2005/01/27 10:53:44 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -117,7 +117,6 @@ SELPREV = '' # Select previous item SELEND = '' # Select bottom item SELTOP = '' # Select top item -SELWILD = '' # Select using wildcards # Scrolling Commands @@ -191,6 +190,12 @@ SORTREV = '' SORTSEP = '' +# Wildcard Features + +FILTERWILD = '' # Filter file list with wildcard +SELWILD = '' # Select using wildcards + + ##### # GUI Defaults ##### @@ -1021,7 +1026,6 @@ "SELPREV":SELPREV, "SELEND":SELEND, "SELTOP":SELTOP, - "SELWILD":SELWILD, "PGDN":PGDN, "PGUP":PGUP, "PGRT":PGRT, @@ -1076,6 +1080,8 @@ "SORTBYNAME":SORTBYNAME, "SORTREV":SORTREV, "SORTSEP":SORTSEP, + "FILTERWILD":FILTERWILD, + "SELWILD":SELWILD, } # Set all the program options to their default values @@ -1942,6 +1948,9 @@ # Bind handler to invoke Clear Command History self.DirList.bind(self.KeyBindings["CLRHIST"], ClearHistory) + # Bind handler for "Select With Wildcard" + self.DirList.bind(self.KeyBindings["FILTERWILD"], lambda event : KeySelWild(event, FilterWildcard=True)) + # Bind handler to invoke Decrement Font Size self.DirList.bind(self.KeyBindings["FONTDECR"], FontDecr) @@ -1976,7 +1985,7 @@ self.DirList.bind(self.KeyBindings["READCONF"], ProcessConfiguration) # Bind handler for "Refresh Screen" - self.DirList.bind(self.KeyBindings["REFRESH"], RefreshDirList) + self.DirList.bind(self.KeyBindings["REFRESH"], lambda event : RefreshDirList(event, ClearFilterWildcard=True)) # Bind handler for "Toggle Autorefresh" self.DirList.bind(self.KeyBindings["TOGAUTO"], KeyToggleAuto) @@ -2208,7 +2217,7 @@ # Don't autorefresh if there is a lock outstanding if not UI.DirListMutex.test(): - RefreshDirList() + RefreshDirList(None) # Setup next polling event self.DirList.after(POLLINT, self.poll) @@ -2857,7 +2866,7 @@ # Event Handler: Select Using Wildcard ##### -def KeySelWild(event, initial=""): +def KeySelWild(event, initial="", FilterWildcard=False): global UI # Ask the user for the wildcard pattern, using initial string, if any @@ -2891,23 +2900,28 @@ WrnMsg(wWILDCOMP % wc) return 'break' - # Iterate over the current directory listing - # saving the indexes of items which match. - # We start at 1 not 0 because the first entry - # ("..") is never considered when doing wildcard - # matching. + # This function can be called to use wildcards to: 1) Filter file list or 2) Select files - UI.FilterWildcard = wild - RefreshDirList() + if FilterWildcard: + UI.FilterWildcard = wild + RefreshDirList(None) -# matches = [] -# for x in range(1,UI.DirList.size()): -# if wild.match(UI.DirList.get(x)): -# matches.append(x) -# -# # If anything matched, select it -# if matches: -# UI.SetSelection(matches, matches[0]) + else: + + # Iterate over the current directory listing + # saving the indexes of items which match. + # We start at 1 not 0 because the first entry + # ("..") is never considered when doing wildcard + # matching. + + matches = [] + for x in range(1,UI.DirList.size()): + if wild.match(UI.DirList.get(x)): + matches.append(x) + + # If anything matched, select it + if matches: + UI.SetSelection(matches, matches[0]) # Save the wildcard only if dynamic menus are enabled (MAXMENU > 0) # AND one of two conditions exist: @@ -3281,7 +3295,7 @@ if refresh: LoadHelpMenu() - RefreshDirList() + RefreshDirList(None) return 'break' @@ -3400,7 +3414,7 @@ time.sleep(AFTERWAIT) if AFTERCLEAR: KeySelNone(None) - RefreshDirList() + RefreshDirList(None) # End of 'ExecuteCommand() @@ -4379,7 +4393,8 @@ # Refresh Contents Of Directory Listing To Stay In Sync With Reality ##### -def RefreshDirList(*args): +def RefreshDirList(event, ClearFilterWildcard=False): + global UI # Indicate that we are doing an refresh UI.UpdateTitle(UIroot, refreshing=REFRESHINDI) @@ -4389,6 +4404,11 @@ while not UI.DirListMutex.testandset(): pass + # Clearout any active wildcard filtering if asked to + + if ClearFilterWildcard: + UI.FilterWildcard = None + # Get current selection and active sellist = UI.DirList.curselection() @@ -4475,7 +4495,7 @@ # Reflect Our Changes In The Interface ##### - RefreshDirList() + RefreshDirList(None) ##### # Dump requested debug information