本文整理汇总了Python中PyQt4.Qt.QListWidgetItem.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidgetItem.setData方法的具体用法?Python QListWidgetItem.setData怎么用?Python QListWidgetItem.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QListWidgetItem
的用法示例。
在下文中一共展示了QListWidgetItem.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refill_all_boxes
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def refill_all_boxes(self):
if self.refilling:
return
self.refilling = True
self.current_device = None
self.current_format = None
self.clear_fields(new_boxes=True)
self.edit_format.clear()
self.edit_format.addItem('')
for format_ in self.current_plugboards:
self.edit_format.addItem(format_)
self.edit_format.setCurrentIndex(0)
self.edit_device.clear()
self.ok_button.setEnabled(False)
self.del_button.setEnabled(False)
self.existing_plugboards.clear()
for f in self.formats:
if f not in self.current_plugboards:
continue
for d in self.devices:
if d not in self.current_plugboards[f]:
continue
ops = []
for op in self.current_plugboards[f][d]:
ops.append('([' + op[0] + '] -> ' + op[1] + ')')
txt = '%s:%s = %s\n'%(f, d, ', '.join(ops))
item = QListWidgetItem(txt)
item.setData(Qt.UserRole, (f, d))
self.existing_plugboards.addItem(item)
self.refilling = False
示例2: _display_issues
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def _display_issues(self):
self.values_list.clear()
issues = self.mm.get_all_issues(True)
for id, issue in issues:
item = QListWidgetItem(get_icon('images/books.png'), issue, self.values_list)
item.setData(1, (id,))
self.values_list.addItem(item)
示例3: __init__
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def __init__(self, parent, duplicates, loc):
QDialog.__init__(self, parent)
l = QVBoxLayout()
self.setLayout(l)
self.la = la = QLabel(_('Books with the same title and author as the following already exist in the library %s.'
' Select which books you want copied anyway.') %
os.path.basename(loc))
la.setWordWrap(True)
l.addWidget(la)
self.setWindowTitle(_('Duplicate books'))
self.books = QListWidget(self)
self.items = []
for book_id, (title, authors) in duplicates.iteritems():
i = QListWidgetItem(_('{0} by {1}').format(title, ' & '.join(authors[:3])), self.books)
i.setData(Qt.UserRole, book_id)
i.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
i.setCheckState(Qt.Checked)
self.items.append(i)
l.addWidget(self.books)
self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
bb.accepted.connect(self.accept)
bb.rejected.connect(self.reject)
self.a = b = bb.addButton(_('Select &all'), bb.ActionRole)
b.clicked.connect(self.select_all), b.setIcon(QIcon(I('plus.png')))
self.n = b = bb.addButton(_('Select &none'), bb.ActionRole)
b.clicked.connect(self.select_none), b.setIcon(QIcon(I('minus.png')))
self.ctc = b = bb.addButton(_('&Copy to clipboard'), bb.ActionRole)
b.clicked.connect(self.copy_to_clipboard), b.setIcon(QIcon(I('edit-copy.png')))
l.addWidget(bb)
self.resize(600, 400)
示例4: add_builtin_recipe
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def add_builtin_recipe(self):
from calibre.web.feeds.recipes.collection import \
get_builtin_recipe_collection, get_builtin_recipe_by_id
from PyQt4.Qt import QDialog, QVBoxLayout, QListWidgetItem, \
QListWidget, QDialogButtonBox, QSize
d = QDialog(self)
d.l = QVBoxLayout()
d.setLayout(d.l)
d.list = QListWidget(d)
d.list.doubleClicked.connect(lambda x: d.accept())
d.l.addWidget(d.list)
d.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel,
Qt.Horizontal, d)
d.bb.accepted.connect(d.accept)
d.bb.rejected.connect(d.reject)
d.l.addWidget(d.bb)
d.setWindowTitle(_('Choose builtin recipe'))
items = []
for r in get_builtin_recipe_collection():
id_ = r.get('id', '')
title = r.get('title', '')
lang = r.get('language', '')
if id_ and title:
items.append((title + ' [%s]'%lang, id_))
items.sort(key=lambda x:sort_key(x[0]))
for title, id_ in items:
item = QListWidgetItem(title)
item.setData(Qt.UserRole, id_)
d.list.addItem(item)
d.resize(QSize(450, 400))
ret = d.exec_()
d.list.doubleClicked.disconnect()
if ret != d.Accepted:
return
items = list(d.list.selectedItems())
if not items:
return
item = items[-1]
id_ = unicode(item.data(Qt.UserRole).toString())
title = unicode(item.data(Qt.DisplayRole).toString()).rpartition(' [')[0]
profile = get_builtin_recipe_by_id(id_, download_recipe=True)
if profile is None:
raise Exception('Something weird happened')
if self._model.has_title(title):
if question_dialog(self, _('Replace recipe?'),
_('A custom recipe named %s already exists. Do you want to '
'replace it?')%title):
self._model.replace_by_title(title, profile)
else:
return
else:
self.model.add(title, profile)
self.clear()
示例5: create_item
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def create_item(self, data):
x = data
i = QListWidgetItem(
QIcon(QPixmap(x["path"]).scaled(256, 256, transformMode=Qt.SmoothTransformation)), x["name"], self.images
)
i.setData(Qt.UserRole, x["fname"])
i.setData(Qt.UserRole + 1, x["path"])
return i
示例6: to_item
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def to_item(key, ac, parent):
ic = ac.icon()
if not ic or ic.isNull():
ic = blank
ans = QListWidgetItem(ic, unicode(ac.text()).replace('&', ''), parent)
ans.setData(Qt.UserRole, key)
ans.setToolTip(ac.toolTip())
return ans
示例7: _display_choices
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def _display_choices(self):
self.values_list.clear()
choices = self.mm.search(self.mi.title)
if choices is None or len(choices)==0:
item = QListWidgetItem(get_icon('images/books.png'), _('there seem to be no matches'), self.values_list)
self.values_list.addItem(item)
for id, name in choices.items():
item = QListWidgetItem(get_icon('images/books.png'), name, self.values_list)
item.setData(1, (id,))
self.values_list.addItem(item)
示例8: initialize
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def initialize(self):
self.devices.blockSignals(True)
self.devices.clear()
for dev in self.gui.device_manager.devices:
for d, name in dev.get_user_blacklisted_devices().iteritems():
item = QListWidgetItem('%s [%s]'%(name, d), self.devices)
item.setData(Qt.UserRole, (dev, d))
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable)
item.setCheckState(Qt.Checked)
self.devices.blockSignals(False)
示例9: _display_formats
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def _display_formats(self):
self.values_list.clear()
formats = self.dm.get_download_info(self.casanova_id)
if isinstance(formats, list):
for format in formats:
item = QListWidgetItem(get_icon('images/books.png'), format['type'], self.values_list)
item.setData(1, (format,))
self.values_list.addItem(item)
else:
return error_dialog(self.gui, 'Casanova message', unicode(formats), show=True)
示例10: build_dictionaries
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def build_dictionaries(self, current=None):
self.dictionaries.clear()
for dic in sorted(dictionaries.all_user_dictionaries, key=lambda d:sort_key(d.name)):
i = QListWidgetItem(dic.name, self.dictionaries)
i.setData(Qt.UserRole, dic)
if dic.is_active:
i.setData(Qt.FontRole, self.emph_font)
if current == dic.name:
self.dictionaries.setCurrentItem(i)
if current is None and self.dictionaries.count() > 0:
self.dictionaries.setCurrentRow(0)
示例11: set_bookmarks
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def set_bookmarks(self, bookmarks=None):
if bookmarks is None:
bookmarks = self.original_bookmarks
self.bookmarks_list.clear()
for bm in bookmarks:
i = QListWidgetItem(bm['title'])
i.setData(Qt.UserRole, self.bm_to_item(bm))
i.setFlags(i.flags() | Qt.ItemIsEditable)
self.bookmarks_list.addItem(i)
if len(bookmarks) > 0:
self.bookmarks_list.setCurrentItem(self.bookmarks_list.item(0), QItemSelectionModel.ClearAndSelect)
示例12: show_current_dictionary
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def show_current_dictionary(self, *args):
d = self.current_dictionary
if d is None:
return
self.dlabel.setText(_('Configure the dictionary: <b>%s') % d.name)
self.is_active.blockSignals(True)
self.is_active.setChecked(d.is_active)
self.is_active.blockSignals(False)
self.words.clear()
for word, lang in sorted(d.words, key=lambda x:sort_key(x[0])):
i = QListWidgetItem('%s [%s]' % (word, get_language(lang)), self.words)
i.setData(Qt.UserRole, (word, lang))
示例13: init_input_order
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def init_input_order(self, defaults=False):
if defaults:
input_map = prefs.defaults['input_format_order']
else:
input_map = prefs['input_format_order']
all_formats = set()
self.opt_input_order.clear()
for fmt in all_input_formats().union(set(['ZIP', 'RAR'])):
all_formats.add(fmt.upper())
for format in input_map + list(all_formats.difference(input_map)):
item = QListWidgetItem(format, self.opt_input_order)
item.setData(Qt.UserRole, QVariant(format))
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
示例14: run
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def run(self):
for file in self.files:
if(self._fnameInCollection(file)):
self.emit(SIGNAL('logMessage'), "File {0} is already in test collection".format(os.path.basename(file)))
else:
item = QListWidgetItem(os.path.basename(file))
tc = TestCase(os.path.basename(file),file)
item.setData(Qt.UserRole, tc)
self.emit(SIGNAL('addItemToList'), item)
self.emit(SIGNAL('logMessage'), "Added file {0}".format(os.path.basename(file)))
self.parserHelper.parseListItem(item)
self.emit(SIGNAL('setItemIcon'), item, tc.status)
self.emit(SIGNAL('sortListAndUpdateButtons'))
示例15: run_checks
# 需要导入模块: from PyQt4.Qt import QListWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QListWidgetItem import setData [as 别名]
def run_checks(self, container):
with BusyCursor():
self.show_busy()
QApplication.processEvents()
errors = run_checks(container)
self.hide_busy()
for err in sorted(errors, key=lambda e:(100 - e.level, e.name)):
i = QListWidgetItem('%s\xa0\xa0\xa0\xa0[%s]' % (err.msg, err.name), self.items)
i.setData(Qt.UserRole, err)
i.setIcon(icon_for_level(err.level))
if errors:
self.items.setCurrentRow(0)
self.current_item_changed()
self.items.setFocus(Qt.OtherFocusReason)
else:
self.clear_help(_('No problems found'))