本文整理汇总了Python中PyQt5.QtWidgets.QTableWidget.sortByColumn方法的典型用法代码示例。如果您正苦于以下问题:Python QTableWidget.sortByColumn方法的具体用法?Python QTableWidget.sortByColumn怎么用?Python QTableWidget.sortByColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableWidget
的用法示例。
在下文中一共展示了QTableWidget.sortByColumn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Viewer
# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import sortByColumn [as 别名]
#.........这里部分代码省略.........
-----
SN2 Score: {}
DDRA Score: {}
IIDX EX Score: {}""".format(timings['W1'], timings['W2'], timings['W3'], timings['W4'],
timings['W5'], timings['Miss'],
parse.highscore_stat(song[step_counter], "Modifiers"),
parse.calculate_score_supernova2(song[step_counter]),
parse.calculate_score_ddra(song[step_counter]),
parse.calculate_score_iidx(song[step_counter]))
cell.setToolTip(tooltip)
self.table.setItem(current_row, current_column, cell)
# This exception is reached if a Song was played, but
# has no score (AutoPlay, PlayerAutoPlay)
except AttributeError:
cell = QTableWidgetItem()
self.table.setItem(current_row, current_column, cell)
step_counter = step_counter + 1
# If there are no scores for the current difficulty,
# add an empty cell instead
else:
cell = QTableWidgetItem()
self.table.setItem(current_row, current_column, cell)
# This exception is reached if we already reached the last
# score on a song (using step_counter)
except IndexError:
cell = QTableWidgetItem()
self.table.setItem(current_row, current_column, cell)
current_column = current_column + 1
current_row = current_row + 1
# Final table adjustments
self.table.resizeColumnsToContents()
self.table.setSortingEnabled(True)
self.table.sortByColumn(0, Qt.AscendingOrder)
def combobox_activated(self, combobox):
"""Sets the current game mode and regenerates the table."""
self.mode = combobox.currentText()
self.init_table()
def themebox_activated(self, combobox):
"""Sets the current grading system and regenerates the table."""
self.theme = combobox.currentText()
self.init_table()
def about_box(self):
"""Shows an about box with information about smtracker."""
text = ("<p>{desc} (version {vers})</p>"
"<p>Released under the terms of the <a href=\"http://www.gnu.org"
"/licenses/gpl-3.0.html\">GNU General Public License"
", version 3 or later</a></p>"
"<p>Icons provided by <a href=\"http://stepmania.com\">"
"StepMania</a> under the <a href=\"https://github.com/stepmania"
"/stepmania/blob/master/Docs/Licenses.txt\">MIT license</a></p>"
"<p><a href=\"{url}\">{url}</a></p>").format(
desc=smtracker.__description__,
vers=smtracker.__version__,
url=smtracker.__url__)
QMessageBox.information(self, "About smtracker", text)
def export_html(self):
示例2: LabelAssistDialog
# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import sortByColumn [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
示例3: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTableWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTableWidget import sortByColumn [as 别名]
def __init__(self, named_importances, *args, **kwargs):
super(VariableImportanceDialog, self).__init__(*args, **kwargs)
self.setWindowTitle("Variable Importance Table")
self.setMinimumWidth(700)
self.setMinimumHeight(800)
layout = QGridLayout()
layout.setContentsMargins(10, 10, 10, 10)
if named_importances:
# Show variable importance table
rows = len(list(named_importances.items()))
columns = 5
table = QTableWidget(rows, columns)
table.setHorizontalHeaderLabels(['Variable Name', 'Class #0', 'Class #1', 'Overall', 'Gini'])
table.verticalHeader().setVisible(False)
importances_mins = list(map(min, list(zip(*list(named_importances.values())))))
importances_maxs = list(map(max, list(zip(*list(named_importances.values())))))
for i, (variable, importances) in enumerate(named_importances.items()):
# Remove non-ASCII characters to get rid of the sigma character in the variable names.
variable = re.sub(r'[^\x00-\x7F]+','s', variable)
item = QTableWidgetItem(variable)
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
table.setItem(i, 0, item)
for j, importance in enumerate(importances):
# Get color based on the importance value
val = importances[j]
imin = importances_mins[j]
imax = importances_maxs[j]
range = importances_maxs[j] - importances_mins[j]
color = int( 255 - old_div(( (val-imin) * 200), range) )
# Load items as strings
item = QTableWidgetItemWithFloatSorting(str("{: .05f}".format(importance)))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
item.setBackground(QColor(color,255,color))
table.setItem(i, j+1, item)
table.resizeColumnsToContents()
table.setSortingEnabled(True)
table.sortByColumn(3, Qt.DescendingOrder) # Sort by overall importance
layout.addWidget(table, 1, 0, 3, 2)
else:
# Classifier is not trained. Show warning message.
msg = ('To enable this feature, you must choose the following classifier type via the menu Advanced > Classifier:\n\n'
'"Parallel Random Forest Classifier with Variable Importance (VIGRA)"\n\n'
'...and then RETRAIN your classifier (press "Live Update").')
warningLabel = QLabel(msg)
warningLabel.setAlignment(Qt.AlignCenter)
warningLabel.setWordWrap(True)
layout.addWidget(warningLabel, 3, 0, 1 ,2)
# Create and add close button
closeButton = QPushButton("Close")
closeButton.clicked.connect(self.close)
layout.addWidget(closeButton, 4, 1)
self.setLayout(layout)