本文整理汇总了Python中spyderlib.qt.QtGui.QListWidget.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.clear方法的具体用法?Python QListWidget.clear怎么用?Python QListWidget.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QListWidget
的用法示例。
在下文中一共展示了QListWidget.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileSwitcher
# 需要导入模块: from spyderlib.qt.QtGui import QListWidget [as 别名]
# 或者: from spyderlib.qt.QtGui.QListWidget import clear [as 别名]
#.........这里部分代码省略.........
# Build the text that will appear on the list widget
for index, score in enumerate(scores):
text, rich_text, score_value = score
if score_value != -1:
text_item = '<big>' + rich_text + '</big>'
if trying_for_line_number:
text_item += " [{0:} {1:}]".format(self.line_count[index],
_("lines"))
text_item += "<br><i>{0:}</i>".format(
short_paths[index])
results.append((score_value, index, text_item))
# Sort the obtained scores and populate the list widget
self.filtered_path = []
for result in sorted(results):
index = result[1]
text = result[-1]
path = paths[index]
item = QListWidgetItem(self.tabs.tabIcon(index), text)
item.setToolTip(path)
item.setSizeHint(QSize(0, 25))
self.list.addItem(item)
self.filtered_path.append(path)
# Move selected item in list accordingly and update list size
if current_path in self.filtered_path:
self.set_current_row(self.filtered_path.index(current_path))
elif self.filtered_path:
self.set_current_row(0)
self.fix_size(short_paths)
# If a line number is searched look for it
self.line_number = line_number
self.goto_line(line_number)
def setup_symbol_list(self, filter_text, current_path):
"""Setup list widget content for symbol list display."""
# Get optional symbol name
filter_text, symbol_text = filter_text.split('@')
# Fetch the Outline explorer data, get the icons and values
oedata = self.get_symbol_list()
icons = get_python_symbol_icons(oedata)
symbol_list = process_python_symbol_data(oedata)
line_fold_token = [(item[0], item[2], item[3]) for item in symbol_list]
choices = [item[1] for item in symbol_list]
scores = get_search_scores(symbol_text, choices, template="<b>{0}</b>")
# Build the text that will appear on the list widget
results = []
lines = []
self.filtered_symbol_lines = []
for index, score in enumerate(scores):
text, rich_text, score_value = score
line, fold_level, token = line_fold_token[index]
lines.append(text)
if score_value != -1:
results.append((score_value, line, text, rich_text,
fold_level, icons[index], token))
template_1 = '<code>{0}<big>{1} {2}</big></code>'
template_2 = '<br><code>{0}</code><i>[Line {1}]</i>'
for (score, line, text, rich_text, fold_level, icon,
token) in sorted(results):
fold_space = ' '*(fold_level)
line_number = line + 1
self.filtered_symbol_lines.append(line_number)
textline = template_1.format(fold_space, token, rich_text)
textline += template_2.format(fold_space, line_number)
item = QListWidgetItem(icon, textline)
item.setSizeHint(QSize(0, 16))
self.list.addItem(item)
# Move selected item in list accordingly and update list size
self.set_current_row(0)
self.fix_size(lines, extra=125)
def setup(self):
"""Setup list widget content."""
if not self.tabs.count():
self.close()
return
self.list.clear()
current_path = self.current_path
filter_text = self.filter_text
# Get optional line or symbol to define mode and method handler
trying_for_symbol = ('@' in self.filter_text)
if trying_for_symbol:
self.mode = self.SYMBOL_MODE
self.setup_symbol_list(filter_text, current_path)
else:
self.mode = self.FILE_MODE
self.setup_file_list(filter_text, current_path)
示例2: PathManager
# 需要导入模块: from spyderlib.qt.QtGui import QListWidget [as 别名]
# 或者: from spyderlib.qt.QtGui.QListWidget import clear [as 别名]
#.........这里部分代码省略.........
add_button = create_toolbutton(self, text=_("Add path"),
icon=get_icon('edit_add.png'),
triggered=self.add_path,
text_beside_icon=True)
toolbar.append(add_button)
remove_button = create_toolbutton(self, text=_("Remove path"),
icon=get_icon('edit_remove.png'),
triggered=self.remove_path,
text_beside_icon=True)
toolbar.append(remove_button)
self.selection_widgets.append(remove_button)
self._add_widgets_to_layout(layout, toolbar)
layout.addStretch(1)
if os.name == 'nt' and sync:
self.sync_button = create_toolbutton(self,
text=_("Synchronize..."),
icon=get_icon('synchronize.png'), triggered=self.synchronize,
tip=_("Synchronize Spyder's path list with PYTHONPATH "
"environment variable"),
text_beside_icon=True)
layout.addWidget(self.sync_button)
return toolbar
def synchronize(self):
"""
Synchronize Spyder's path list with PYTHONPATH environment variable
Only apply to: current user, on Windows platforms
"""
answer = QMessageBox.question(self, _("Synchronize"),
_("This will synchronize Spyder's path list with "
"<b>PYTHONPATH</b> environment variable for current user, "
"allowing you to run your Python modules outside Spyder "
"without having to configure sys.path. "
"<br>Do you want to clear contents of PYTHONPATH before "
"adding Spyder's path list?"),
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
if answer == QMessageBox.Cancel:
return
elif answer == QMessageBox.Yes:
remove = True
else:
remove = False
from spyderlib.utils.environ import (get_user_env, set_user_env,
listdict2envdict)
env = get_user_env()
if remove:
ppath = self.pathlist+self.ro_pathlist
else:
ppath = env.get('PYTHONPATH', [])
if not isinstance(ppath, list):
ppath = [ppath]
ppath = [path for path in ppath
if path not in (self.pathlist+self.ro_pathlist)]
ppath.extend(self.pathlist+self.ro_pathlist)
env['PYTHONPATH'] = ppath
set_user_env( listdict2envdict(env), parent=self )
def get_path_list(self):
"""Return path list (does not include the read-only path list)"""
return self.pathlist
def update_list(self):
"""Update path list"""
self.listwidget.clear()
for name in self.pathlist+self.ro_pathlist:
item = QListWidgetItem(name)