Project/ProjectBaseBrowser.py

changeset 3601
236578b22511
parent 3600
7d17c492ab95
child 3603
cd14023a8ac1
equal deleted inserted replaced
3600:7d17c492ab95 3601:236578b22511
570 """ 570 """
571 Public method to get the file/directory names of all expanded items. 571 Public method to get the file/directory names of all expanded items.
572 572
573 @return list of expanded items names (list of string) 573 @return list of expanded items names (list of string)
574 """ 574 """
575 # step 1: find the top most index
576 childIndex = self.currentIndex()
577 if not childIndex.isValid():
578 return []
579
580 while childIndex.isValid():
581 topIndex = childIndex
582 childIndex = self.indexAbove(childIndex)
583
584 # step 2: get names of expanded items
585 expandedNames = [] 575 expandedNames = []
586 childIndex = topIndex 576
577 childIndex = self.model().index(0, 0)
587 while childIndex.isValid(): 578 while childIndex.isValid():
588 if self.isExpanded(childIndex): 579 if self.isExpanded(childIndex):
589 expandedNames.append( 580 try:
590 self.model().item(childIndex).name()) 581 expandedNames.append(
582 self.model().item(childIndex).name())
583 except AttributeError:
584 # only items defining the name() method are returned
585 pass
591 childIndex = self.indexBelow(childIndex) 586 childIndex = self.indexBelow(childIndex)
587
592 return expandedNames 588 return expandedNames
589
590 def expandItemsByName(self, names):
591 """
592 Public method to expand items given their names.
593
594 @param names list of item names to be expanded (list of string)
595 """
596 model = self.model()
597 for name in names:
598 childIndex = model.index(0, 0)
599 while childIndex.isValid():
600 if model.item(childIndex).name() == name:
601 self.setExpanded(childIndex, True)
602 break
603 childIndex = self.indexBelow(childIndex)
593 604
594 def _prepareRepopulateItem(self, name): 605 def _prepareRepopulateItem(self, name):
595 """ 606 """
596 Protected slot to handle the prepareRepopulateItem signal. 607 Protected slot to handle the prepareRepopulateItem signal.
597 608

eric ide

mercurial