本文整理汇总了Python中spyderlib.qt.QtGui.QTreeWidgetItem类的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem类的具体用法?Python QTreeWidgetItem怎么用?Python QTreeWidgetItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTreeWidgetItem类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_dir_item
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
示例2: populate_classes
def populate_classes(self):
"""Populate classes"""
self.lines = {}
for lineno, c_name, methods in self.classes:
item = QTreeWidgetItem(self, [c_name], QTreeWidgetItem.Type)
self.lines[item] = lineno
if methods is None:
item.setIcon(0, get_icon('function.png'))
else:
item.setIcon(0, get_icon('class.png'))
if methods:
self.populate_methods(item, c_name, methods)
示例3: populate_methods
def populate_methods(self, parent, c_name, methods):
"""Populate methods"""
for lineno, m_name in methods:
decorator = m_name.startswith('@')
if decorator:
m_name = m_name[1:]
item = QTreeWidgetItem(parent, [m_name], QTreeWidgetItem.Type)
self.lines[item] = lineno
if m_name.startswith('__'):
item.setIcon(0, get_icon('private2.png'))
elif m_name.startswith('_'):
item.setIcon(0, get_icon('private1.png'))
elif decorator:
item.setIcon(0, get_icon('decorator.png'))
else:
item.setIcon(0, get_icon('method.png'))
示例4: __init__
def __init__(self, name, line, parent, preceding):
if preceding is None:
QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
else:
if preceding is not parent:
# Preceding must be either the same as item's parent
# or have the same parent as item
while preceding.parent() is not parent:
preceding = preceding.parent()
if preceding is None:
break
if preceding is None:
QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
else:
QTreeWidgetItem.__init__(self, parent, preceding, QTreeWidgetItem.Type)
self.setText(0, name)
parent_text = from_qvariant(parent.data(0, Qt.UserRole), to_text_string)
set_item_user_text(self, parent_text + "/" + name)
self.line = line
示例5: __init__
def __init__(self, path, treewidget):
QTreeWidgetItem.__init__(self, treewidget, QTreeWidgetItem.Type)
self.path = path
self.setIcon(0, get_icon('python.png'))
self.setToolTip(0, path)
set_item_user_text(self, path)
示例6: refresh
def refresh(self):
"""
Refreshing search results panel
"""
title = "'%s' - " % self.search_text
if self.results is None:
text = _('Search canceled')
else:
nb_files = len(self.results)
if nb_files == 0:
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,
#.........这里部分代码省略.........
示例7: populate_tree
def populate_tree(self, parentItem, children_list):
"""Recursive method to create each item (and associated data) in the tree."""
for child_key in children_list:
self.item_depth += 1
(filename, line_number, function_name, file_and_line, node_type
) = self.function_info(child_key)
(primcalls, total_calls, loc_time, cum_time, callers
) = self.stats[child_key]
child_item = QTreeWidgetItem(parentItem)
self.item_list.append(child_item)
self.set_item_data(child_item, filename, line_number)
# FIXME: indexes to data should be defined by a dictionary on init
child_item.setToolTip(0, 'Function or module name')
child_item.setData(0, Qt.DisplayRole, function_name)
child_item.setIcon(0, get_icon(self.icon_list[node_type]))
child_item.setToolTip(1, _('Time in function '\
'(including sub-functions)'))
#child_item.setData(1, Qt.DisplayRole, cum_time)
child_item.setData(1, Qt.DisplayRole, '%.3f' % cum_time)
child_item.setTextAlignment(1, Qt.AlignCenter)
child_item.setToolTip(2, _('Local time in function '\
'(not in sub-functions)'))
#child_item.setData(2, Qt.DisplayRole, loc_time)
child_item.setData(2, Qt.DisplayRole, '%.3f' % loc_time)
child_item.setTextAlignment(2, Qt.AlignCenter)
child_item.setToolTip(3, _('Total number of calls '\
'(including recursion)'))
child_item.setData(3, Qt.DisplayRole, total_calls)
child_item.setTextAlignment(3, Qt.AlignCenter)
child_item.setToolTip(4, _('File:line '\
'where function is defined'))
child_item.setData(4, Qt.DisplayRole, file_and_line)
#child_item.setExpanded(True)
if self.is_recursive(child_item):
child_item.setData(4, Qt.DisplayRole, '(%s)' % _('recursion'))
child_item.setDisabled(True)
else:
callees = self.find_callees(child_key)
if self.item_depth < 3:
self.populate_tree(child_item, callees)
elif callees:
child_item.setChildIndicatorPolicy(child_item.ShowIndicator)
self.items_to_be_shown[id(child_item)] = callees
self.item_depth -= 1
示例8: __init__
def __init__(self, parent=None):
QTreeWidgetItem.__init__(self, parent)
示例9: refresh
def refresh(self):
title = _('Results for ')+self.filename
self.set_title(title)
self.clear()
self.data = {}
# Populating tree
results = ((_('Convention'),
ima.icon('convention'), self.results['C:']),
(_('Refactor'),
ima.icon('refactor'), self.results['R:']),
(_('Warning'),
ima.icon('warning'), self.results['W:']),
(_('Error'),
ima.icon('error'), self.results['E:']))
for title, icon, messages in results:
title += ' (%d message%s)' % (len(messages),
's' if len(messages)>1 else '')
title_item = QTreeWidgetItem(self, [title], QTreeWidgetItem.Type)
title_item.setIcon(0, icon)
if not messages:
title_item.setDisabled(True)
modules = {}
for module, lineno, message, msg_id in messages:
basename = osp.splitext(osp.basename(self.filename))[0]
if not module.startswith(basename):
# Pylint bug
i_base = module.find(basename)
module = module[i_base:]
dirname = osp.dirname(self.filename)
if module.startswith('.') or module == basename:
modname = osp.join(dirname, module)
else:
modname = osp.join(dirname, *module.split('.'))
if osp.isdir(modname):
modname = osp.join(modname, '__init__')
for ext in ('.py', '.pyw'):
if osp.isfile(modname+ext):
modname = modname + ext
break
if osp.isdir(self.filename):
parent = modules.get(modname)
if parent is None:
item = QTreeWidgetItem(title_item, [module],
QTreeWidgetItem.Type)
item.setIcon(0, ima.icon('python'))
modules[modname] = item
parent = item
else:
parent = title_item
if len(msg_id) > 1:
text = "[%s] %d : %s" % (msg_id, lineno, message)
else:
text = "%d : %s" % (lineno, message)
msg_item = QTreeWidgetItem(parent, [text], QTreeWidgetItem.Type)
msg_item.setIcon(0, ima.icon('arrow'))
self.data[id(msg_item)] = (modname, lineno)
示例10: populate_tree
def populate_tree(self):
"""Create each item (and associated data) in the tree"""
if not self.stats:
warn_item = QTreeWidgetItem(self)
warn_item.setData(
0, Qt.DisplayRole,
_('No timings to display. '
'Did you forget to add @profile decorators ?')
.format(url=WEBSITE_URL))
warn_item.setFirstColumnSpanned(True)
warn_item.setTextAlignment(0, Qt.AlignCenter)
font = warn_item.font(0)
font.setStyle(QFont.StyleItalic)
warn_item.setFont(0, font)
return
try:
monospace_font = self.window().editor.get_plugin_font()
except AttributeError: # If run standalone for testing
monospace_font = QFont("Courier New")
monospace_font.setPointSize(10)
for func_info, func_data in self.stats.items():
# Function name and position
filename, start_line_no, func_name = func_info
func_stats, func_peak_usage = func_data
func_item = QTreeWidgetItem(self)
func_item.setData(
0, Qt.DisplayRole,
_('{func_name} (peak {peak_usage:.3f} MiB) in file "{filename}", '
'line {line_no}').format(
filename=filename,
line_no=start_line_no,
func_name=func_name,
peak_usage=func_peak_usage))
func_item.setFirstColumnSpanned(True)
func_item.setData(COL_POS, Qt.UserRole,
(osp.normpath(filename), start_line_no))
# For sorting by time
func_item.setData(COL_USAGE, Qt.DisplayRole, func_peak_usage)
func_item.setData(COL_INCREMENT, Qt.DisplayRole,
func_peak_usage)
if self.parent().use_colors:
# Choose deteministic unique color for the function
md5 = hashlib.md5((filename + func_name).encode("utf8")).hexdigest()
hue = (int(md5[:2], 16) - 68) % 360 # avoid blue (unreadable)
func_color = QColor.fromHsv(hue, 200, 255)
else:
# Red color only
func_color = QColor.fromRgb(255, 0, 0)
# get max increment
max_increment = 0
for line_info in func_stats:
(line_no, code_line, usage, increment) = line_info
if increment is not None:
max_increment = max(max_increment, increment)
# Lines of code
for line_info in func_stats:
line_item = QTreeWidgetItem(func_item)
(line_no, code_line, usage, increment) = line_info
self.fill_item(
line_item, filename, line_no, code_line,
usage, increment)
# Color background
if increment is not None:
alpha = increment / max_increment if max_increment != 0 else 0
color = QColor(func_color)
color.setAlphaF(alpha) # Returns None
color = QBrush(color)
for col in range(self.columnCount()):
line_item.setBackground(col, color)
else:
for col in range(self.columnCount()):
line_item.setForeground(col, CODE_NOT_RUN_COLOR)
# Monospace font for code
line_item.setFont(COL_LINE, monospace_font)
示例11: refresh
def refresh(self):
title = _("Results for ") + self.filename
self.set_title(title)
self.clear()
self.data = {}
# Populating tree
results = (
(_("Convention"), ima.icon("convention"), self.results["C:"]),
(_("Refactor"), ima.icon("refactor"), self.results["R:"]),
(_("Warning"), ima.icon("warning"), self.results["W:"]),
(_("Error"), ima.icon("error"), self.results["E:"]),
)
for title, icon, messages in results:
title += " (%d message%s)" % (len(messages), "s" if len(messages) > 1 else "")
title_item = QTreeWidgetItem(self, [title], QTreeWidgetItem.Type)
title_item.setIcon(0, icon)
if not messages:
title_item.setDisabled(True)
modules = {}
for module, lineno, message, msg_id in messages:
basename = osp.splitext(osp.basename(self.filename))[0]
if not module.startswith(basename):
# Pylint bug
i_base = module.find(basename)
module = module[i_base:]
dirname = osp.dirname(self.filename)
if module.startswith(".") or module == basename:
modname = osp.join(dirname, module)
else:
modname = osp.join(dirname, *module.split("."))
if osp.isdir(modname):
modname = osp.join(modname, "__init__")
for ext in (".py", ".pyw"):
if osp.isfile(modname + ext):
modname = modname + ext
break
if osp.isdir(self.filename):
parent = modules.get(modname)
if parent is None:
item = QTreeWidgetItem(title_item, [module], QTreeWidgetItem.Type)
item.setIcon(0, ima.icon("python"))
modules[modname] = item
parent = item
else:
parent = title_item
if len(msg_id) > 1:
text = "[%s] %d : %s" % (msg_id, lineno, message)
else:
text = "%d : %s" % (lineno, message)
msg_item = QTreeWidgetItem(parent, [text], QTreeWidgetItem.Type)
msg_item.setIcon(0, ima.icon("arrow"))
self.data[id(msg_item)] = (modname, lineno)