本文整理汇总了Python中PyQt5.QtWidgets.QTableWidget.selectedIndexes方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidget.selectedIndexes方法的具体用法?Python QTableWidget.selectedIndexes怎么用?Python QTableWidget.selectedIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableWidget
的用法示例。
在下文中一共展示了QTableWidget.selectedIndexes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LabelAssistDialog
# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import selectedIndexes [as 别名]
#.........这里部分代码省略.........
box.show()
return
# Clear table
self.table.clearContents()
self.table.setRowCount(0)
self.table.setSortingEnabled(False)
self.progressBar.show()
self.computeButton.setEnabled(False)
def compute_features_for_frame(tIndex, t, features):
# Compute features and labels (called in parallel from request pool)
roi = [slice(None) for i in range(len(self.topLevelOperatorView.LabelImages.meta.shape))]
roi[tIndex] = slice(t, t+1)
roi = tuple(roi)
frame = self.topLevelOperatorView.SegmentationImages(roi).wait()
frame = frame.squeeze().astype(numpy.uint32, copy=False)
# Dirty trick: We don't care what we're passing here for the 'image' parameter,
# but vigra insists that we pass *something*, so we'll cast the label image as float32.
features[t] = vigra.analysis.extractRegionFeatures(frame.view(numpy.float32),
frame,
['Count'],
ignoreLabel=0)
tIndex = self.topLevelOperatorView.SegmentationImages.meta.axistags.index('t')
tMax = self.topLevelOperatorView.SegmentationImages.meta.shape[tIndex]
features = {}
labels = {}
def compute_all_features():
# Compute features in parallel
pool = RequestPool()
for t in range(tMax):
pool.add( Request( partial(compute_features_for_frame, tIndex, t, features) ) )
pool.wait()
# Compute labels
labels = self.topLevelOperatorView.LabelInputs([]).wait()
req = Request(compute_all_features)
req.notify_finished( partial(self._populateTable, features, labels) )
req.submit()
@threadRouted
def _populateTable(self, features, labels, *args):
self.progressBar.hide()
self.computeButton.setEnabled(True)
for time, feature in features.items():
# Insert row
rowNum = self.table.rowCount()
self.table.insertRow(self.table.rowCount())
# Get max and min object areas
areas = feature['Count']#objectFeatures['Standard Object Features']['Count']
maxObjArea = numpy.max(areas[numpy.nonzero(areas)])
minObjArea = numpy.min(areas[numpy.nonzero(areas)])
# Get number of labeled objects
labelNum = numpy.count_nonzero(labels[time])
# Load fram number
item = QTableWidgetItem(str(time))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 0, item)
# Load max object areas
item = QTableWidgetItemWithFloatSorting(str("{: .02f}".format(maxObjArea)))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 1, item)
# Load min object areas
item = QTableWidgetItemWithFloatSorting(str("{: .02f}".format(minObjArea)))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 2, item)
# Load label numbers
item = QTableWidgetItemWithFloatSorting(str("{: .01f}".format(labelNum)))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.table.setItem(rowNum, 3, item)
# Resize column size to fit dialog size
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
# Sort by max object area
self.table.setSortingEnabled(True)
self.table.sortByColumn(1, Qt.DescendingOrder)
def _captureDoubleClick(self):
# Navigate to selected frame
index = self.table.selectedIndexes()[0]
frameStr = self.table.model().data(index).toString()
if frameStr:
frameNum = int(frameStr)
self.parent().editor.posModel.time = frameNum
示例2: DPlayerUI
# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import selectedIndexes [as 别名]
#.........这里部分代码省略.........
def doubleClicked(self, item):
"""Play song at item's row."""
self.doubleClicked = True
self.lastPlayed = self.playlist.currentIndex()
if self.lastPlayed >= 0:
self.setStyle(self.lastPlayed, QFont.Normal)
self.currentPlaying = item.row()
self.playerCore.songChanged = True
self.playlist.setCurrentIndex(self.currentPlaying)
self.setStyle(self.currentPlaying, QFont.Bold)
self.stopClicked()
self.playClicked()
self.songLabel.setText('{} - {}'.format(
self.playlistTable.item(self.currentPlaying, 0).text(),
self.playlistTable.item(self.currentPlaying, 1).text()))
for index in range(4):
self.playlistTable.resizeColumnToContents(index)
def toSort(self, column):
"""Sort music by column."""
if self.lastPlayed >= 0:
self.setStyle(self.lastPlayed, QFont.Normal)
self.playerCore.sort(column, self.descendingOrder[column])
self.descendingOrder[column] = bool(1 - self.descendingOrder[column])
for index in range(4):
if index != column:
self.descendingOrder[index] = False
def deleteSongs(self):
"""Delete selected songs."""
selectedSongs = self.playlistTable.selectedIndexes()
indexes = [index.row() for index in selectedSongs]
toBeRemoved = sorted(indexes[::4], reverse=True)
currentIndex = self.playlist.currentIndex()
if currentIndex >= 0:
self.setStyle(currentIndex, QFont.Normal)
self.playerCore.remove(toBeRemoved)
for index in toBeRemoved:
self.playlistTable.removeRow(index)
if self.playlistTable.rowCount() == 0:
return
currentIndex = self.playlist.currentIndex()
if currentIndex >= 0:
self.setStyle(self.playlist.currentIndex(), QFont.Bold)
self.songLabel.setText('{} - {}'.format(
self.playlistTable.item(self.currentPlaying, 0).text(),
self.playlistTable.item(self.currentPlaying, 1).text()))
for index in range(4):
self.playlistTable.resizeColumnToContents(index)
def savePlaylist(self):
"""Save playlist."""
url, _ = QFileDialog.getSaveFileUrl(self, 'Save playlist')
self.playerCore.savePlaylist(url)
def loadPlaylist(self):
"""Load playlist."""