本文整理汇总了Python中PySide.QtGui.QListWidget.selectedItems方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.selectedItems方法的具体用法?Python QListWidget.selectedItems怎么用?Python QListWidget.selectedItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QListWidget
的用法示例。
在下文中一共展示了QListWidget.selectedItems方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigEditor
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import selectedItems [as 别名]
#.........这里部分代码省略.........
self.main_layout.addLayout(self.config_layout)
self.main_layout.addWidget(self.mainButtons)
self.main.setLayout(self.main_layout)
self.setCentralWidget(self.main)
self.setWindowTitle(self.title)
self.setUnifiedTitleAndToolBarOnMac(True)
self.categories.setCurrentItem(self.categories.item(0))
self.menuBar = QMenuBar()
self.filemenu = QMenu('&File')
self.quitAction = QAction(self)
self.quitAction.setText('&Quit')
if platform.system() != 'Darwin':
self.quitAction.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Q))
QObject.connect(self.quitAction, SIGNAL('triggered()'), self.quitApp)
self.filemenu.addAction(self.quitAction)
self.menuBar.addMenu(self.filemenu)
self.setMenuBar(self.menuBar)
self.show()
self.activateWindow()
self.raise_()
self.setMinimumWidth(self.geometry().width()*1.2)
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
def category_selected(self):
self.settings.setCurrentIndex(self.config.config.index(self.categories.selectedItems()[0].text()))
def mainbutton_clicked(self, button):
if button == self.main_reset:
for cat in self.base_cfg.get_categories():
for setting in self.base_cfg.get_settings(cat):
self.widget_list[cat][setting].updateValue(self.base_cfg.get_setting(cat,setting))
elif button == self.main_defaults:
for cat in self.def_cfg.get_categories():
for setting in self.def_cfg.get_settings(cat):
self.widget_list[cat][setting].updateValue(self.def_cfg.get_setting(cat,setting))
elif button == self.main_apply:
bad_settings = self.validate_settings()
if bad_settings == []:
self.save_settings()
self.main_apply.setEnabled(False)
self.main_reset.setEnabled(False)
else:
msgBox = QMessageBox()
msgBox.setText("Must fix the following invalid settings before quitting:")
msgBox.setStandardButtons(QMessageBox.Ok)
info = ''
for setting in bad_settings:
new = '%s,%s<br>' % setting
info = '%s%s' % (info, new)
msgBox.setInformativeText(info)
msgBox.exec_()
def quitApp(self):
self.app.closeAllWindows()
def get_changes(self):
示例2: MultiListDialog
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import selectedItems [as 别名]
class MultiListDialog(QDialog):
def __init__(self, items): # , parent=None
super(MultiListDialog, self).__init__() # parent
self.resize(800, 550)
self.entries = items
layout = QVBoxLayout(self)
self.listWidget = QListWidget(self)
self.listWidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.HlineInputfiles = ConfigLineDir(u"Verzeichnis NI XML:", "dir")
self.HlineOutputfiles = ConfigLineDir(u"Verzeichnis Report:", "dir")
if os.path.isfile(PICKLE_TEMP_FILE):
pkl_file = open(PICKLE_TEMP_FILE, 'rb')
inPath = pickle.load(pkl_file)
outPath = pickle.load(pkl_file)
pkl_file.close()
if os.path.isdir(inPath):
self.HlineInputfiles.editText.setText(inPath)
if os.path.isdir(outPath):
self.HlineOutputfiles.editText.setText(outPath)
layout.addLayout(self.HlineInputfiles)
layout.addLayout(self.HlineOutputfiles)
layout.addWidget(self.listWidget)
layout.addWidget(QLabel("Mehrfachauswahl -> Strg + Mausklick"))
# OK and Cancel buttons
buttons = QDialogButtonBox(QDialogButtonBox.Apply | QDialogButtonBox.Close, Qt.Horizontal, self)
# Apply before Close
buttons.setStyleSheet("* { button-layout: 2 }")
layout.addWidget(buttons)
buttons.rejected.connect(self.close)
buttons.button(QDialogButtonBox.Apply).clicked.connect(self.Apply_Clicked)
self.SetListItems()
self.HlineInputfiles.editText.textChanged.connect(self.RefreshList)
self.HlineInputfiles.editText.textChanged.connect(self.SetListItems)
# def SetOutputDir(self):
# self.HlineOutputfiles.editText.setText(self.HlineInputfiles.getText())
def SetListItems(self, parent=None):
itemslist = os.listdir(self.HlineInputfiles.getText())
for it in itemslist:
if it.endswith(".xml"):
self.listWidget.addItem(it)
def GetMarkedItems(self):
results = []
try:
for el in self.listWidget.selectedItems():
results.append(str(el.text()))
return (results)
except:
return (None)
def RefreshList(self):
self.listWidget.clear()
print "refresh"
def Apply_Clicked(self):
SelectedItems = self.GetMarkedItems()
textMsg = "Selektierte Dateie(n):\r\n"
if len(SelectedItems) > 0:
for file in SelectedItems:
filePath = os.path.join(self.HlineInputfiles.getText(), file)
textMsg += (file + "\r\n")
XmlAnalysis.XmlAnalysis(filePath, self.HlineOutputfiles.getText())
#QMessageBox.information(self, "Report", textMsg)
textMsg += "\r\nReport-Verzeichnis öffnen?\r\n"
msgBox = QMessageBox.StandardButton.Yes
msgBox |= QMessageBox.StandardButton.No
if QMessageBox.question(self, "Report", textMsg, msgBox) == QMessageBox.Yes:
os.startfile(self.HlineOutputfiles.getText())
else:
QMessageBox.warning(self, "Achtung", "Keine Datei selektiert!")
pass
示例3: ProfileSelection
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import selectedItems [as 别名]
class ProfileSelection(QDialog):
'''
classdocs
'''
removeProfile = Signal(Athlete_Model)
profileSelected = Signal(Athlete_Model)
profileUpdate_request = Signal(Athlete_Model, Athlete_Model)
lastProfileDeleted = Signal()
def __init__(self, athletesList):
'''
Constructor
'''
QDialog.__init__(self)
self.setWindowTitle("Profile Selection")
self.athletesList = athletesList
self._initGUI()
def _initGUI(self):
topHLayout = QHBoxLayout()
hLayout = QHBoxLayout()
vLayout = QVBoxLayout()
# Label
greeterText = QLabel("Welcome to <b>Pushup app</b>." + \
"<br><br> Select a profile:")
vLayout.addWidget(greeterText)
# List
self.list = QListWidget()
self.list.setMinimumWidth(150)
self.list.setSelectionMode(QAbstractItemView.SingleSelection)
# SingleSelection is the default value, but I prefer to be sure
self.list.itemSelectionChanged.connect(self._activateButtons)
for athlete in self.athletesList:
iconW = QIcon.fromTheme("user-available")
# doens't work on Mac and Windows
# http://qt-project.org/doc/qt-4.8/qicon.html#fromTheme
listW = QListWidgetItem(iconW, athlete._name)
listW.setData(Qt.UserRole, athlete)
self.list.addItem(listW)
topHLayout.addWidget(self.list)
self.profileWidget = ProfileFormWidget()
self.profileWidget.hide()
topHLayout.addWidget(self.profileWidget)
vLayout.addLayout(topHLayout)
vLayout.addLayout(hLayout)
# Buttons
self.okBtn = QPushButton("Ok")
self.okBtn.setDisabled(True)
self.okBtn.setDefault(True)
self.okBtn.clicked.connect(self._okButtonSlot)
self.list.itemDoubleClicked.connect(self._okButtonSlot)
cancelBtn = QPushButton("Cancel")
cancelBtn.clicked.connect(self._cancelButtonSlot)
self.editBtn = QPushButton("Edit")
self.editBtn.setDisabled(True)
self.editBtn.setCheckable(True)
self.editBtn.clicked.connect(self._toggleProfileEdit)
self.saveBtn = QPushButton("Save changes") # Saves the changes made on the profile
self.saveBtn.hide()
self.saveBtn.clicked.connect(self._saveButtonSlot)
self.removeProfileBtn = QPushButton("Remove Profile")
self.removeProfileBtn.setDisabled(True)
self.removeProfileBtn.clicked.connect(self._removeProfile_Dialog)
hLayout.addWidget(self.editBtn)
hLayout.addWidget(self.removeProfileBtn)
hLayout.addWidget(cancelBtn)
hLayout.addWidget(self.okBtn)
hLayout.addWidget(self.saveBtn)
self.setLayout(vLayout)
def getSelectedProfile(self):
selectedListItem = self.list.selectedItems()[0]
athleteProfile = selectedListItem.data(Qt.UserRole)
return athleteProfile
def updateList(self, athletes):
self.list.clear()
self.athletesList = athletes
for athlete in self.athletesList:
iconW = QIcon.fromTheme("user-available")
#.........这里部分代码省略.........
示例4: MainWindow
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import selectedItems [as 别名]
#.........这里部分代码省略.........
up_down_vbox = QVBoxLayout(self.up_down_widget)
up_down_vbox.addWidget(up_button)
up_down_vbox.addWidget(down_button)
up_down_vbox.addWidget(remove_button)
self.up_down_widget.setLayout(up_down_vbox)
group_input = QGroupBox()
grid_input = QGridLayout()
grid_input.addWidget(add_button, 0, 0)
grid_input.addWidget(input_files_label, 1, 0)
grid_input.addWidget(self.files_list, 2, 0)
grid_input.addWidget(self.up_down_widget, 2, 1)
group_input.setLayout(grid_input)
group_output = QGroupBox()
grid_output = QGridLayout()
grid_output.addWidget(select_path_label, 0, 0)
grid_output.addWidget(self.dest_path_edit, 1, 0)
grid_output.addWidget(select_path, 1, 1)
group_output.setLayout(grid_output)
vbox_options = QVBoxLayout(self.options_widget)
vbox_options.addWidget(group_input)
vbox_options.addWidget(group_output)
vbox_options.addWidget(start)
self.options_widget.setLayout(vbox_options)
splitter_filelist = QSplitter()
splitter_filelist.setOrientation(Qt.Vertical)
splitter_filelist.addWidget(self.options_widget)
vbox_main = QVBoxLayout(self.main_widget)
vbox_main.addWidget(splitter_filelist)
vbox_main.setContentsMargins(0,0,0,0)
def show_about(self):
#TODO add hyperlinks and create simple base website
#TODO versioning system
QMessageBox.about(self, 'About', 'PDF Merger\n2013 Nikola Peric\n\n'
+ 'http://www.example.com/\nhttps://github.com/nikolap/pdfmerger/\n\n'
+ 'Licensed under The MIT License\nhttp://opensource.org/licenses/MIT' )
def clicked_add(self):
fname, _ = QFileDialog.getOpenFileNames(self, 'Select two or more PDFs to merge',
QDir.homePath(), "*.pdf")
self.files_list.addItems(fname)
def move_file_up(self):
sorted_selected_items = self.get_sorted_selected_items()
if 0 not in sorted_selected_items:
for row in sorted_selected_items:
item = self.files_list.takeItem(row)
self.files_list.insertItem(row - 1, item)
def move_file_down(self):
sorted_selected_items = self.get_sorted_selected_items(descending=True)
if (self.files_list.count() - 1) not in sorted_selected_items:
for row in sorted_selected_items:
item = self.files_list.takeItem(row)
self.files_list.insertItem(row + 1, item)
def get_sorted_selected_items(self, descending=False):
items_list = []
for item in self.files_list.selectedItems():
items_list.append(self.files_list.row(item))
return sorted(items_list, key=int, reverse = descending)
def remove_file(self):
for item in self.files_list.selectedItems():
row = self.files_list.row(item)
self.files_list.takeItem(row)
def select_save_path(self):
fname, _ = QFileDialog.getSaveFileName(self, 'Save file', QDir.homePath(), "*.pdf")
self.dest_path_edit.setText(fname)
def merge_pdf(self):
save_path = self.dest_path_edit.text()
if save_path is '':
raise Exception(QMessageBox.warning(self, 'Warning!', 'No location to save file selected.\n'
+ 'Cannot proceed with merger.'))
input_files = []
for i in range(0, self.files_list.count()):
file_path = self.files_list.item(i).text()
if '.pdf' not in file_path and '.PDF' not in file_path:
QMessageBox.warning(self, 'Warning!', 'Some files not PDFs\n'
+ 'Please examine' + file_path)
raise Exception("PDF file error!")
else:
input_files.append(file_path)
if len(input_files) >= 2:
merge_pdf(destination=save_path, pdf_files=input_files)
else:
QMessageBox.warning(self, 'Warning!', 'Not enough PDFs selected.\n'
+ 'Please choose 2 or more files to merge.')
示例5: MainControl
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import selectedItems [as 别名]
class MainControl(QWidget):
toChangeChunk = Signal(tuple)
toChangeSlice = Signal(int)
def __init__(self, parent):
super(MainControl, self).__init__(parent)
self.parent = parent
self.selectedMinerals = parent.selectedMinerals
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
lb0 = QLabel('Minecraft Prism chunk minerals finder')
lb1 = QLabel('Chunk X')
lb2 = QLabel('Chunk Z')
lb3 = QLabel('Show deposits of:')
lb4 = QLabel('Slice Elevation')
#lb0.setFrameStyle(QFrame.Box)
lb0.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
lb2.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
self.txtChunkX = QLineEdit()
self.txtChunkZ = QLineEdit()
self.txtElevation = QLineEdit(str(self.parent.presenter.elevation))
self.txtChunkX.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
self.txtChunkZ.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
self.txtElevation.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
self.btnViewChunk = QPushButton('View Chunk')
self.btnViewChunk.clicked.connect(self.btnViewChunk_OnClick)
self.btnSliceUp = QPushButton('Slice Up')
self.btnSliceUp.clicked.connect(self.btnSliceUp_OnClick)
self.btnSliceDown = QPushButton('Slice Down')
self.btnSliceDown.clicked.connect(self.btnSliceDown_OnClick)
self.lstMinerals = QListWidget()
self.lstMinerals.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.lstMinerals.addItem(SelectedMineral('Gold', 14))
self.lstMinerals.addItem(SelectedMineral('Iron', 15))
self.lstMinerals.addItem(SelectedMineral('Diamond', 56))
self.lstMinerals.addItem(SelectedMineral('Redstone', 73))
self.lstMinerals.addItem(SelectedMineral('Obsidian', 49))
self.lstMinerals.addItem(SelectedMineral('Coal', 16))
self.lstMinerals.addItem(SelectedMineral('Lazurit', 21))
self.lstMinerals.setCurrentItem(self.lstMinerals.item(0))
self.lstMinerals.itemSelectionChanged.connect(self.onSelectedMinerals)
elevBox = QHBoxLayout()
elevBox.addWidget(lb4)
elevBox.addWidget(self.txtElevation)
elevBox.addWidget(self.btnSliceUp)
elevBox.addWidget(self.btnSliceDown)
ly = QGridLayout()
ly.addWidget(lb0, 0, 0, 1, 4)
ly.addWidget(lb1, 1, 0, 1, 1)
ly.addWidget(self.txtChunkX, 1, 1, 1, 1)
ly.addWidget(lb2, 1, 2, 1, 1)
ly.addWidget(self.txtChunkZ, 1, 3, 1, 1)
ly.addWidget(lb3, 2, 0, 1, 2)
ly.addWidget(self.lstMinerals, 2, 2, 1, 2)
ly.addWidget(self.btnViewChunk, 3, 1, 1, 2)
ly.addLayout(elevBox, 4, 0, 1, 4)
ly.setColumnStretch(0, 20)
ly.setColumnStretch(1, 15)
ly.setColumnStretch(2, 46)
ly.setColumnStretch(3, 19)
self.setLayout(ly)
def sizeHint(self):
return QSize(self.parent.controlsWidth, 180)
def btnViewChunk_OnClick(self):
chX = int(self.txtChunkX.text())
chZ = int(self.txtChunkZ.text())
self.toChangeChunk.emit((chX, chZ))
def btnSliceUp_OnClick(self):
elev = int(self.txtElevation.text()) + 1
if elev < 64:
self.toChangeSlice.emit(elev)
self.txtElevation.setText(str(elev))
def btnSliceDown_OnClick(self):
elev = int(self.txtElevation.text()) - 1
if elev > -1:
self.toChangeSlice.emit(elev)
self.txtElevation.setText(str(elev))
def onSelectedMinerals(self):
selMin = []
for item in self.lstMinerals.selectedItems():
selMin.append(item.blockCode)
self.parent.selectedMinerals.setSelectedMinerals(selMin)