eric6/Project/ProjectBaseBrowser.py

changeset 8243
cc717c2ae956
parent 8143
2c730d5fd177
child 8259
2bbec88047dd
equal deleted inserted replaced
8242:aa713ac50c0d 8243:cc717c2ae956
6 """ 6 """
7 Module implementing the baseclass for the various project browsers. 7 Module implementing the baseclass for the various project browsers.
8 """ 8 """
9 9
10 import os 10 import os
11 import contextlib
11 12
12 from PyQt5.QtCore import ( 13 from PyQt5.QtCore import (
13 QModelIndex, pyqtSignal, Qt, QCoreApplication, QItemSelectionModel, 14 QModelIndex, pyqtSignal, Qt, QCoreApplication, QItemSelectionModel,
14 QItemSelection, QElapsedTimer 15 QItemSelection, QElapsedTimer
15 ) 16 )
589 expandedNames = [] 590 expandedNames = []
590 591
591 childIndex = self.model().index(0, 0) 592 childIndex = self.model().index(0, 0)
592 while childIndex.isValid(): 593 while childIndex.isValid():
593 if self.isExpanded(childIndex): 594 if self.isExpanded(childIndex):
594 try: 595 with contextlib.suppress(AttributeError):
595 expandedNames.append( 596 expandedNames.append(
596 self.model().item(childIndex).name()) 597 self.model().item(childIndex).name())
597 except AttributeError:
598 # only items defining the name() method are returned 598 # only items defining the name() method are returned
599 pass
600 childIndex = self.indexBelow(childIndex) 599 childIndex = self.indexBelow(childIndex)
601 600
602 return expandedNames 601 return expandedNames
603 602
604 def expandItemsByName(self, names): 603 def expandItemsByName(self, names):
609 """ 608 """
610 model = self.model() 609 model = self.model()
611 for name in names: 610 for name in names:
612 childIndex = model.index(0, 0) 611 childIndex = model.index(0, 0)
613 while childIndex.isValid(): 612 while childIndex.isValid():
614 try: 613 with contextlib.suppress(AttributeError):
615 if model.item(childIndex).name() == name: 614 if model.item(childIndex).name() == name:
616 self.setExpanded(childIndex, True) 615 self.setExpanded(childIndex, True)
617 break 616 break
618 except AttributeError:
619 # ignore items not supporting this method 617 # ignore items not supporting this method
620 pass
621 childIndex = self.indexBelow(childIndex) 618 childIndex = self.indexBelow(childIndex)
622 619
623 def _prepareRepopulateItem(self, name): 620 def _prepareRepopulateItem(self, name):
624 """ 621 """
625 Protected slot to handle the prepareRepopulateItem signal. 622 Protected slot to handle the prepareRepopulateItem signal.

eric ide

mercurial