def PopulateTree( self, projectobj ): """ Build and populate this instance of the projecttree @param Object WpProject """ self.project = projectobj ## Get configuration for this tree self.excludeprefix = self.configobj.settings['projecttree-prefixexclude'] self.excludesuffix = self.configobj.settings['projecttree-suffixexclude'] ## File and folder exclusions criteriasuffix = re.compile(self.excludesuffix) criteriaprefix = re.compile(self.excludeprefix) self.SetIndent(10) # Destroying all content if content is present alreadyopened = False if( self.IsEmpty() == False ): self.DeleteAllItems() alreadyopened = True ArtIDs = [ 'wx.ART_FOLDER', 'wx.ART_FOLDER_OPEN', 'wx.ART_NORMAL_FILE', 'wx.ART_HELP_FOLDER' ] il = wx.ImageList( 16, 16 ) for items in ArtIDs: pic = wx.ArtProvider_GetBitmap(eval(items), wx.ART_TOOLBAR, ( 16, 16 ) ) il.Add( pic ) self.AssignImageList( il ) ## Setup project information projectInformation = WpProjectData() projectInformation.setProjectName(self.project.GetTitle()) treeroot = self.AddRoot( projectInformation.getProjectName(), 3, 3, wx.TreeItemData(projectInformation) ) ## Set project tree pane text to project name pub.sendMessage('mainframe.setpanetitle', {'pane': 'project', 'caption': projectInformation.getProjectName()}) self.SetItemHasChildren(treeroot, True) self.SetItemBold(treeroot) self.SetItemBackgroundColour(treeroot, wx.Colour(162, 181, 205)) root = treeroot ids = {root: treeroot} ## Build projecttree by looping over current directory listing for dir in self.project.GetPaths(): dlist = WpFileSystem.ListDirectory( dir ) ## Prepare basic information for node pathTitle = os.path.split(dir)[1] subrootInformation = WpElementData() subrootInformation.setCurrentDirectory(dir) subroot = self.AppendItem(treeroot, pathTitle, 0, 1, wx.TreeItemData(subrootInformation)) self.SetItemHasChildren( subroot, True ) ids = {dir: subroot} ## Build directories and filenames for( dirpath, dirnames, filenames ) in dlist[ 'files' ]: for dirname in dirnames: directoryInformation = WpElementData() directoryInformation.setCurrentDirectory(os.path.join( dirpath, dirname)) directoryInformation.setCurrentFile( os.path.join( subrootInformation.getCurrentDirectory(), directoryInformation.getCurrentDirectory() ) ) ids[directoryInformation.getCurrentDirectory()] = self.AppendItem( ids[dirpath], dirname, 0, 1, wx.TreeItemData(directoryInformation) ) for filename in sorted(filenames): ## Exclude files if re.search(criteriasuffix, filename) or re.search(criteriaprefix, filename): continue fileInformation = WpElementData() fileInformation.setCurrentDirectory(dirpath) fileInformation.setCurrentFilename(filename) fileInformation.setProjectId(self.project.GetId()) fileInformation.setCurrentFile( os.path.join( fileInformation.getCurrentDirectory(), fileInformation.getCurrentFilename() ) ) self.AppendItem( ids[fileInformation.getCurrentDirectory()], fileInformation.getCurrentFilename(), 2, 2, wx.TreeItemData(fileInformation) ) self.SetupBindings() ## Show the project tree pub.sendMessage('mainframe.showpane', 'project')