本文整理汇总了Python中PyQt4.QtGui.QListView.currentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.currentIndex方法的具体用法?Python QListView.currentIndex怎么用?Python QListView.currentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QListView
的用法示例。
在下文中一共展示了QListView.currentIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VariableComboBox
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
class VariableComboBox(QWidget):
def __init__(self, id, text="Input data", default=[], model=None):
QWidget.__init__(self)
self.setToolTip("<p>Select input dataset</p>")
self.id = id
if model is None:
self.model = TreeModel()
else:
self.model = model
self.comboBox = QComboBox()
self.treeView = QListView(self.comboBox)
self.connect(self.comboBox, SIGNAL("currentIndexChanged(int)"),
self.changeSelectedText)
self.proxyModel = SortFilterProxyModel()
self.proxyModel.setDynamicSortFilter(True)
self.proxyModel.setFilterKeyColumn(1)
self.proxyModel.setSourceModel(self.model)
regexp = QRegExp("|".join([r"%s" % i for i in default]))
self.proxyModel.setFilterRegExp(regexp)
# self.treeView.header().hide()
self.currentText = QString()
self.treeView.setModel(self.proxyModel)
self.comboBox.setModel(self.proxyModel)
self.comboBox.setView(self.treeView)
# self.treeView.hideColumn(1)
# self.treeView.hideColumn(2)
# self.treeView.hideColumn(3)
self.treeView.viewport().installEventFilter(self.comboBox)
label = QLabel(text)
hbox = HBoxLayout()
hbox.addWidget(label)
hbox.addWidget(self.comboBox)
self.setLayout(hbox)
self.changeSelectedText(None)
def changeSelectedText(self, index):
item = self.treeView.currentIndex()
if not item.isValid():
item = self.proxyModel.index(0,0, QModelIndex())
tree = self.treeView.model().parentTree(item)
self.currentText = tree
def parameterValues(self):
return {self.id:self.currentText}
示例2: DataTypeKeysWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
class DataTypeKeysWidget(QWidget):
dataTypeKeySelected = pyqtSignal(str)
def __init__(self):
QWidget.__init__(self)
self.__filter_popup = FilterPopup(self)
self.__filter_popup.filterSettingsChanged.connect(self.onItemChanged)
layout = QVBoxLayout()
self.model = DataTypeKeysListModel()
self.filter_model = DataTypeProxyModel(self.model)
filter_layout = QHBoxLayout()
self.search_box = SearchBox()
self.search_box.filterChanged.connect(self.setSearchString)
filter_layout.addWidget(self.search_box)
filter_popup_button = QToolButton()
filter_popup_button.setIcon(util.resourceIcon("ide/cog_edit.png"))
filter_popup_button.clicked.connect(self.showFilterPopup)
filter_layout.addWidget(filter_popup_button)
layout.addLayout(filter_layout)
self.data_type_keys_widget = QListView()
self.data_type_keys_widget.setModel(self.filter_model)
self.data_type_keys_widget.selectionModel().selectionChanged.connect(self.itemSelected)
layout.addSpacing(15)
layout.addWidget(self.data_type_keys_widget, 2)
layout.addStretch()
# layout.addWidget(Legend("Default types", DataTypeKeysListModel.DEFAULT_DATA_TYPE))
layout.addWidget(Legend("Observations available", DataTypeKeysListModel.HAS_OBSERVATIONS))
self.setLayout(layout)
def onItemChanged(self, item):
self.filter_model.setShowBlockKeys(item["block"])
self.filter_model.setShowSummaryKeys(item["summary"])
self.filter_model.setShowGenKWKeys(item["gen_kw"])
self.filter_model.setShowGenDataKeys(item["gen_data"])
self.filter_model.setShowCustomPcaKeys(item["custom_pca"])
def itemSelected(self):
selected_item = self.getSelectedItem()
if selected_item is not None:
self.dataTypeKeySelected.emit(selected_item)
def getSelectedItem(self):
""" @rtype: str """
index = self.data_type_keys_widget.currentIndex()
source_index = self.filter_model.mapToSource(index)
item = self.model.itemAt(source_index)
return item
def selectDefault(self):
self.data_type_keys_widget.setCurrentIndex(self.filter_model.index(0, 0))
def setSearchString(self, filter):
self.filter_model.setFilterFixedString(filter)
def showFilterPopup(self):
self.__filter_popup.show()
示例3: DesktopIconWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
#.........这里部分代码省略.........
def createShortcut(self):
d = ShortcutDialog(self)
if self.window().runDialog(d.create) == QDialog.Accepted:
shortcut = d.getResult()
shortcut["id"] = str(uuid.uuid4())
self.quickDesktopModel.addShortcut(shortcut)
d.deleteLater()
def createBookmark(self):
d = BookmarkDialog(self)
if self.window().runDialog(d.create) == QDialog.Accepted:
shortcut = {
"id": str(uuid.uuid4()),
"icon": "",
"openwith": "",
"dir": "",
}
shortcut.update(d.getResult())
self.quickDesktopModel.addShortcut(shortcut)
d.deleteLater()
def createComputerShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.trUtf8("我的电脑"),
"path": COMPUTER_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def createDocumentsShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.trUtf8("我的文档"),
"path": DOCUMENTS_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def createPicturesShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.trUtf8("图片收藏"),
"path": PICTURES_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def createMusicShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.trUtf8("我的音乐"),
"path": MUSIC_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def renameShortcut(self):
self.listView.edit(self.listView.currentIndex())
def removeShortcut(self):
self.quickDesktopModel.removeShortcut(self.listView.currentIndex())
def editShortcut(self):
index = self.listView.currentIndex()
if not index.isValid():
return
shortcut = self.quickDesktopModel.shortcutAt(index)
url = QUrl.fromUserInput(shortcut["path"])
if not url.isValid():
return
if url.scheme() == "special":
QMessageBox.information(self, self.trUtf8("编辑快捷方式"), self.trUtf8("不能编辑特殊图标。"))
return
elif url.scheme() == "file":
d = ShortcutDialog(self)
else:
d = BookmarkDialog(self)
if self.window().runDialog(d.edit, shortcut) == QDialog.Accepted:
shortcut.update(d.getResult())
self.quickDesktopModel.updateShortcut(shortcut, index)
d.deleteLater()
def runQuickDesktopShortcut(self):
index = self.listView.currentIndex()
if not index.isValid():
return
if not self.quickDesktopModel.runShortcut(index):
QMessageBox.information(self, self.trUtf8("快捷面板"), \
self.trUtf8("不能运行快捷方式。请检查文件是否存在或者程序是否正确。"))
else:
self.window().close()
示例4: SortedListWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
#.........这里部分代码省略.........
self._upButton = QToolButton(self)
self._upButton.setDefaultAction(self._upAction)
self._upButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
self._downAction = QAction(
"\u2193", self, toolTip="Move down")
self._downButton = QToolButton(self)
self._downButton.setDefaultAction(self._downAction)
self._downButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
vButtonLayout.addWidget(self._upButton)
vButtonLayout.addWidget(self._downButton)
gridLayout.addLayout(vButtonLayout, 0, 2, 2, 1)
hButtonLayout = QHBoxLayout()
self._addAction = QAction("+", self)
self._addButton = QToolButton(self)
self._addButton.setDefaultAction(self._addAction)
self._removeAction = QAction("-", self)
self._removeButton = QToolButton(self)
self._removeButton.setDefaultAction(self._removeAction)
hButtonLayout.addWidget(self._addButton)
hButtonLayout.addWidget(self._removeButton)
hButtonLayout.addStretch(10)
gridLayout.addLayout(hButtonLayout, 2, 0, 1, 2)
self.setLayout(gridLayout)
self._addAction.triggered.connect(self._onAddAction)
self._removeAction.triggered.connect(self._onRemoveAction)
self._upAction.triggered.connect(self._onUpAction)
self._downAction.triggered.connect(self._onDownAction)
def sizeHint(self):
size = QWidget.sizeHint(self)
return QSize(size.width(), 100)
def _onAddAction(self):
item = QStandardItem("")
item.setFlags(item.flags() ^ Qt.ItemIsDropEnabled)
self._listView.model().appendRow(item)
self._listView.setCurrentIndex(item.index())
self._listView.edit(item.index())
def _onRemoveAction(self):
current = self._listView.currentIndex()
self._listView.model().takeRow(current.row())
def _onUpAction(self):
row = self._listView.currentIndex().row()
model = self._listView.model()
if row > 0:
items = model.takeRow(row)
model.insertRow(row - 1, items)
self._listView.setCurrentIndex(model.index(row - 1, 0))
def _onDownAction(self):
row = self._listView.currentIndex().row()
model = self._listView.model()
if row < model.rowCount() and row >= 0:
items = model.takeRow(row)
if row == model.rowCount():
model.appendRow(items)
else:
model.insertRow(row + 1, items)
self._listView.setCurrentIndex(model.index(row + 1, 0))
def setModel(self, model):
""" Set a model to select items from
"""
self._model = model
self._listView.setItemDelegate(self._MyItemDelegate(self._model, self))
def addItem(self, *args):
""" Add a new entry in the list
"""
item = QStandardItem(*args)
item.setFlags(item.flags() ^ Qt.ItemIsDropEnabled)
self._listView.model().appendRow(item)
def setItems(self, items):
self._listView.model().clear()
for item in items:
self.addItem(item)
def items(self):
order = []
for row in range(self._listView.model().rowCount()):
order.append(str(self._listView.model().item(row, 0).text()))
return order
def __changed(self):
self.sortingOrderChanged.emit()
sortingOrder = property(items, setItems)
示例5: SelectionSetsWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
#.........这里部分代码省略.........
QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
self._addToolButton.setDefaultAction(self._addAction)
self._updateToolButton.setDefaultAction(self._updateAction)
self._removeToolButton.setDefaultAction(self._removeAction)
buttonLayout.addWidget(self._addToolButton)
buttonLayout.addWidget(self._updateToolButton)
buttonLayout.addWidget(self._removeToolButton)
layout.addLayout(buttonLayout)
self.setLayout(layout)
self._addAction.triggered.connect(self.addCurrentSelection)
self._updateAction.triggered.connect(self.updateSelectedSelection)
self._removeAction.triggered.connect(self.removeSelectedSelection)
self._setListView.selectionModel().selectionChanged.connect(
self._onListViewSelectionChanged)
self.selectionModel = None
self._selections = []
def sizeHint(self):
size = QFrame.sizeHint(self)
return QSize(size.width(), 200)
def _onSelectionChanged(self, selected, deselected):
self.setSelectionModified(True)
def _onListViewSelectionChanged(self, selected, deselected):
try:
index = self._setListView.selectedIndexes()[0]
except IndexError:
return
self.commitSelection(self._proxyModel.mapToSource(index).row())
def _onSetNameChange(self, item):
self.selections[item.row()].name = str(item.text())
def _setButtonStates(self, val):
self._updateToolButton.setEnabled(val)
def setSelectionModel(self, selectionModel):
if self.selectionModel:
self.selectionModel.selectionChanged.disconnect(
self._onSelectionChanged)
self.selectionModel = selectionModel
self.selectionModel.selectionChanged.connect(self._onSelectionChanged)
def addCurrentSelection(self):
item = self.addSelection(
SelectionByKey(self.selectionModel.selection(),
name="New selection",
key=(1, 2, 3, 10)))
index = self._proxyModel.mapFromSource(item.index())
self._setListView.setCurrentIndex(index)
self._setListView.edit(index)
self.setSelectionModified(False)
def removeSelectedSelection(self):
i = self._proxyModel.mapToSource(self._setListView.currentIndex()).row()
self._listModel.takeRow(i)
del self.selections[i]
def updateCurentSelection(self):
i = self._proxyModel.mapToSource(self._setListView.selectedIndex()).row()
self.selections[i].setSelection(self.selectionModel.selection())
self.setSelectionModified(False)
def addSelection(self, selection, name=""):
self._selections.append(selection)
item = QStandardItem(selection.name)
item.setFlags(item.flags() ^ Qt.ItemIsDropEnabled)
self._listModel.appendRow(item)
self.setSelectionModified(False)
return item
def updateSelectedSelection(self):
i = self._proxyModel.mapToSource(self._setListView.currentIndex()).row()
self.selections[i].setSelection(self.selectionModel.selection())
self.setSelectionModified(False)
def setSelectionModified(self, val):
self._selectionModified = val
self._setButtonStates(val)
self.selectionModified.emit(bool(val))
def commitSelection(self, index):
selection = self.selections[index]
selection.select(self.selectionModel)
def setSelections(self, selections):
self._listModel.clear()
for selection in selections:
self.addSelection(selection)
def selections(self):
return self._selections
selections = property(selections, setSelections)
示例6: DataTypeKeysWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
class DataTypeKeysWidget(QWidget):
dataTypeKeySelected = pyqtSignal(str)
def __init__(self):
QWidget.__init__(self)
layout = QVBoxLayout()
self.model = DataTypeKeysListModel()
self.filter_model = DataTypeProxyModel(self.model)
self.search_box = SearchBox()
self.search_box.filterChanged.connect(self.setSearchString)
layout.addWidget(self.search_box)
data_type_model = QStandardItemModel(0, 1)
item = QStandardItem("Select data types...")
data_type_model.appendRow(item)
self.__summary_item = QStandardItem("Summary")
self.__summary_item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
self.__summary_item.setData(Qt.Checked, Qt.CheckStateRole)
data_type_model.appendRow(self.__summary_item)
self.__block_item = QStandardItem("Block")
self.__block_item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
self.__block_item.setData(Qt.Checked, Qt.CheckStateRole)
data_type_model.appendRow(self.__block_item)
data_type_model.itemChanged.connect(self.onItemChanged)
combo = QComboBox()
combo.setModel(data_type_model)
layout.addWidget(combo)
self.data_type_keys_widget = QListView()
self.data_type_keys_widget.setModel(self.filter_model)
self.data_type_keys_widget.selectionModel().selectionChanged.connect(self.itemSelected)
layout.addSpacing(15)
layout.addWidget(self.data_type_keys_widget, 2)
layout.addWidget(Legend("Default types", DataTypeKeysListModel.DEFAULT_DATA_TYPE))
layout.addWidget(Legend("Observations available", DataTypeKeysListModel.HAS_OBSERVATIONS))
self.setLayout(layout)
def onItemChanged(self, item):
assert isinstance(item, QStandardItem)
checked = item.checkState()==Qt.Checked
if item == self.__block_item:
self.filter_model.setShowBlockKeys(checked)
elif item == self.__summary_item:
self.filter_model.setShowSummaryKeys(checked)
def itemSelected(self):
selected_item = self.getSelectedItem()
if selected_item is not None:
self.dataTypeKeySelected.emit(selected_item)
def getSelectedItem(self):
""" @rtype: str """
index = self.data_type_keys_widget.currentIndex()
source_index = self.filter_model.mapToSource(index)
item = self.model.itemAt(source_index)
return item
def selectDefault(self):
self.data_type_keys_widget.setCurrentIndex(self.filter_model.index(0, 0))
def setSearchString(self, filter):
self.filter_model.setFilterFixedString(filter)
示例7: MainWindow
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setupGUI()
self.job_monitor = HadoopJobMonitor()
def setupGUI(self):
layout = QGridLayout()
self.widget = QWidget()
self.widget.setLayout(layout)
self.setCentralWidget(self.widget)
self.setWindowTitle("Nutch Job Service")
# create active job list
active_label = QLabel("Active Hadoop Jobs")
layout.addWidget(active_label, 0, 0)
self.lv = QListView()
layout.addWidget(self.lv, 1, 0, 3, 1)
# Create buttons
self.stop_button = QPushButton("Stop")
self.refresh_button = QPushButton("Refresh")
button_layout = QVBoxLayout()
button_layout.addWidget(self.stop_button)
button_layout.addWidget(self.refresh_button)
layout.addLayout(button_layout, 1, 1)
# Start Button
self.new_job_layout = QHBoxLayout()
self.new_job_combo = QComboBox()
self.new_job_combo.addItems(["Inject", "Generate", "Fetch", "Parse", "Solr"])
self.new_job_button = QPushButton("Start New Job")
self.new_job_layout.addWidget(self.new_job_combo)
self.new_job_layout.addWidget(self.new_job_button)
layout.addLayout(self.new_job_layout, 5, 0)
# self.statusBar()
self.connectSlots()
def load_data(self):
"""
Loads data from the hadoop job list.
"""
self.showStatusMessage("Fetching Hadoop job list...")
print "Loading data..."
self.job_monitor.fetch_hadoop_job_info()
self.job_list_model = JobListModel(self.job_monitor, self)
self.lv.setModel(self.job_list_model)
self.updateStatusBar()
def start_new_nob(self):
"""
Starts a new job according to the selected item in combo box.
"""
current_text = self.new_job_combo.currentText()
print "Starting %s" % current_text
def stop_job(self):
current_item = self.lv.currentIndex().data(0).toString()
job_object = self.job_list_model.get_job_object(current_item)
job_object.stop()
def connectSlots(self):
"""
Connects signals to slots.
"""
self.connect(self.refresh_button, SIGNAL("clicked()"), self.load_data)
self.connect(self.stop_button, SIGNAL("clicked()"), self.stop_job)
self.connect(self.new_job_button, SIGNAL("clicked()"), self.start_new_nob)
def showStatusMessage(self, message):
self.statusBar().showMessage(message)
def updateStatusBar(self):
"""
Updates status bar according to the number of active hadoop jobs.
"""
self.statusBar().showMessage("%s jobs are active." % self.job_monitor.num_jobs)
示例8: DirectoryWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import currentIndex [as 别名]
#.........这里部分代码省略.........
index1 = self.listView.rootIndex()
index2 = self.proxyModel.mapToSource(index1)
self.lineEdit.setText(self.model.filePath(index2))
self.listView.setCurrentIndex(index1)
def customContext(self, pos):
index = self.listView.indexAt(pos)
index = self.proxyModel.mapToSource(index)
if not index.isValid():
self.rmAction.setEnabled(False)
self.openAction.setEnabled(False)
self.loadAction.setEnabled(False)
elif not self.model.isDir(index):
info = self.model.fileInfo(index)
suffix = info.suffix()
if suffix in ("Rd","Rdata","RData"):
self.loadAction.setEnabled(True)
self.openAction.setEnabled(False)
self.loadExternal.setEnabled(False)
elif suffix in ("txt","csv","R","r"):
self.openAction.setEnabled(True)
self.loadAction.setEnabled(False)
self.loadExternal.setEnabled(True)
else:
self.loadAction.setEnabled(False)
self.openAction.setEnabled(False)
self.loadExternal.setEnabled(True)
menu = QMenu(self)
for action in self.actions:
menu.addAction(action)
menu.exec_(self.listView.mapToGlobal(pos))
def openItem(self):
index = self.listView.currentIndex()
index = self.proxyModel.mapToSource(index)
self.emit(SIGNAL("openFileRequest(QString)"),
self.model.filePath(index))
def loadItem(self):
index = self.listView.currentIndex()
index = self.proxyModel.mapToSource(index)
self.emit(SIGNAL("loadFileRequest(QString)"),
self.model.filePath(index))
def externalItem(self):
index = self.listView.currentIndex()
index = self.proxyModel.mapToSource(index)
QDesktopServices.openUrl(QUrl(self.model.filePath(index)))
def newFolder(self):
text, ok = QInputDialog.getText(self,
"New Folder", "Folder name:", QLineEdit.Normal,
"new_folder")
if ok:
index = self.listView.rootIndex()
index = self.proxyModel.mapToSource(index)
self.model.mkdir(index, text)
def setFolder(self):
index = self.listView.currentIndex()
index = self.proxyModel.mapToSource(index)
commands = "setwd('%s')" % self.model.filePath(index)
self.emitCommands(commands)
def rmItem(self):
index = self.listView.currentIndex()