dabo Commit
Revision 6618
Date: 2011-06-11 10:09:58 -0700 (Sat, 11 Jun 2011)
Author: Ed
Trac: http://trac.dabodev.com/changeset/6618

Changed:
U   trunk/dabo/ui/uiwx/dTreeView.py

Log:
Enhanced the 'makeDirTree()' method to accept a list of file patterns for both 
including and excluding. Also added checks for upper/lower case versions of 
those patterns.

Diff:
Modified: trunk/dabo/ui/uiwx/dTreeView.py
===================================================================
--- trunk/dabo/ui/uiwx/dTreeView.py     2011-06-08 22:49:10 UTC (rev 6617)
+++ trunk/dabo/ui/uiwx/dTreeView.py     2011-06-11 17:09:58 UTC (rev 6618)
@@ -850,10 +850,12 @@
                        showHidden=False, expand=False):
                """
                Make this dTreeView show a filesystem directory hierarchy. You
-               can specify a wildcard pattern: e.g., "\*py" will only include 
files
-               ending in 'py'. If no wildcard is specified, all files will be 
included.
+               can specify a wildcard pattern: e.g., "*py" will only include 
files
+               ending in 'py'. You can also pass a list of wildcards, and 
files 
+               matching any of these will be included in the tree. If no 
wildcard
+               is specified, all files will be included.
 
-               You can also specify file patterns to ignore in the 'ignore' 
parameter.
+               You can also specify file patterns to ignore in the 'ignored' 
parameter.
                This can be a single string of a file pattern, or a list of 
such patterns.
                Any file matching any of these patterns will not be included in 
the tree.
 
@@ -878,7 +880,8 @@
                # Add any trailing slash character
                self._pathNode = {}
                # Define the function to be passed to os.path.walk
-               def addNode(showHid, currDir, fNames):
+               def addNode(arg, currDir, fNames):
+                       wildcards, ignored, showHid = arg
                        prnt, nm = os.path.split(currDir)
                        if not showHid and nm.startswith("."):
                                return
@@ -895,12 +898,16 @@
                        self.setNodeImg(nd, "folderopen", "expanded")
                        nd.ToolTipText = nd._filePath = currDir
                        acceptedNames = ignoredNames = None
-                       if wildcard is not None:
-                               acceptedNames = glob.glob(os.path.join(currDir, 
wildcard))
+                       if wildcards is not None:
+                               acceptedNames = []
+                               for wc in wildcards:
+                                       acceptedNames += 
glob.glob(os.path.join(currDir, wc.lower()))
+                                       acceptedNames += 
glob.glob(os.path.join(currDir, wc.upper()))
                        if ignored is not None:
                                ignoredNames = []
                                for ig in ignored:
-                                       ignoredNames += 
glob.glob(os.path.join(currDir, ig))
+                                       ignoredNames += 
glob.glob(os.path.join(currDir, ig.lower()))
+                                       ignoredNames += 
glob.glob(os.path.join(currDir, ig.upper()))
                        for f in fNames:
                                fullName = os.path.join(currDir, f)
                                if os.path.isdir(fullName):
@@ -923,10 +930,14 @@
                        if currDir in self._pathNode:
                                
self.SortChildren(self._pathNode[currDir].itemID)
 
+               if wildcard and not isinstance(wildcard, (list, tuple)):
+                       # single string passed
+                       wildcard = [wildcard]
                if ignored and not isinstance(ignored, (list, tuple)):
                        # single string passed
                        ignored = [ignored]
-               os.path.walk(dirPath, addNode, showHidden)
+               arg = (wildcard, ignored, showHidden)
+               os.path.walk(dirPath, addNode, arg)
                os.path.walk(dirPath, sortNode, None)
                if expand:
                        self.expandAll()



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to