本文整理汇总了Python中spyderlib.qt.QtGui.QListWidget.addItem方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.addItem方法的具体用法?Python QListWidget.addItem怎么用?Python QListWidget.addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QListWidget
的用法示例。
在下文中一共展示了QListWidget.addItem方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileSwitcher
# 需要导入模块: from spyderlib.qt.QtGui import QListWidget [as 别名]
# 或者: from spyderlib.qt.QtGui.QListWidget import addItem [as 别名]
#.........这里部分代码省略.........
# Get optional line number
if trying_for_line_number:
filter_text, line_number = filter_text.split(':')
else:
line_number = None
# Get all available filenames and get the scores for "fuzzy" matching
scores = get_search_scores(filter_text, self.filenames,
template="<b>{0}</b>")
# 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):
示例2: RateLawWidget
# 需要导入模块: from spyderlib.qt.QtGui import QListWidget [as 别名]
# 或者: from spyderlib.qt.QtGui.QListWidget import addItem [as 别名]
class RateLawWidget(QWidget):
"""
Rate Law widget
"""
def __init__(self, parent, max_entries=100):
""" Creates a very basic window with some text """
"""
RATE_LAW_MESSAGE = \
"The Plugins for Spyder consists out of three main classes: \n\n" \
"1. HelloWorld\n\n" \
"\tThe HelloWorld class inherits all its methods from\n" \
"\tSpyderPluginMixin and the HelloWorldWidget and performs all\n" \
"\tthe processing required by the GU. \n\n" \
"2. HelloWorldConfigPage\n\n" \
"\tThe HelloWorldConfig class inherits all its methods from\n" \
"\tPluginConfigPage to create a configuration page that can be\n" \
"\tfound under Tools -> Preferences\n\n" \
"3. HelloWorldWidget\n\n" \
"\tThe HelloWorldWidget class inherits all its methods from\n" \
"\tQWidget to create the actual plugin GUI interface that \n" \
"\tdisplays this message on screen\n\n"
"""
#Testing access editor on plugin initialization
RATE_LAW_MESSAGE = ""
displaynamelist = []
#displaylist = []
infixlist = []
desclist = []
parameterstringlist = []
xmldoc = minidom.parse('\\.spyder2\\ratelaw2_0_3.xml')
#xmldoc = minidom.parse('%\\Downloads\\ratelaw2_0_3.xml')
lawlistxml = xmldoc.getElementsByTagName('law')
#i is the number of laws currently in the xml file
i = 0
for s in lawlistxml:
#RATE_LAW_MESSAGE += s.getAttribute('displayName') + "\n"
RATE_LAW_MESSAGE += s.getAttribute('display') + "\n"
#displaynamelist[i] = s.getAttribute('displayName')
#displaylist[i] = s.getAttribute('display')
displaynamelist.append(s.getAttribute('displayName'))
#displaylist.append(s.getAttribute('display'))
infixlist.append(s.getAttribute('infixExpression'))
desclist.append(s.getAttribute('description'))
parameterlist = s.getElementsByTagName('listOfParameters')[0]
#for p in parameterlist
parameters = parameterlist.getElementsByTagName('parameter')
parameterstring = ""
for param in parameters:
parametername = param.attributes['name'].value
parameterdesc = param.attributes['description'].value
parameterstring = parameterstring + '\t' + parametername + ":" + '\t' + " " + parameterdesc + "\n"
#print('\t' + parametername + ":" + '\t' + parameterdesc)
parameterstringlist.append(parameterstring)
i = i + 1
QWidget.__init__(self, parent)
self.setWindowTitle("Rate Law Library")
self.output = None
self.error_output = None
self._last_wdir = None
self._last_args = None
self._last_pythonpath = None
self.textlabel = QLabel(RATE_LAW_MESSAGE)
self.lawlist = QListWidget()
self.lawpage = QStackedWidget()
#Adding displayName items to lawlist
for j in range(i):
item = QListWidgetItem(displaynamelist[j])
self.lawlist.addItem(item)
self.lawdetailpage = QWidget()
# Page layout will become its own function
setup_group = QGroupBox(displaynamelist[j])
infixmod = infixlist[j].replace("___"," ")
setup_label = QLabel(infixmod)
setup_label.setWordWrap(True)
desc_group = QGroupBox("Description")
desc_label = QLabel(desclist[j])
desc_label.setWordWrap(True)
param_label = QLabel(parameterstringlist[j])
param_label.setWordWrap(True)
# Warning: do not try to regroup the following QLabel contents with
# widgets above -- this string was isolated here in a single QLabel
# on purpose: to fix Issue 863
setup_layout = QVBoxLayout()
setup_layout.addWidget(setup_label)
setup_group.setLayout(setup_layout)
desc_layout = QVBoxLayout()
#.........这里部分代码省略.........
示例3: PathManager
# 需要导入模块: from spyderlib.qt.QtGui import QListWidget [as 别名]
# 或者: from spyderlib.qt.QtGui.QListWidget import addItem [as 别名]
#.........这里部分代码省略.........
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)
item.setIcon(get_std_icon('DirClosedIcon'))
if name in self.ro_pathlist:
item.setFlags(Qt.NoItemFlags)
self.listwidget.addItem(item)
self.refresh()
def refresh(self, row=None):
"""Refresh widget"""
for widget in self.selection_widgets:
widget.setEnabled(self.listwidget.currentItem() is not None)
not_empty = self.listwidget.count() > 0
if self.sync_button is not None:
self.sync_button.setEnabled(not_empty)
def move_to(self, absolute=None, relative=None):
index = self.listwidget.currentRow()
if absolute is not None:
if absolute:
new_index = len(self.pathlist)-1
else:
new_index = 0
else:
new_index = index + relative
new_index = max(0, min(len(self.pathlist)-1, new_index))
path = self.pathlist.pop(index)
self.pathlist.insert(new_index, path)
self.update_list()
self.listwidget.setCurrentRow(new_index)
def remove_path(self):
answer = QMessageBox.warning(self, _("Remove path"),
_("Do you really want to remove selected path?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
self.pathlist.pop(self.listwidget.currentRow())
self.update_list()
def add_path(self):
self.emit(SIGNAL('redirect_stdio(bool)'), False)
directory = getexistingdirectory(self, _("Select directory"),
self.last_path)
self.emit(SIGNAL('redirect_stdio(bool)'), True)
if directory:
directory = osp.abspath(directory)
self.last_path = directory
if directory in self.pathlist:
answer = QMessageBox.question(self, _("Add path"),
_("This directory is already included in Spyder path "
"list.<br>Do you want to move it to the top of "
"the list?"),
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.Yes:
self.pathlist.remove(directory)
else:
return
self.pathlist.insert(0, directory)
self.update_list()
示例4: RateLawWidget
# 需要导入模块: from spyderlib.qt.QtGui import QListWidget [as 别名]
# 或者: from spyderlib.qt.QtGui.QListWidget import addItem [as 别名]
class RateLawWidget(QWidget):
"""
Rate Law widget
"""
def __init__(self, parent, max_entries=100):
"Initialize Various list objects before assignment"
displaylist = []
displaynamelist = []
infixmod = []
infixlist = []
desclist = []
parameternamelist = []
parameterdesclist = []
parameterstringlist = []
paramcountlist = []
buttonlist = []
xmldoc = minidom.parse('C:\\Users\\Jayit\\.spyder2\\ratelaw2_0_3.xml')
#xmldoc = minidom.parse('%\\Downloads\\ratelaw2_0_3.xml')
lawlistxml = xmldoc.getElementsByTagName('law')
o = 0
for s in lawlistxml:
o = o + 1
parameternamelistlist = [0 for x in range(o)]
parameterdesclistlist = [0 for x in range(o)]
"""i is the number of laws currently in the xml file"""
i = 0
"""
Parsing xml: Acquiring rate law name, description, and list of parameter information
"""
for s in lawlistxml:
#RATE_LAW_MESSAGE += s.getAttribute('displayName') + "\n"
"""Gets Latec Expression"""
displaylist.append(s.getAttribute('display'))
"""Gets Rate-Law Name"""
displaynamelist.append(s.getAttribute('displayName'))
""""Gets Raw Rate-Law expression"""
infixlist.append(s.getAttribute('infixExpression'))
"""Gets description statement"""
desclist.append(s.getAttribute('description'))
"""Gets listOfParameters Object"""
parameterlist = s.getElementsByTagName('listOfParameters')[0]
"""Gets a list of parameters within ListOfParameters object"""
parameters = parameterlist.getElementsByTagName('parameter')
for param in parameters:
parameternamelist.append(param.attributes['name'].value)
#print(param.attributes['name'].value)
parameterdesclist.append(param.attributes['description'].value)
parameternamelistlist[i] = parameternamelist
#print("break")
parameterdesclistlist[i] = parameterdesclist
parameternamelist = []
parameterdesclist = []
i = i + 1
SLElistlist = [ 0 for x in range(i)]
PLElistlist = [ 0 for x in range(i)]
ILElistlist = [ 0 for x in range(i)]
paramLElistlist = [ 0 for x in range(i)]
numlistlist = [ 0 for x in range(i)]
QWidget.__init__(self, parent)
self.setWindowTitle("Rate Law Library")
self.output = None
self.error_output = None
self._last_wdir = None
self._last_args = None
self._last_pythonpath = None
#self.textlabel = QLabel(RATE_LAW_MESSAGE)
self.lawlist = QListWidget()
self.lawpage = QStackedWidget()
index = 0
for j in range(i):
item = QListWidgetItem(displaynamelist[j])
self.lawlist.addItem(item)
self.lawdetailpage = QWidget()
setup_group = QGroupBox(displaynamelist[j])
infixmod.append(infixlist[j].replace("___"," "))
#.........这里部分代码省略.........