Coverage for PyRx.dirNavigator : 39%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#$Id: dirNavigator.py 258 2015-11-14 17:04:46Z sarkiss $ This can be replaced with wx.GenericDirCtrl """
"""wx.Panel with wx.TreeCtrl (self.tree) used to store AutoDock data as in a tree: Example: tree = MolTreeCtrlPanel(parent) tree.buildTree(path)
wxTreeItemIds are stored in self.treeDict """ "parent is passed to wx.Panel.__init__" # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
# self.tree.SetPyData(self.root, None) # self.tree.SetItemImage(self.root, self.fldridx, wx.TreeItemIcon_Normal) # self.tree.SetItemImage(self.root, self.fldropenidx, wx.TreeItemIcon_Expanded) #self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.tree) #self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndEdit, self.tree)
selection = self.tree.GetSelections() if len(selection) > 1: return elif selection: self.tree.SelectItem(selection[0], False) pt = event.GetPosition() item, flags = self.tree.HitTest(pt) if item.IsOk(): self.tree.SelectItem(item) event.Skip()
"Creates Refresh menu on x.EVT_RIGHT_UP" menu = wx.Menu() selections = self.tree.GetSelections() if len(selections) == 1: self.selection = selections[0] elif len(selections) != 0: deleteAllMenu = menu.Append(wx.ID_ANY, "Delete") self.Bind(wx.EVT_MENU, self.OnDeleteAll, deleteAllMenu) self.selection = None self.selections = selections else: #selections = 0 self.selection = None
if self.selection and self.selection != self.tree.RootItem: file = self.tree.GetPyData(self.selection) self.path = file tmp, ext = os.path.splitext(file) if 'pdb' in ext: displayMenu = menu.Append(wx.ID_ANY, "Display") self.Bind(wx.EVT_MENU, self.OnDisplay, displayMenu) elif 'map' in ext: displayMayaviMenu = menu.Append(wx.ID_ANY, "Display (Mayavi)") self.Bind(wx.EVT_MENU, self.OnDisplayMayavi, displayMayaviMenu) if os.path.isfile(self.path): editMenu = menu.Append(wx.ID_ANY, "Edit") self.Bind(wx.EVT_MENU, self.OnEdit, editMenu) deleteMenu = menu.Append(wx.ID_ANY, "Delete") self.Bind(wx.EVT_MENU, self.OnDelete, deleteMenu) menu.AppendSeparator() propertiesMenu = menu.Append(wx.ID_ANY, "Properties") self.Bind(wx.EVT_MENU, self.OnProperties, propertiesMenu) menu.AppendSeparator()
refreshMenu = menu.Append(wx.ID_ANY, "Refresh") self.Bind(wx.EVT_MENU, self.OnRefresh, refreshMenu) self.PopupMenu(menu) event.Skip()
# try: #used when TR_MULTIPLE is False # self.selection = self.tree.GetSelection() # except: self.GetSingleSelection() if self.selection: file = self.tree.GetPyData(self.selection) self.path = file tmp, ext = os.path.splitext(file) if 'pdb' in ext: self.OnDisplay(event) elif 'map' in ext: self.OnDisplayMayavi(event) else: self.OnEdit(event) event.Skip()
selections = self.tree.GetSelections() if len(selections) == 1: self.selection = selections[0] else: self.selection = None return self.selection
dlg = wx.MessageDialog(self, 'Path: '+self.path, 'Path', wx.CENTRE #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION ) dlg.ShowModal() dlg.Destroy()
if self.selection: path = self.tree.GetPyData(self.selection) if os.path.isfile(path): try: self.frame.documentsView.OpenDocument(path) except Excpetion, inst: self.frame.log.error("Error Editing "+path+"\n"+str(inst))
self.frame.molNav.TryOpenMolecule(self.path) self.frame.view.SetSelection(0)#3D Canvas
self.frame.mayaviEngine.DisplayAutoGridMap(self.path)
dirList = [] path = self.path if os.path.exists(path): if os.path.isdir(path): val = wx.ID_YES if confirm: dlg = wx.MessageDialog(self, 'Are you sure you want to delete '+path+" ?", 'Confirm Folder Delete', wx.YES_NO | wx.ICON_INFORMATION ) val = dlg.ShowModal() dlg.Destroy()
if val == wx.ID_YES: dirList.append(path)
else: os.remove(path) self.treeDict.pop(path) self.tree.Delete(self.selection)
for dir in dirList: if not dir == self.basePath: for root, dirs, files in os.walk(dir, topdown=False): for name in files: try: filePath = os.path.join(root, name) os.remove(filePath) self.tree.Delete(self.treeDict[filePath]) self.treeDict.pop(filePath) except: pass
for name in dirs: try: filePath = os.path.join(root, name) os.rmdir(filePath) self.tree.Delete(self.treeDict[filePath]) self.treeDict.pop(filePath) except: pass
os.rmdir(dir) self.tree.Delete(self.treeDict[dir]) self.treeDict.pop(dir)
dlg = wx.MessageDialog(self, 'Are you sure you want to delete selected files/folders ?', 'Confirm Folder Delete', wx.YES_NO | wx.ICON_INFORMATION ) val = dlg.ShowModal() dlg.Destroy() if val != wx.ID_YES: return
popList = [] #the list of files that should be removed from self.selections to avoid crashes for selection in self.selections: path = self.tree.GetPyData(selection) if os.path.isdir(path): for tmpSelection in self.selections: file = self.tree.GetPyData(tmpSelection) if path in file and tmpSelection != selection: popList.append(tmpSelection)
setList = set(popList) for item in setList: self.selections.remove(item)
for selection in self.selections: self.selection = selection file = self.tree.GetPyData(self.selection) self.path = file self.OnDelete(None, False)
"Bound to wx.EVT_SIZE"
"""Recessively builds the tree: root is wxTreeItemId, path is a directory""" else: else:
"Builds the tree by using self.tree.AddRoot and self.build"
"Invoked when Refresh menu is pressed" #now set back selections
item = event.GetItem() if item and self.tree.GetPyData(item) == self.basePath: event.Veto()
txt = event.GetLabel() if not txt: event.Veto() return path = self.tree.GetPyData(event.GetItem()) path1, path2 = os.path.split(path) newPath = os.path.join(path1, txt) os.rename(path, newPath)
""" From http://zeta-puppis.com/blog/2008/02/15/python-listdir-order Returns the content of a directory by showing directories first and then files by ordering the names alphabetically """ return dirs |