本文整理汇总了Python中PyQt4.Qt.QListWidget.setSelectionMode方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.setSelectionMode方法的具体用法?Python QListWidget.setSelectionMode怎么用?Python QListWidget.setSelectionMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QListWidget
的用法示例。
在下文中一共展示了QListWidget.setSelectionMode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SelectNames
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class SelectNames(QDialog): # {{{
def __init__(self, names, txt, parent=None):
QDialog.__init__(self, parent)
self.l = l = QVBoxLayout(self)
self.setLayout(l)
self.la = la = QLabel(_("Create a Virtual Library based on %s") % txt)
l.addWidget(la)
self._names = QListWidget(self)
self._names.addItems(QStringList(sorted(names, key=sort_key)))
self._names.setSelectionMode(self._names.ExtendedSelection)
l.addWidget(self._names)
self._or = QRadioButton(_("Match any of the selected %s names") % txt)
self._and = QRadioButton(_("Match all of the selected %s names") % txt)
self._or.setChecked(True)
l.addWidget(self._or)
l.addWidget(self._and)
self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
l.addWidget(self.bb)
self.resize(self.sizeHint())
@property
def names(self):
for item in self._names.selectedItems():
yield unicode(item.data(Qt.DisplayRole).toString())
@property
def match_type(self):
return " and " if self._and.isChecked() else " or "
示例2: AddBookDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class AddBookDialog(SizePersistedDialog):
def __init__(self, parent=None, mm=None, mi = None):
SizePersistedDialog.__init__(self, parent, 'casanova plugin:add book dialog')
self.setWindowTitle('Add text to Casanova:')
self.gui = parent
self.mm = mm
self.mi = mi
self.one_line_description = ''
layout = QVBoxLayout(self)
self.setLayout(layout)
self.one_liner_label = QLabel('Enter a short description (255 chars max) before pressing OK')
layout.addWidget(self.one_liner_label)
self.one_liner_str = QLineEdit(self)
self.one_liner_str.setText('')
layout.addWidget(self.one_liner_str)
self.one_liner_label.setBuddy(self.one_liner_str)
self.values_label = QLabel('Below are potential matches of texts that already exist - please make sure you are adding something new')
layout.addWidget(self.values_label)
self.values_list = QListWidget(self)
self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
layout.addWidget(self.values_list)
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self._accept_clicked)
self.button_box.rejected.connect(self.reject)
layout.addWidget(self.button_box)
self._display_choices()
# Cause our dialog size to be restored from prefs or created on first usage
self.resize_dialog()
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)
def _accept_clicked(self):
#self._save_preferences()
one_liner = unicode(self.one_liner_str.text())
if one_liner=='':
self.values_list.clear()
item = QListWidgetItem(get_icon('images/books.png'), _('you need to enter a short description'), self.values_list)
self.values_list.addItem(item)
else:
self.one_line_description = one_liner
self.accept()
示例3: PrefsViewerDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class PrefsViewerDialog(SizePersistedDialog):
def __init__(self, gui, namespace):
SizePersistedDialog.__init__(self, gui, 'Prefs Viewer dialog')
self.setWindowTitle('Preferences for: '+namespace)
self.db = gui.current_db
self.namespace = namespace
self._init_controls()
self.resize_dialog()
self._populate_settings()
if self.keys_list.count():
self.keys_list.setCurrentRow(0)
def _init_controls(self):
layout = QVBoxLayout(self)
self.setLayout(layout)
ml = QHBoxLayout()
layout.addLayout(ml, 1)
self.keys_list = QListWidget(self)
self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection)
self.keys_list.setFixedWidth(150)
self.keys_list.setAlternatingRowColors(True)
ml.addWidget(self.keys_list)
self.value_text = QTextEdit(self)
self.value_text.setTabStopWidth(24)
self.value_text.setReadOnly(True)
ml.addWidget(self.value_text, 1)
button_box = QDialogButtonBox(QDialogButtonBox.Ok)
button_box.accepted.connect(self.accept)
button_box.setCenterButtons(True)
layout.addWidget(button_box)
def _populate_settings(self):
self.keys_list.clear()
ns_prefix = 'namespaced:%s:'% self.namespace
keys = sorted([k[len(ns_prefix):] for k in self.db.prefs.iterkeys()
if k.startswith(ns_prefix)])
for key in keys:
self.keys_list.addItem(key)
self.keys_list.setMinimumWidth(self.keys_list.sizeHintForColumn(0))
self.keys_list.currentRowChanged[int].connect(self._current_row_changed)
def _current_row_changed(self, new_row):
if new_row < 0:
self.value_text.clear()
return
key = unicode(self.keys_list.currentItem().text())
val = self.db.prefs.get_namespaced(self.namespace, key, '')
self.value_text.setPlainText(self.db.prefs.to_raw(val))
示例4: SearchDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class SearchDialog(SizePersistedDialog):
def __init__(self, parent=None, mm=None):
SizePersistedDialog.__init__(self, parent, 'casanova plugin:search dialog')
self.setWindowTitle('Search Casanova:')
self.gui = parent
self.mm = mm
layout = QVBoxLayout(self)
self.setLayout(layout)
self.search_label = QLabel('Search for:')
layout.addWidget(self.search_label)
self.search_str = QLineEdit(self)
self.search_str.setText('')
layout.addWidget(self.search_str)
self.search_label.setBuddy(self.search_str)
self.find_button = QPushButton("&Find")
self.search_button_box = QDialogButtonBox(Qt.Horizontal)
self.search_button_box.addButton(self.find_button, QDialogButtonBox.ActionRole)
self.search_button_box.clicked.connect(self._find_clicked)
layout.addWidget(self.search_button_box)
self.values_list = QListWidget(self)
self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
layout.addWidget(self.values_list)
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self._accept_clicked)
self.button_box.rejected.connect(self.reject)
layout.addWidget(self.button_box)
# Cause our dialog size to be restored from prefs or created on first usage
self.resize_dialog()
def _display_choices(self, choices):
self.values_list.clear()
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)
def _find_clicked(self):
query = unicode(self.search_str.text())
self._display_choices(self.mm.search(query))
def _accept_clicked(self):
#self._save_preferences()
self.selected_texts = []
for item in self.values_list.selectedItems():
self.selected_texts.append(item.data(1).toPyObject()[0])
self.accept()
示例5: ChoosePluginToolbarsDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class ChoosePluginToolbarsDialog(QDialog):
def __init__(self, parent, plugin, locations):
QDialog.__init__(self, parent)
self.locations = locations
self.setWindowTitle(
_('Add "%s" to toolbars or menus')%plugin.name)
self._layout = QVBoxLayout(self)
self.setLayout(self._layout)
self._header_label = QLabel(
_('Select the toolbars and/or menus to add <b>%s</b> to:') %
plugin.name)
self._layout.addWidget(self._header_label)
self._locations_list = QListWidget(self)
self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
self._locations_list.setSizePolicy(sizePolicy)
for key, text in locations:
self._locations_list.addItem(text)
if key in {'toolbar', 'toolbar-device'}:
self._locations_list.item(self._locations_list.count()-1
).setSelected(True)
self._layout.addWidget(self._locations_list)
self._footer_label = QLabel(
_('You can also customise the plugin locations '
'using <b>Preferences -> Customise the toolbar</b>'))
self._layout.addWidget(self._footer_label)
button_box = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
self._layout.addWidget(button_box)
self.resize(self.sizeHint())
def selected_locations(self):
selected = []
for row in self._locations_list.selectionModel().selectedRows():
selected.append(self.locations[row.row()])
return selected
示例6: SelectTagsDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class SelectTagsDialog(QDialog):
def __init__(self, parent, modal=True, flags=Qt.WindowFlags(), caption="Select Tags", ok_button="Select"):
QDialog.__init__(self, parent, flags)
self.setModal(modal)
self.setWindowTitle(caption)
lo = QVBoxLayout(self)
lo.setMargin(10)
lo.setSpacing(5)
# tag selector
self.wtagsel = QListWidget(self)
lo.addWidget(self.wtagsel)
# self.wtagsel.setColumnMode(QListBox.FitToWidth)
self.wtagsel.setSelectionMode(QListWidget.MultiSelection)
QObject.connect(self.wtagsel, SIGNAL("itemSelectionChanged()"), self._check_tag)
# buttons
lo.addSpacing(10)
lo2 = QHBoxLayout()
lo.addLayout(lo2)
lo2.setContentsMargins(0, 0, 0, 0)
lo2.setMargin(5)
self.wokbtn = QPushButton(ok_button, self)
self.wokbtn.setMinimumWidth(128)
QObject.connect(self.wokbtn, SIGNAL("clicked()"), self.accept)
self.wokbtn.setEnabled(False)
cancelbtn = QPushButton("Cancel", self)
cancelbtn.setMinimumWidth(128)
QObject.connect(cancelbtn, SIGNAL("clicked()"), self.reject)
lo2.addWidget(self.wokbtn)
lo2.addStretch(1)
lo2.addWidget(cancelbtn)
self.setMinimumWidth(384)
self._tagnames = []
def setTags(self, tagnames):
self._tagnames = tagnames
self.wtagsel.clear()
self.wtagsel.insertItems(0, list(tagnames))
def _check_tag(self):
for i in range(len(self._tagnames)):
if self.wtagsel.item(i).isSelected():
self.wokbtn.setEnabled(True)
return
else:
self.wokbtn.setEnabled(False)
def getSelectedTags(self):
return [tag for i, tag in enumerate(self._tagnames) if self.wtagsel.item(i).isSelected()]
示例7: ChooseFormatToDownloadDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class ChooseFormatToDownloadDialog(SizePersistedDialog):
def __init__(self, parent=None, dm=None, casanova_id=None):
SizePersistedDialog.__init__(self, parent, 'casanova plugin:format download dialog')
self.setWindowTitle('Select format to download:')
self.gui = parent
self.dm = dm
self.casanova_id = casanova_id
layout = QVBoxLayout(self)
self.setLayout(layout)
self.values_list = QListWidget(self)
self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
layout.addWidget(self.values_list)
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self._accept_clicked)
self.button_box.rejected.connect(self.reject)
layout.addWidget(self.button_box)
self._display_formats()
# Cause our dialog size to be restored from prefs or created on first usage
self.resize_dialog()
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)
def _accept_clicked(self):
#self._save_preferences()
self.selected_format = None
for item in self.values_list.selectedItems():
self.selected_format = item.data(1).toPyObject()[0]
self.accept()
示例8: ChooseIssuesToUpdateDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class ChooseIssuesToUpdateDialog(SizePersistedDialog):
def __init__(self, parent=None, mm=None):
SizePersistedDialog.__init__(self, parent, 'casanova plugin:issues update dialog')
self.setWindowTitle('Select issues to update:')
self.gui = parent
self.mm = mm
layout = QVBoxLayout(self)
self.setLayout(layout)
self.values_list = QListWidget(self)
self.values_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
layout.addWidget(self.values_list)
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self._accept_clicked)
self.button_box.rejected.connect(self.reject)
layout.addWidget(self.button_box)
self._display_issues()
# Cause our dialog size to be restored from prefs or created on first usage
self.resize_dialog()
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)
def _accept_clicked(self):
#self._save_preferences()
self.selected_issues = []
for item in self.values_list.selectedItems():
self.selected_issues.append(item.data(1).toPyObject()[0])
self.accept()
示例9: PrefsViewerDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class PrefsViewerDialog(SizePersistedDialog):
def __init__(self, gui, namespace):
SizePersistedDialog.__init__(self, gui, 'Prefs Viewer dialog')
self.setWindowTitle('Preferences for: '+namespace)
self.gui = gui
self.db = gui.current_db
self.namespace = namespace
self._init_controls()
self.resize_dialog()
self._populate_settings()
if self.keys_list.count():
self.keys_list.setCurrentRow(0)
def _init_controls(self):
layout = QVBoxLayout(self)
self.setLayout(layout)
ml = QHBoxLayout()
layout.addLayout(ml, 1)
self.keys_list = QListWidget(self)
self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection)
self.keys_list.setFixedWidth(150)
self.keys_list.setAlternatingRowColors(True)
ml.addWidget(self.keys_list)
self.value_text = QTextEdit(self)
self.value_text.setTabStopWidth(24)
self.value_text.setReadOnly(True)
ml.addWidget(self.value_text, 1)
button_box = QDialogButtonBox(QDialogButtonBox.Ok)
button_box.accepted.connect(self.accept)
self.clear_button = button_box.addButton('Clear', QDialogButtonBox.ResetRole)
self.clear_button.setIcon(get_icon('trash.png'))
self.clear_button.setToolTip('Clear all settings for this plugin')
self.clear_button.clicked.connect(self._clear_settings)
layout.addWidget(button_box)
def _populate_settings(self):
self.keys_list.clear()
ns_prefix = self._get_ns_prefix()
keys = sorted([k[len(ns_prefix):] for k in self.db.prefs.iterkeys()
if k.startswith(ns_prefix)])
for key in keys:
self.keys_list.addItem(key)
self.keys_list.setMinimumWidth(self.keys_list.sizeHintForColumn(0))
self.keys_list.currentRowChanged[int].connect(self._current_row_changed)
def _current_row_changed(self, new_row):
if new_row < 0:
self.value_text.clear()
return
key = unicode(self.keys_list.currentItem().text())
val = self.db.prefs.get_namespaced(self.namespace, key, '')
self.value_text.setPlainText(self.db.prefs.to_raw(val))
def _get_ns_prefix(self):
return 'namespaced:%s:'% self.namespace
def _clear_settings(self):
from calibre.gui2.dialogs.confirm_delete import confirm
message = '<p>Are you sure you want to clear your settings in this library for this plugin?</p>' \
'<p>Any settings in other libraries or stored in a JSON file in your calibre plugins ' \
'folder will not be touched.</p>' \
'<p>You must restart calibre afterwards.</p>'
if not confirm(message, self.namespace+'_clear_settings', self):
return
ns_prefix = self._get_ns_prefix()
keys = [k for k in self.db.prefs.iterkeys() if k.startswith(ns_prefix)]
for k in keys:
del self.db.prefs[k]
self._populate_settings()
d = info_dialog(self, 'Settings deleted',
'<p>All settings for this plugin in this library have been cleared.</p>'
'<p>Please restart calibre now.</p>',
show_copy_button=False)
b = d.bb.addButton(_('Restart calibre now'), d.bb.AcceptRole)
b.setIcon(QIcon(I('lt.png')))
d.do_restart = False
def rf():
d.do_restart = True
b.clicked.connect(rf)
d.set_details('')
d.exec_()
b.clicked.disconnect()
self.close()
if d.do_restart:
self.gui.quit(restart=True)
示例10: ManageKeysDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import setSelectionMode [as 别名]
class ManageKeysDialog(QDialog):
def __init__(self, parent, key_type_name, plugin_keys, create_key, keyfile_ext = u""):
QDialog.__init__(self,parent)
self.parent = parent
self.key_type_name = key_type_name
self.plugin_keys = plugin_keys
self.create_key = create_key
self.keyfile_ext = keyfile_ext
self.import_key = (keyfile_ext != u"")
self.binary_file = (key_type_name == u"Adobe Digital Editions Key")
self.json_file = (key_type_name == u"Kindle for Mac and PC Key")
self.setWindowTitle("{0} {1}: Manage {2}s".format(PLUGIN_NAME, PLUGIN_VERSION, self.key_type_name))
# Start Qt Gui dialog layout
layout = QVBoxLayout(self)
self.setLayout(layout)
help_layout = QHBoxLayout()
layout.addLayout(help_layout)
# Add hyperlink to a help file at the right. We will replace the correct name when it is clicked.
help_label = QLabel('<a href="http://www.foo.com/">Help</a>', self)
help_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard)
help_label.setAlignment(Qt.AlignRight)
help_label.linkActivated.connect(self.help_link_activated)
help_layout.addWidget(help_label)
keys_group_box = QGroupBox(_(u"{0}s".format(self.key_type_name)), self)
layout.addWidget(keys_group_box)
keys_group_box_layout = QHBoxLayout()
keys_group_box.setLayout(keys_group_box_layout)
self.listy = QListWidget(self)
self.listy.setToolTip(u"{0}s that will be used to decrypt ebooks".format(self.key_type_name))
self.listy.setSelectionMode(QAbstractItemView.SingleSelection)
self.populate_list()
keys_group_box_layout.addWidget(self.listy)
button_layout = QVBoxLayout()
keys_group_box_layout.addLayout(button_layout)
self._add_key_button = QtGui.QToolButton(self)
self._add_key_button.setToolTip(u"Create new {0}".format(self.key_type_name))
self._add_key_button.setIcon(QIcon(I('plus.png')))
self._add_key_button.clicked.connect(self.add_key)
button_layout.addWidget(self._add_key_button)
self._delete_key_button = QtGui.QToolButton(self)
self._delete_key_button.setToolTip(_(u"Delete highlighted key"))
self._delete_key_button.setIcon(QIcon(I('list_remove.png')))
self._delete_key_button.clicked.connect(self.delete_key)
button_layout.addWidget(self._delete_key_button)
if type(self.plugin_keys) == dict:
self._rename_key_button = QtGui.QToolButton(self)
self._rename_key_button.setToolTip(_(u"Rename highlighted key"))
self._rename_key_button.setIcon(QIcon(I('edit-select-all.png')))
self._rename_key_button.clicked.connect(self.rename_key)
button_layout.addWidget(self._rename_key_button)
self.export_key_button = QtGui.QToolButton(self)
self.export_key_button.setToolTip(u"Save highlighted key to a .{0} file".format(self.keyfile_ext))
self.export_key_button.setIcon(QIcon(I('save.png')))
self.export_key_button.clicked.connect(self.export_key)
button_layout.addWidget(self.export_key_button)
spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
button_layout.addItem(spacerItem)
layout.addSpacing(5)
migrate_layout = QHBoxLayout()
layout.addLayout(migrate_layout)
if self.import_key:
migrate_layout.setAlignment(Qt.AlignJustify)
self.migrate_btn = QPushButton(u"Import Existing Keyfiles", self)
self.migrate_btn.setToolTip(u"Import *.{0} files (created using other tools).".format(self.keyfile_ext))
self.migrate_btn.clicked.connect(self.migrate_wrapper)
migrate_layout.addWidget(self.migrate_btn)
migrate_layout.addStretch()
self.button_box = QDialogButtonBox(QDialogButtonBox.Close)
self.button_box.rejected.connect(self.close)
migrate_layout.addWidget(self.button_box)
self.resize(self.sizeHint())
def populate_list(self):
if type(self.plugin_keys) == dict:
for key in self.plugin_keys.keys():
self.listy.addItem(QListWidgetItem(key))
else:
for key in self.plugin_keys:
self.listy.addItem(QListWidgetItem(key))
def add_key(self):
d = self.create_key(self)
d.exec_()
if d.result() != d.Accepted:
# New key generation cancelled.
return
new_key_value = d.key_value
if type(self.plugin_keys) == dict:
#.........这里部分代码省略.........