diff --git a/twander.py b/twander.py index 0655af1..1545136 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.184 2005/01/29 00:37:38 tundra Exp $" +RCSID = "$Id: twander.py,v 3.185 2005/01/29 04:31:54 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -43,12 +43,13 @@ # Set OS type - this allows us to trigger OS-specific code # where needed. -OSNAME = os.name +OSNAME = os.name +OSPLATFORM = sys.platform # If we're on Win32, try to load win32all stuff if possible WIN32ALL = False -if OSNAME == 'nt': +if OSPLATFORM == 'win32': try: from win32api import GetLogicalDriveStrings as GetDrives from win32api import GetUserName, GetFileAttributes, GetComputerName, GetDiskFreeSpace, GetVolumeInformation @@ -302,8 +303,13 @@ USETHREADS = False # Use threads on Unix? USEWIN32ALL = True # Use win32all features if available? WARN = True # Warnings on? +WILDNOCASE = False # Turns on case-insensitive wildcard matching WIN32ALLON = True # Flag for toggling win32all features while running +# Wildcards are case-insensitive on Win32 by default + +if OSPLATFORM == 'win32': + WILDNOCASE = True ##### # Constants @@ -410,7 +416,7 @@ # Get the user name -if OSNAME == 'nt': +if OSPLATFORM == 'win32': if WIN32ALL and USEWIN32ALL and WIN32ALLON: USERNAME = GetUserName() else: @@ -470,7 +476,7 @@ # Some things are OS-dependent -if OSNAME == 'nt': +if OSPLATFORM == 'win32': AltMask = (1<<17) DontCareMask |= Mod1Mask # Some versions of Win32 set this when Alt is pressed else: @@ -892,7 +898,7 @@ # Handle Windows variants - if sys.platform == 'win32': + if OSPLATFORM == 'win32': pipe = os.popen(command, 'r') # Handle Unix variants @@ -1000,12 +1006,21 @@ def FilterWildcardMatch(matchthis): + # Accomodate case-insensitive matching + + if WILDNOCASE: + wc = UI.FilterWildcard[2] + matchthis = matchthis.lower() + + else: + wc = UI.FilterWildcard[1] + # If there's not active filter, everything matches - if not UI.FilterWildcard[1]: + if not wc: matched = True - elif UI.FilterWildcard[1].match(matchthis): + elif wc.match(matchthis): matched = True else: @@ -1014,7 +1029,7 @@ # Invert the sense of the logic if so dictated, but # only if there is actually a wildcard active. - if UI.FilterWildcard[1] and INVERTFILTER: + if wc and INVERTFILTER: matched = not matched return matched @@ -1077,7 +1092,7 @@ # Load Symbol Table with predefined symbols UI.SymTable[SYMOS] = os.name - UI.SymTable[SYMPLATFORM] = sys.platform + UI.SymTable[SYMPLATFORM] = OSPLATFORM # Unbind all existing key bindings @@ -1847,7 +1862,7 @@ # If were on Win32 and have the extensions loaded also offer the drive list - if OSNAME == 'nt' and GetWin32Drives(): + if OSPLATFORM == 'win32' and GetWin32Drives(): UI.ShortBtn.menu.add_command(label="DriveList", command=lambda: KeyDriveList(None)) # Add Shortcut Key Definitions @@ -2419,7 +2434,10 @@ sortedby = "%s %s " % (TTLSORTFLD, srtfld) autostate = YesOrNo[AUTOREFRESH] + refreshing + filterwc = UI.FilterWildcard[0] + if WILDNOCASE: + filterwc = filterwc.lower() if INVERTFILTER: filterwc = "NOT " + filterwc filter = "%s %s" % (TTLFILTER, filterwc) @@ -2847,7 +2865,7 @@ # Unless we're running on Win32 and we are able to do # a Drive List View - elif OSNAME == 'nt' and GetWin32Drives(): + elif OSPLATFORM == 'win32' and GetWin32Drives(): LoadDirList(SHOWDRIVES) return 'break' @@ -2863,7 +2881,7 @@ # This is only possible on Win32 and if there is a list of # drives available - i.e, If Win32All is installed - if OSNAME == 'nt' and GetWin32Drives(): + if OSPLATFORM == 'win32' and GetWin32Drives(): LoadDirList(SHOWDRIVES) return 'break' @@ -3041,8 +3059,14 @@ wc = r".*" + uwc # Compile it - abort if compilation fails + # Build both a normal and lower-case version + # of the search engine so we can support case-insensitive + # matching elswehere. + try: wild = re.compile(wc) + wildl = re.compile(wc.lower()) + except: WrnMsg(wWILDCOMP % wc) return 'break' @@ -3050,7 +3074,7 @@ # This function can be called to use wildcards to: 1) Filter file list or 2) Select files if FilterWildcard: - UI.FilterWildcard = (wc, wild) + UI.FilterWildcard = (wc, wild, wildl) RefreshDirList(None) else: @@ -3240,7 +3264,7 @@ # do nothing if it is empty (which happens if the user has not # installed the Win32All package). - if OSNAME=='nt' and \ + if OSNAME =='nt' and \ os.path.abspath(UI.CurrentDir) == os.path.abspath(UI.CurrentDir + selected): LoadDirList(SHOWDRIVES, save=True) @@ -3306,7 +3330,7 @@ # We know what to do on Win32 and Unix. We ignore # the selection elsewhere. - elif OSNAME == 'nt': + elif OSPLATFORM == 'win32': ExecuteCommand(os.path.join(os.path.abspath(UI.CurrentDir), selected), '', ResolveBuiltIns=False, UseStartDir=True) elif OSNAME == 'posix': @@ -3577,7 +3601,7 @@ return # Reset any active filtering - UI.FilterWildcard = ("None", None) + UI.FilterWildcard = ("None", None, None) # Transform double forward-slashes into a single # forward-slash. This keeps the Directory Stack @@ -3604,7 +3628,7 @@ # not available (which means Win32All is not installed), # just ignore and return, doing nothing. - elif OSNAME != 'nt' or not GetWin32Drives(): + elif OSPLATFORM != 'win32' or not GetWin32Drives(): return # Indicate we are doing a refresh. @@ -3808,7 +3832,7 @@ # Collapse case on Win32 when sorting by name sortkey = fields[keyindex] - if OSNAME == 'nt' and (SORTBYFIELD.lower() == fNAME.lower()): + if OSPLATFORM == 'win32' and (SORTBYFIELD.lower() == fNAME.lower()): sortkey = sortkey.lower() # Keep track of the file name and its details, separating directories from files @@ -4185,7 +4209,7 @@ # Handle Win32 systems - elif OSNAME == 'nt': + elif OSPLATFORM == 'win32': # Defaults owner = WIN32OWNER @@ -4323,7 +4347,7 @@ # Force Unix-style path separators if requested - if FORCEUNIXPATH and OSNAME == 'nt': + if FORCEUNIXPATH and OSPLATFORM == 'win32': currentdir = currentdir.replace("\\", "/") dselection = dselection.replace("\\", "/") dselections = dselections.replace("\\", "/") @@ -4350,7 +4374,7 @@ if cmd.count(vblref): s = "" for m in UI.ProgMem[x]: - if FORCEUNIXPATH and OSNAME == 'nt': + if FORCEUNIXPATH and OSPLATFORM == 'win32': m = m.replace("\\", "/") s += QUOTECHAR + m + QUOTECHAR + " " cmd = cmd.replace(vblref, s) @@ -4550,7 +4574,7 @@ # Clearout any active wildcard filtering if asked to if ClearFilterWildcard: - UI.FilterWildcard = ("None", None) + UI.FilterWildcard = ("None", None, None) INVERTFILTER = False @@ -4698,7 +4722,7 @@ addentry = False - if OSNAME == 'nt': + if OSPLATFORM == 'win32': # First make a case-collapsed copy of the existing list @@ -4952,12 +4976,15 @@ "AUTOREFRESH":AUTOREFRESH, "FORCEUNIXPATH":FORCEUNIXPATH, "INVERTFILTER":INVERTFILTER, - "NODETAILS":NODETAILS, "NONAVIGATE":NONAVIGATE, + "NODETAILS":NODETAILS, + "NONAVIGATE":NONAVIGATE, "SORTREVERSE":SORTREVERSE, "SORTSEPARATE":SORTSEPARATE, "SYMDIR":SYMDIR, "USETHREADS":USETHREADS, - "USEWIN32ALL":USEWIN32ALL, "WARN":WARN} + "USEWIN32ALL":USEWIN32ALL, + "WILDNOCASE":WILDNOCASE, + "WARN":WARN} UI.OptionsNumeric = {"AFTERWAIT":AFTERWAIT,"DEBUGLEVEL":DEBUGLEVEL, "FSZ":FSZ, "MFSZ":MFSZ, "HFSZ":HFSZ, "HEIGHT":HEIGHT, "MAXMENU":MAXMENU, "MAXMENUBUF":MAXMENUBUF, "MAXNESTING":MAXNESTING, @@ -4988,7 +5015,7 @@ UI.CurrentDir = "" # Initialize storage for filtering wildcard -UI.FilterWildcard = ("None", None) +UI.FilterWildcard = ("None", None, None) # Initialize various menu data structures ClearHistory(None) @@ -5101,13 +5128,13 @@ # Windows is sloppy about accepting both '//' and '\\' # so we have to condition the command line input for consistency. - if OSNAME == 'nt' and STARTDIR == '//': + if OSPLATFORM == 'win32' and STARTDIR == '//': STARTDIR = SHOWDRIVES # Make sure any user request to start in a Drive List View # is possible. If not, just start in the root directory. - if STARTDIR == SHOWDRIVES and (OSNAME != 'nt' or not GetWin32Drives()): + if STARTDIR == SHOWDRIVES and (OSPLATFORM != 'win32' or not GetWin32Drives()): STARTDIR = PSEP if not os.path.isdir(STARTDIR):