本文整理汇总了Python中PySide.QtGui.QListWidget.takeItem方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.takeItem方法的具体用法?Python QListWidget.takeItem怎么用?Python QListWidget.takeItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QListWidget
的用法示例。
在下文中一共展示了QListWidget.takeItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import takeItem [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.resize(800,600)
self.setWindowTitle('PDF Merger')
about = QAction('About', self)
self.connect(about, SIGNAL('triggered()'), self.show_about)
exit = QAction('Exit', self)
exit.setShortcut('Ctrl+Q')
self.connect(exit, SIGNAL('triggered()'), SLOT('close()'))
self.statusBar()
menubar = self.menuBar()
file = menubar.addMenu('File')
file.addAction(about)
file.addAction(exit)
self.main_widget = QWidget(self)
self.setCentralWidget(self.main_widget)
self.up_down_widget = QWidget(self)
self.options_widget = QWidget(self)
input_files_label = QLabel("Input PDFs\nThis is the order in which the files will be merged too")
self.files_list = QListWidget()
self.files_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
add_button = QPushButton("Add PDF(s) to merge...")
add_button.clicked.connect(self.clicked_add)
up_button = QPushButton("Up")
up_button.clicked.connect(self.move_file_up)
down_button = QPushButton("Down")
down_button.clicked.connect(self.move_file_down)
remove_button = QPushButton("Remove PDF")
remove_button.clicked.connect(self.remove_file)
select_path_label = QLabel("Output PDF")
self.dest_path_edit = QLineEdit()
self.dest_path_edit.setReadOnly(True)
select_path = QPushButton("Select...")
select_path.clicked.connect(self.select_save_path)
start = QPushButton("Start")
start.clicked.connect(self.merge_pdf)
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:
#.........这里部分代码省略.........
示例2: UiMain
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import takeItem [as 别名]
#.........这里部分代码省略.........
# Makes the -> readable and clear
self.switch_active_item_button_off.setFont(QFont('SansSerif', 17))
self.switch_active_item_button_off.setGeometry(175, 55, 40, 30)
# on button
self.switch_active_item_button_on = QPushButton(self.options)
self.switch_active_item_button_on.setText('<-'.decode('utf-8'))
# makes <- readable and clear
self.switch_active_item_button_on.setFont(QFont('SansSerif', 17))
self.switch_active_item_button_on.setGeometry(175, 90, 40, 30)
QObject.connect(self.switch_active_item_button_on, SIGNAL
("clicked()"), self.switch_item_on)
QObject.connect(self.switch_active_item_button_off, SIGNAL
("clicked()"), self.switch_item_off)
# A button to toggle the split output in half option. It's a temporary
# fix for the Foobar double output problem.
self.switch_output_split_btn = QCheckBox(self.options)
self.switch_output_split_btn.setCheckState(Qt.CheckState.Unchecked)
self.switch_output_split_btn.setGeometry(10, 140, 40, 30)
self.switch_output_split_btn.stateChanged.connect(self.toggle_split)
# The label for the split toggle
self.switch_output_split_lbl = QLabel(self.options)
self.switch_output_split_lbl.setText(
"Split the output text in half (don't use this if you don't need it)")
self.switch_output_split_lbl.setGeometry(30, 140, 300, 30)
def switch_item_on(self):
""" Switches items (musicapps) on """
try:
# If an item from the active box is selected
# Remove it and place it inside the inactive box
item_taken = self.inactive_items_list.takeItem(
self.inactive_items_list.currentRow())
self.active_items_list.addItem(item_taken)
active_items = {}
inactive_items = {}
for i in range(self.active_items_list.count()):
active_items[self.active_items_list.item(i).text()] =\
ITEMS[self.active_items_list.item(i).text()
.encode('utf-8')]
for i in range(self.inactive_items_list.count()):
inactive_items[self.inactive_items_list.item(i).text()] =\
ITEMS[self.inactive_items_list.item(i).text()
.encode('utf-8')]
Constants.ACTIVE_ITEMS = active_items
Constants.INACTIVE_ITEMS = inactive_items
# clear the selection combobox
self.app_select_box.clear()
# Repopulate the combobox
self.app_select_box.addItem(None)
for item in active_items:
self.app_select_box.addItem(item)
Constants.CONFIG.set('active', item_taken.text(),
ITEMS[item_taken.text()])
Constants.CONFIG.remove_option('inactive', item_taken.text())
# Updates the config file to be up to date with activeItems
Constants.CONFIG.update()
except:
raise
def switch_item_off(self):
""" Switches items (musicapps) off """
try:
# If an item from the inactive box is selected.
示例3: ProfileSelection
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import takeItem [as 别名]
#.........这里部分代码省略.........
return athleteProfile
def updateList(self, athletes):
self.list.clear()
self.athletesList = athletes
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)
def resetWidget(self):
""" Resets the widget to the initial laoyout.
Should be used only in specific cases
"""
self.editBtn.setChecked(False)
self._toggleProfileEdit()
def _removeProfile_Dialog(self):
"""Runs a prompt dialog.
Ask the user if he really wants to remove the selected profile.
"""
confirmationDialog = QMessageBox()
confirmationDialog.setText("Do you really want to remove the selected profile ?")
confirmationDialog.setInformativeText("Profile deletion can not be undone")
confirmationDialog.setIcon(QMessageBox.Question)
confirmationDialog.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
confirmationDialog.accepted.connect(self._emitRemoveProfile)
ret = confirmationDialog.exec_()
if ret==QMessageBox.Yes:
self._emitRemoveProfile()
def _emitRemoveProfile(self):
athlete = self.getSelectedProfile()
rowToDelete = 0
for index, element in enumerate(self.athletesList):
if element == athlete:
rowToDelete = index
self.list.takeItem(rowToDelete)
self.athletesList.remove(athlete)
self.removeProfile.emit(athlete)
def _okButtonSlot(self):
athlete = self.list.selectedItems()[0].data(Qt.UserRole)
self.accept() # is it correct ? Maybe self.close() is better ?
# Or should I redefine the accept() method ?
#athleteProfile = self.getSelectedProfile()
self.profileSelected.emit(athlete)
def _cancelButtonSlot(self):
if len(self.athletesList) == 0:
self.lastProfileDeleted.emit()
self.reject()
def _saveButtonSlot(self):
selectedProfile = self.getSelectedProfile()
updatedProfile = self.profileWidget.getProfile()
self.profileUpdate_request.emit(selectedProfile, updatedProfile)
#self._toggleProfileEdit()
def _toggleProfileEdit(self):
if self.editBtn.isChecked():
self.profileWidget.setProfile(self.getSelectedProfile())
self.profileWidget.show()
self.saveBtn.show()
self.okBtn.hide()
self.removeProfileBtn.hide()
else:
self.saveBtn.hide()
self.profileWidget.hide()
self.okBtn.show()
self.removeProfileBtn.show()
def _activateButtons(self):
selectedItems = self.list.selectedItems()
if len(selectedItems)!=0 :
self.okBtn.setDisabled(False)
self.removeProfileBtn.setDisabled(False)
self.editBtn.setDisabled(False)
else :
self.okBtn.setDisabled(True)
self.removeProfileBtn.setDisabled(True)
self.editBtn.setDisabled(True)