src/eric7/CodeFormatting/BlackFormattingDialog.py

branch
eric7
changeset 9220
e9e7eca7efee
parent 9214
bd28e56047d7
child 9221
bf71ee032bb4
equal deleted inserted replaced
9219:964a326c58d4 9220:e9e7eca7efee
37 """ 37 """
38 Class implementing a dialog showing the code formatting progress and the result. 38 Class implementing a dialog showing the code formatting progress and the result.
39 """ 39 """
40 DataTypeRole = Qt.ItemDataRole.UserRole 40 DataTypeRole = Qt.ItemDataRole.UserRole
41 DataRole = Qt.ItemDataRole.UserRole + 1 41 DataRole = Qt.ItemDataRole.UserRole + 1
42
43 StatusColumn = 0
44 FileNameColumn = 1
42 45
43 def __init__(self, configuration, filesList, project=None, 46 def __init__(self, configuration, filesList, project=None,
44 action=BlackFormattingAction.Format, parent=None): 47 action=BlackFormattingAction.Format, parent=None):
45 """ 48 """
46 Constructor 49 Constructor
62 self.progressBar.setMaximum(len(filesList)) 65 self.progressBar.setMaximum(len(filesList))
63 self.progressBar.setValue(0) 66 self.progressBar.setValue(0)
64 67
65 self.resultsList.header().setSortIndicator(1, Qt.SortOrder.AscendingOrder) 68 self.resultsList.header().setSortIndicator(1, Qt.SortOrder.AscendingOrder)
66 69
70 self.statisticsGroup.setVisible(False)
71
67 self.__report = BlackReport(self) 72 self.__report = BlackReport(self)
68 self.__report.check = action is BlackFormattingAction.Check 73 self.__report.check = action is BlackFormattingAction.Check
69 self.__report.diff = action is BlackFormattingAction.Diff 74 self.__report.diff = action is BlackFormattingAction.Diff
70 75
71 self.__config = copy.deepcopy(configuration) 76 self.__config = copy.deepcopy(configuration)
72 self.__project = project 77 self.__project = project
73 self.__action = action 78 self.__action = action
74 79
75 self.__cancelled = False 80 self.__cancelled = False
76 self.__diffDialog = None 81 self.__diffDialog = None
82
83 self.__allFilter = self.tr("<all>")
77 84
78 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(True) 85 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
79 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) 86 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False)
80 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) 87 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True)
81 88
129 """ 136 """
130 self.resultsList.header().resizeSections( 137 self.resultsList.header().resizeSections(
131 QHeaderView.ResizeMode.ResizeToContents) 138 QHeaderView.ResizeMode.ResizeToContents)
132 self.resultsList.header().setStretchLastSection(True) 139 self.resultsList.header().setStretchLastSection(True)
133 140
141 def __populateStatusFilterCombo(self):
142 """
143 Private method to populate the status filter combo box with allowed selections.
144 """
145 allowedSelections = set()
146 for row in range(self.resultsList.topLevelItemCount()):
147 allowedSelections.add(
148 self.resultsList.topLevelItem(row).text(
149 BlackFormattingDialog.StatusColumn
150 )
151 )
152
153 self.statusFilterComboBox.addItem(self.__allFilter)
154 self.statusFilterComboBox.addItems(sorted(allowedSelections))
155
134 def __finish(self): 156 def __finish(self):
135 """ 157 """
136 Private method to perform some actions after the run was performed or canceled. 158 Private method to perform some actions after the run was performed or canceled.
137 """ 159 """
138 self.__resort() 160 self.__resort()
143 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) 165 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
144 166
145 self.progressBar.setVisible(False) 167 self.progressBar.setVisible(False)
146 168
147 self.__updateStatistics() 169 self.__updateStatistics()
170 self.__populateStatusFilterCombo()
148 171
149 def __updateStatistics(self): 172 def __updateStatistics(self):
150 """ 173 """
151 Private method to update the statistics about the recent formatting run. 174 Private method to update the statistics about the recent formatting run and
175 make them visible.
152 """ 176 """
153 self.reformattedLabel.setText( 177 self.reformattedLabel.setText(
154 self.tr("reformatted") 178 self.tr("reformatted")
155 if self.__action is BlackFormattingAction.Format else 179 if self.__action is BlackFormattingAction.Format else
156 self.tr("would reformat") 180 self.tr("would reformat")
163 self.excludedCountLabel.setText("{0:n}".format(self.__report.ignored_count)) 187 self.excludedCountLabel.setText("{0:n}".format(self.__report.ignored_count))
164 self.failuresCountLabel.setText("{0:n}".format(self.__report.failure_count)) 188 self.failuresCountLabel.setText("{0:n}".format(self.__report.failure_count))
165 self.processedCountLabel.setText("{0:n}".format(processed)) 189 self.processedCountLabel.setText("{0:n}".format(processed))
166 self.reformattedCountLabel.setText("{0:n}".format(self.__report.change_count)) 190 self.reformattedCountLabel.setText("{0:n}".format(self.__report.change_count))
167 self.unchangedCountLabel.setText("{0:n}".format(self.__report.same_count)) 191 self.unchangedCountLabel.setText("{0:n}".format(self.__report.same_count))
192
193 self.statisticsGroup.setVisible(True)
168 194
169 @pyqtSlot(QAbstractButton) 195 @pyqtSlot(QAbstractButton)
170 def on_buttonBox_clicked(self, button): 196 def on_buttonBox_clicked(self, button):
171 """ 197 """
172 Private slot to handle button presses of the dialog buttons. 198 Private slot to handle button presses of the dialog buttons.
321 @type QCloseEvent 347 @type QCloseEvent
322 """ 348 """
323 if self.__diffDialog is not None: 349 if self.__diffDialog is not None:
324 self.__diffDialog.close() 350 self.__diffDialog.close()
325 evt.accept() 351 evt.accept()
352
353 @pyqtSlot(str)
354 def on_statusFilterComboBox_currentTextChanged(self, status):
355 """
356 Private slot handling the selection of a status for items to be shown.
357
358 @param status selected status
359 @type str
360 """
361 for row in range(self.resultsList.topLevelItemCount()):
362 itm = self.resultsList.topLevelItem(row)
363 itm.setHidden(
364 status != self.__allFilter
365 and itm.text(BlackFormattingDialog.StatusColumn) != status
366 )
326 367
327 368
328 class BlackReport(black.Report): 369 class BlackReport(black.Report):
329 """ 370 """
330 Class extending the black Report to work with our dialog. 371 Class extending the black Report to work with our dialog.

eric ide

mercurial