本文整理汇总了Python中spyderlib.qt.QtGui.QTreeWidgetItem.childCount方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem.childCount方法的具体用法?Python QTreeWidgetItem.childCount怎么用?Python QTreeWidgetItem.childCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem.childCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh
# 需要导入模块: from spyderlib.qt.QtGui import QTreeWidgetItem [as 别名]
# 或者: from spyderlib.qt.QtGui.QTreeWidgetItem import childCount [as 别名]
#.........这里部分代码省略.........
text = _('String not found')
else:
text_matches = _('matches in')
text_files = _('file')
if nb_files > 1:
text_files += 's'
text = "%d %s %d %s" % (self.nb, text_matches,
nb_files, text_files)
if self.error_flag:
text += ' (' + self.error_flag + ')'
elif self.results is not None and not self.completed:
text += ' (' + _('interrupted') + ')'
self.set_title(title+text)
self.clear()
self.data = {}
if not self.results: # First search interrupted *or* No result
return
# Directory set
dir_set = set()
for filename in sorted(self.results.keys()):
dirname = osp.abspath(osp.dirname(filename))
dir_set.add(dirname)
# Root path
root_path_list = None
_common = get_common_path(list(dir_set))
if _common is not None:
root_path_list = [_common]
else:
_common = get_common_path(self.pathlist)
if _common is not None:
root_path_list = [_common]
else:
root_path_list = self.pathlist
if not root_path_list:
return
for _root_path in root_path_list:
dir_set.add(_root_path)
# Populating tree: directories
def create_dir_item(dirname, parent):
if dirname not in root_path_list:
displayed_name = osp.basename(dirname)
else:
displayed_name = dirname
item = QTreeWidgetItem(parent, [displayed_name],
QTreeWidgetItem.Type)
item.setIcon(0, ima.icon('DirClosedIcon'))
return item
dirs = {}
for dirname in sorted(list(dir_set)):
if dirname in root_path_list:
parent = self
else:
parent_dirname = abspardir(dirname)
parent = dirs.get(parent_dirname)
if parent is None:
# This is related to directories which contain found
# results only in some of their children directories
if osp.commonprefix([dirname]+root_path_list):
# create new root path
pass
items_to_create = []
while dirs.get(parent_dirname) is None:
items_to_create.append(parent_dirname)
parent_dirname = abspardir(parent_dirname)
items_to_create.reverse()
for item_dir in items_to_create:
item_parent = dirs[abspardir(item_dir)]
dirs[item_dir] = create_dir_item(item_dir, item_parent)
parent_dirname = abspardir(dirname)
parent = dirs[parent_dirname]
dirs[dirname] = create_dir_item(dirname, parent)
self.root_items = [dirs[_root_path] for _root_path in root_path_list]
# Populating tree: files
for filename in sorted(self.results.keys()):
parent_item = dirs[osp.dirname(filename)]
file_item = QTreeWidgetItem(parent_item, [osp.basename(filename)],
QTreeWidgetItem.Type)
file_item.setIcon(0, get_filetype_icon(filename))
colno_dict = {}
fname_res = []
for lineno, colno, line in self.results[filename]:
if lineno not in colno_dict:
fname_res.append((lineno, colno, line))
colno_dict[lineno] = colno_dict.get(lineno, [])+[str(colno)]
for lineno, colno, line in fname_res:
colno_str = ",".join(colno_dict[lineno])
item = QTreeWidgetItem(file_item,
["%d (%s): %s" % (lineno, colno_str, line.rstrip())],
QTreeWidgetItem.Type)
item.setIcon(0, ima.icon('arrow'))
self.data[id(item)] = (filename, lineno)
# Removing empty directories
top_level_items = [self.topLevelItem(index)
for index in range(self.topLevelItemCount())]
for item in top_level_items:
if not item.childCount():
self.takeTopLevelItem(self.indexOfTopLevelItem(item))