本文整理汇总了Python中PyQt4.Qt.QListWidget.currentItem方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.currentItem方法的具体用法?Python QListWidget.currentItem怎么用?Python QListWidget.currentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QListWidget
的用法示例。
在下文中一共展示了QListWidget.currentItem方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SearchDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import currentItem [as 别名]
class SearchDialog(SizePersistedDialog):
def __init__(self, parent=None, func=None, title="Search"):
SizePersistedDialog.__init__(self, parent, 'arg plugin:search dialog')
self.setWindowTitle(title)
self.gui = parent
self.func = func
layout = QVBoxLayout(self)
self.setLayout(layout)
self.search_label = QLabel(title)
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)
# for multiple selection
#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.func(query))
def _accept_clicked(self):
#self._save_preferences()
self.selected_result = None
if self.values_list.currentItem():
i = self.values_list.currentItem()
self.selected_result = (i.data(1)[0], i.text())
self.accept()
示例2: PrefsViewerDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import currentItem [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))
示例3: PrefsViewerDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import currentItem [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)
示例4: ManageKeysDialog
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import currentItem [as 别名]
#.........这里部分代码省略.........
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:
if new_key_value in self.plugin_keys.values():
old_key_name = [name for name, value in self.plugin_keys.iteritems() if value == new_key_value][0]
info_dialog(None, "{0} {1}: Duplicate {2}".format(PLUGIN_NAME, PLUGIN_VERSION,self.key_type_name),
u"The new {1} is the same as the existing {1} named <strong>{0}</strong> and has not been added.".format(old_key_name,self.key_type_name), show=True)
return
self.plugin_keys[d.key_name] = new_key_value
else:
if new_key_value in self.plugin_keys:
info_dialog(None, "{0} {1}: Duplicate {2}".format(PLUGIN_NAME, PLUGIN_VERSION,self.key_type_name),
u"This {0} is already in the list of {0}s has not been added.".format(self.key_type_name), show=True)
return
self.plugin_keys.append(d.key_value)
self.listy.clear()
self.populate_list()
def rename_key(self):
if not self.listy.currentItem():
errmsg = u"No {0} selected to rename. Highlight a keyfile first.".format(self.key_type_name)
r = error_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
_(errmsg), show=True, show_copy_button=False)
return
d = RenameKeyDialog(self)
d.exec_()
if d.result() != d.Accepted:
# rename cancelled or moot.
return
keyname = unicode(self.listy.currentItem().text().toUtf8(),'utf8')
if not question_dialog(self, "{0} {1}: Confirm Rename".format(PLUGIN_NAME, PLUGIN_VERSION), u"Do you really want to rename the {2} named <strong>{0}</strong> to <strong>{1}</strong>?".format(keyname,d.key_name,self.key_type_name), show_copy_button=False, default_yes=False):
return
self.plugin_keys[d.key_name] = self.plugin_keys[keyname]
del self.plugin_keys[keyname]
self.listy.clear()
self.populate_list()
def delete_key(self):
if not self.listy.currentItem():
return
keyname = unicode(self.listy.currentItem().text().toUtf8(), 'utf8')
if not question_dialog(self, "{0} {1}: Confirm Delete".format(PLUGIN_NAME, PLUGIN_VERSION), u"Do you really want to delete the {1} <strong>{0}</strong>?".format(keyname, self.key_type_name), show_copy_button=False, default_yes=False):
return
if type(self.plugin_keys) == dict:
del self.plugin_keys[keyname]
else:
self.plugin_keys.remove(keyname)
self.listy.clear()
示例5: PluginObject
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import currentItem [as 别名]
#.........这里部分代码省略.........
self.segOrdListBox = QListWidget()
self.segOrdListBox.customContextMenuRequested.connect(self.showOrdContextMenu)
self.segOrdListBox.setContextMenuPolicy(Qt.CustomContextMenu)
self.searchButton = QPushButton("Search")
self.main.connect(self.searchButton, SIGNAL('clicked()'), searchForPassphrase)
self.stopButton = QPushButton("Stop Searching")
self.stopButton.setEnabled(False)
self.main.connect(self.stopButton, SIGNAL('clicked()'), endSearch)
totalSearchLabel = QRichLabel(tr("""<b>Total Passphrase Tries To Search: </b>"""), doWrap=False)
self.totalSearchTriesDisplay = QLineEdit()
self.totalSearchTriesDisplay.setReadOnly(True)
self.totalSearchTriesDisplay.setText(QString('0'))
self.totalSearchTriesDisplay.setFont(GETFONT('Fixed'))
self.totalSearchTriesDisplay.setMinimumWidth(tightSizeNChar(self.totalSearchTriesDisplay, 6)[0])
self.totalSearchTriesDisplay.setMaximumWidth(tightSizeNChar(self.totalSearchTriesDisplay, 12)[0])
searchButtonPanel = makeHorizFrame([self.searchButton, self.stopButton, 'stretch', totalSearchLabel, self.totalSearchTriesDisplay])
self.resultsDisplay = QTextEdit()
self.resultsDisplay.setReadOnly(True)
self.resultsDisplay.setFont(GETFONT('Fixed'))
self.resultsDisplay.setMinimumHeight(100)
self.searchPanel = makeVertFrame([topRow, self.segDefTableView, orderingButtonPanel,
self.segOrdListBox, searchButtonPanel, self.resultsDisplay, 'stretch'])
# Now set the scrollarea widget to the layout
self.tabToDisplay = QScrollArea()
self.tabToDisplay.setWidgetResizable(True)
self.tabToDisplay.setWidget(self.searchPanel)
def getSelectedWlt(self):
wlt = None
selectedWltList = self.main.walletsView.selectedIndexes()
if len(selectedWltList)>0:
row = selectedWltList[0].row()
wltID = str(self.main.walletsView.model().index(row, WLTVIEWCOLS.ID).data().toString())
wlt = self.main.walletMap[wltID]
return wlt
def showSegContextMenu(self):
menu = QMenu(self.segDefTableView)
if len(self.segDefTableView.selectedIndexes())==0:
return
row = self.segDefTableView.selectedIndexes()[0].row()
deleteSegMenuItem = menu.addAction("Delete Segment")
action = menu.exec_(QCursor.pos())
if action == deleteSegMenuItem:
self.deleteSegRow(row)
def showOrdContextMenu(self):
menu = QMenu(self.segOrdListBox)
if len(self.segOrdListBox.selectedItems())==0:
return
item = self.segOrdListBox.currentItem()
deleteOrdMenuItem = menu.addAction("Delete Ordering")
action = menu.exec_(QCursor.pos())
if action == deleteOrdMenuItem:
self.deleteOrdItem(item)
def deleteSegRow(self, row):
self.segDefList.remove(self.segDefList[row])
self.segDefTableModel.updateSegList(self.segDefList)
self.segOrdStrSet.clear()
self.updateOrderingListBox()
def deleteOrdItem(self, ordItem):
ordText = str(ordItem.text())
self.segOrdStrSet.remove(ordText)
self.updateOrderingListBox()
def getTabToDisplay(self):
return self.tabToDisplay
def updateOrderingListBox(self):
self.segOrdListBox.clear()
segOrdList = list(self.segOrdStrSet)
segOrdList.sort()
totalTries = 0
for ordStr in segOrdList:
self.segOrdListBox.addItem(QListWidgetItem(ordStr))
totalTries += self.calculateTries(ordStr)
if totalTries > BILLION_INT:
self.totalSearchTriesDisplay.setText(OVER_BILLION_STR)
else:
self.totalSearchTriesDisplay.setText(str(totalTries))
def calculateTries(self, ordStr):
ordIntList = [int(indexStr) for indexStr in ordStr.split(',')]
totalTries = 1
# Multiply each of the totals of segment instance together.
for ordInt in ordIntList:
totalTries *= self.segDefList[ordInt-1].getSegListLen()
return totalTries
示例6: tab_widget
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import currentItem [as 别名]
#.........这里部分代码省略.........
# Initiate the widgets gui
def initUI(self):
vbox_inner = QVBoxLayout()
grid = QtGui.QGridLayout()
self.genreList = ['Fiction', 'Fact book', 'Poetry']
# Tab 1: Add Data
self.makeAddDataTab(grid)
# Tab 2:Get Data from file
hbox_inner = self.makeGetDataTab(vbox_inner)
tab1 = QWidget()
tab1.setLayout(grid)
vbox_inner.addLayout(hbox_inner)
tab2 = QWidget()
tab2.setLayout(vbox_inner)
self.addTab(tab1, "Add Book Data")
self.addTab(tab2, "Get Book Data")
self.move(150, 150)
self.show()
# Function for when a QListWidgetItem is clicked if the genre_list is
# clicked, will check which genre was chosen and populate genre2_list
# with subgenres of that genre.
def item_clicked(self):
genre = self.sender()
if genre.objectName() == "genre_list":
curr = genre.currentItem().text()
if curr == self.genreList[0]:
genre2List = ["Detective", "autobiography", "Horror", "Comedy"]
elif curr == self.genreList[1]:
genre2List = ["Technology", "Biology", "Chemistry", "Mathematics"]
elif curr == self.genreList[2]:
genre2List = ["Tirade", "Ballads", "Rhyme"]
else:
genre2List = ["None"]
self.genre2_list.clear()
self.genre2_list.addItems(genre2List)
# Function for when a button is clicked, if 'Submit Data' is clicked,
# will check that all input is correct format and if so write
# the data to the file. If the button pressed is 'Get title data'
# will get the selected title in the QListWidget and show the row data
def buttonClicked(self):
sender = self.sender()
if sender.text() == "Refresh list":
if self.parent().dialog.isHidden():
titles = getAllTitles(self.parent())
self.titles_list.clear()
if titles != "":
self.titles_list.addItems(titles)
else:
QMessageBox.warning(self.parent(), "Failure", "Connect to the server before refreshing.")
if sender.text() == "Exit":
if self.parent().dialog.isHidden():
self.parent().disconnect()
sys.exit(0)
示例7: tab_widget
# 需要导入模块: from PyQt4.Qt import QListWidget [as 别名]
# 或者: from PyQt4.Qt.QListWidget import currentItem [as 别名]
#.........这里部分代码省略.........
self.getTitleData = QtGui.QPushButton("Get title data", self)
self.getTitleData.clicked.connect(self.buttonClicked)
vbox_inner.addWidget(self.getTitleData)
self.submit = QtGui.QPushButton("Submit Data", self)
self.submit.clicked.connect(self.buttonClicked)
grid.addWidget(self.submit, 8, 1)
self.quit = QtGui.QPushButton("Exit", self)
self.quit.clicked.connect(QtCore.QCoreApplication.instance().quit)
self.quit.setMaximumWidth(80)
grid.addWidget(self.quit, 8, 0)
tab1 = QWidget()
tab1.setLayout(grid)
tab2 = QWidget()
tab2.setLayout(vbox_inner)
self.addTab(tab1, "Add Data")
self.addTab(tab2, "Get Data")
self.move(150, 150)
self.show()
# Function for when a QListWidgetItem is clicked if the genre_list is
# clicked, will check which genre was chosen and populate genre2_list
# with subgenres of that genre.
def item_clicked(self):
genre = self.sender()
if genre.objectName() == "genre_list":
curr = genre.currentItem().text()
if curr == self.genreList[0]:
genre2List = ["Detective", "autobiograpyh", "Horror", "Comedy"]
elif curr == self.genreList[1]:
genre2List = ["Technology", "Biology", "Chemistry", "Mathematics"]
elif curr == self.genreList[2]:
genre2List = ["Tirade", "Ballads", "Rhyme"]
else:
genre2List = ["None"]
self.genre2_list.clear()
self.genre2_list.addItems(genre2List)
# Function for when a button is clicked, if 'Submit Data' is clicked,
# will check that all input is correct format and if so write
# the data to the file. If the button pressed is 'Get title data'
# will get the selected title in the QListWidget and show the row data
def buttonClicked(self):
sender = self.sender()
if sender.text() == "Get title data":
if self.titles_list.currentItem() != None:
titleToGet = str(self.titles_list.currentItem().text())
titleData = findTitleData(titleToGet)
splitLine = []
splitLine = titleData.split(",", 7)
self.authorData.setText('Author: '+splitLine[0].replace('"', "").lstrip())
self.titleData.setText('Title: '+splitLine[1].replace('"', "").lstrip())
self.genreData.setText('Genre: '+splitLine[2].replace('"', "").lstrip())
self.genre2Data.setText('Genre2: '+splitLine[3].replace('"', "").lstrip())
self.dateData.setText('Date Read: '+splitLine[4].replace('"', "").lstrip())
self.gradeData.setText('Grade: '+splitLine[5].replace('"', "").lstrip())
self.commentsData.setText('Comments: '+splitLine[6].replace('"', "").lstrip())