def _OnPopupNewFolder(self, event): """ Popup event handler for creating new folders by rightclicking inside the projectree. """ selections = self.GetSelections() if len(selections) == 1: selected = selections[0] currentElementData = self.GetPyData(selected) if currentElementData.__class__.__name__ != 'WpProjectData': dialog = wx.TextEntryDialog(self, '', 'Foldername', '') if dialog.ShowModal() == wx.ID_OK: folderName = dialog.GetValue() newFolderPath = os.path.join(currentElementData.getCurrentDirectory(), folderName) ## Does this folder already exist? if os.path.isdir(newFolderPath) == False: os.mkdir(newFolderPath) ## Append folder to tree nodeData = WpElementData() nodeData.setCurrentDirectory(newFolderPath) nodeData.setCurrentFile(newFolderPath) if currentElementData.getCurrentFilename() != None: selected = self.GetItemParent(selected) newItem = self.PrependItem( selected, folderName, 0, 1, wx.TreeItemData(nodeData) ) self.EnsureVisible(newItem) self.Unselect() self.SelectItem(newItem) else: dialog = wx.MessageDialog(None, 'Folder already exists', 'Warning', wx.OK | wx.ICON_QUESTION) if dialog.ShowModal() == wx.ID_OK: dialog.Destroy()
def _OnPopupNewFile(self, event): """ Popup event handler for creating new files by rightclicking inside the projectree. """ selections = self.GetSelections() if len(selections) == 1: selected = selections[0] currentElementData = self.GetPyData(selected) dialog = wx.TextEntryDialog(self, '', 'Filename', '') if dialog.ShowModal() == wx.ID_OK: fileName = dialog.GetValue() newFilePath = os.path.join(currentElementData.getCurrentDirectory(), fileName) if os.path.isfile(newFilePath) == False: WpFileSystem.SaveToFile( '', newFilePath ) ## Adding new file to project tree nodedata = WpElementData() nodedata.setCurrentDirectory(currentElementData.getCurrentDirectory()) nodedata.setCurrentFilename(fileName) nodedata.setCurrentFile( os.path.join(nodedata.getCurrentDirectory(),fileName) ) if currentElementData.getCurrentFilename() != None: selected = self.GetItemParent(selected) newFileItem = self.AppendItem( selected, fileName, 2, 2, wx.TreeItemData(nodedata) ) self.EnsureVisible(newFileItem) self.Unselect() self.SelectItem(newFileItem) else: dialog = wx.MessageDialog(None, 'File already exists', 'Warning', wx.OK | wx.ICON_QUESTION) if dialog.ShowModal() == wx.ID_OK: dialog.Destroy()
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')