40 |
40 |
41 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog): |
41 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog): |
42 """ |
42 """ |
43 Class implementing a dialog to show the results of the code style check. |
43 Class implementing a dialog to show the results of the code style check. |
44 """ |
44 """ |
45 filenameRole = Qt.UserRole + 1 |
45 filenameRole = Qt.ItemDataRole.UserRole + 1 |
46 lineRole = Qt.UserRole + 2 |
46 lineRole = Qt.ItemDataRole.UserRole + 2 |
47 positionRole = Qt.UserRole + 3 |
47 positionRole = Qt.ItemDataRole.UserRole + 3 |
48 messageRole = Qt.UserRole + 4 |
48 messageRole = Qt.ItemDataRole.UserRole + 4 |
49 fixableRole = Qt.UserRole + 5 |
49 fixableRole = Qt.ItemDataRole.UserRole + 5 |
50 codeRole = Qt.UserRole + 6 |
50 codeRole = Qt.ItemDataRole.UserRole + 6 |
51 ignoredRole = Qt.UserRole + 7 |
51 ignoredRole = Qt.ItemDataRole.UserRole + 7 |
52 argsRole = Qt.UserRole + 8 |
52 argsRole = Qt.ItemDataRole.UserRole + 8 |
53 |
53 |
54 availableFutures = [ |
54 availableFutures = [ |
55 'division', 'absolute_import', 'with_statement', |
55 'division', 'absolute_import', 'with_statement', |
56 'print_function', 'unicode_literals', 'generator_stop', |
56 'print_function', 'unicode_literals', 'generator_stop', |
57 'annotations'] |
57 'annotations'] |
106 @param parent reference to the parent widget |
106 @param parent reference to the parent widget |
107 @type QWidget |
107 @type QWidget |
108 """ |
108 """ |
109 super(CodeStyleCheckerDialog, self).__init__(parent) |
109 super(CodeStyleCheckerDialog, self).__init__(parent) |
110 self.setupUi(self) |
110 self.setupUi(self) |
111 self.setWindowFlags(Qt.Window) |
111 self.setWindowFlags(Qt.WindowType.Window) |
112 |
112 |
113 self.__project = project |
113 self.__project = project |
114 |
114 |
115 self.optionsTabWidget.setCurrentIndex(0) |
115 self.optionsTabWidget.setCurrentIndex(0) |
116 |
116 |
126 self.docTypeComboBox.addItem(self.tr("PEP-257"), "pep257") |
126 self.docTypeComboBox.addItem(self.tr("PEP-257"), "pep257") |
127 self.docTypeComboBox.addItem(self.tr("Eric"), "eric") |
127 self.docTypeComboBox.addItem(self.tr("Eric"), "eric") |
128 |
128 |
129 for category, text in CodeStyleCheckerDialog.checkCategories.items(): |
129 for category, text in CodeStyleCheckerDialog.checkCategories.items(): |
130 itm = QListWidgetItem(text, self.categoriesList) |
130 itm = QListWidgetItem(text, self.categoriesList) |
131 itm.setData(Qt.UserRole, category) |
131 itm.setData(Qt.ItemDataRole.UserRole, category) |
132 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) |
132 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable) |
133 itm.setCheckState(Qt.Unchecked) |
133 itm.setCheckState(Qt.CheckState.Unchecked) |
134 |
134 |
135 for future in CodeStyleCheckerDialog.availableFutures: |
135 for future in CodeStyleCheckerDialog.availableFutures: |
136 itm = QListWidgetItem(future, self.futuresList) |
136 itm = QListWidgetItem(future, self.futuresList) |
137 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) |
137 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable) |
138 itm.setCheckState(Qt.Unchecked) |
138 itm.setCheckState(Qt.CheckState.Unchecked) |
139 |
139 |
140 self.dsaHighRiskCombo.addItems( |
140 self.dsaHighRiskCombo.addItems( |
141 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
141 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
142 self.dsaMediumRiskCombo.addItems( |
142 self.dsaMediumRiskCombo.addItems( |
143 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
143 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
151 CodeStyleCheckerDialog.cryptoBitSelectionsEc) |
151 CodeStyleCheckerDialog.cryptoBitSelectionsEc) |
152 |
152 |
153 self.statisticsButton.setEnabled(False) |
153 self.statisticsButton.setEnabled(False) |
154 self.showButton.setEnabled(False) |
154 self.showButton.setEnabled(False) |
155 self.cancelButton.setEnabled(True) |
155 self.cancelButton.setEnabled(True) |
156 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
156 self.buttonBox.button( |
|
157 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
157 |
158 |
158 self.resultList.headerItem().setText(self.resultList.columnCount(), "") |
159 self.resultList.headerItem().setText(self.resultList.columnCount(), "") |
159 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) |
160 self.resultList.header().setSortIndicator( |
|
161 0, Qt.SortOrder.AscendingOrder) |
160 |
162 |
161 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus")) |
163 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus")) |
162 self.deleteBuiltinButton.setIcon(UI.PixmapCache.getIcon("minus")) |
164 self.deleteBuiltinButton.setIcon(UI.PixmapCache.getIcon("minus")) |
163 self.addWhitelistButton.setIcon(UI.PixmapCache.getIcon("plus")) |
165 self.addWhitelistButton.setIcon(UI.PixmapCache.getIcon("plus")) |
164 self.deleteWhitelistButton.setIcon(UI.PixmapCache.getIcon("minus")) |
166 self.deleteWhitelistButton.setIcon(UI.PixmapCache.getIcon("minus")) |
215 """ |
217 """ |
216 if self.__errorItem is None: |
218 if self.__errorItem is None: |
217 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
219 self.__errorItem = QTreeWidgetItem(self.resultList, [ |
218 self.tr("Errors")]) |
220 self.tr("Errors")]) |
219 self.__errorItem.setExpanded(True) |
221 self.__errorItem.setExpanded(True) |
220 self.__errorItem.setForeground(0, Qt.red) |
222 self.__errorItem.setForeground(0, Qt.GlobalColor.red) |
221 |
223 |
222 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
224 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), |
223 message) |
225 message) |
224 if not self.resultList.findItems(msg, Qt.MatchExactly): |
226 if not self.resultList.findItems(msg, Qt.MatchFlag.MatchExactly): |
225 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
227 itm = QTreeWidgetItem(self.__errorItem, [msg]) |
226 itm.setForeground(0, Qt.red) |
228 itm.setForeground(0, Qt.GlobalColor.red) |
227 itm.setFirstColumnSpanned(True) |
229 itm.setFirstColumnSpanned(True) |
228 |
230 |
229 def __createFileErrorItem(self, filename, message): |
231 def __createFileErrorItem(self, filename, message): |
230 """ |
232 """ |
231 Private method to create an error entry for a given file. |
233 Private method to create an error entry for a given file. |
307 msgCode not in self.__noFixCodesList |
309 msgCode not in self.__noFixCodesList |
308 ): |
310 ): |
309 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable")) |
311 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable")) |
310 fixable = True |
312 fixable = True |
311 |
313 |
312 itm.setTextAlignment(0, Qt.AlignRight) |
314 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight) |
313 itm.setTextAlignment(1, Qt.AlignHCenter) |
315 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignHCenter) |
314 |
316 |
315 itm.setTextAlignment(0, Qt.AlignVCenter) |
317 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignVCenter) |
316 itm.setTextAlignment(1, Qt.AlignVCenter) |
318 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignVCenter) |
317 itm.setTextAlignment(2, Qt.AlignVCenter) |
319 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignVCenter) |
318 |
320 |
319 itm.setData(0, self.filenameRole, filename) |
321 itm.setData(0, self.filenameRole, filename) |
320 itm.setData(0, self.lineRole, int(result["line"])) |
322 itm.setData(0, self.lineRole, int(result["line"])) |
321 itm.setData(0, self.positionRole, int(result["offset"])) |
323 itm.setData(0, self.positionRole, int(result["offset"])) |
322 itm.setData(0, self.messageRole, result["display"]) |
324 itm.setData(0, self.messageRole, result["display"]) |
410 """ |
412 """ |
411 self.__fileOrFileList = fileList[:] |
413 self.__fileOrFileList = fileList[:] |
412 self.__project = project |
414 self.__project = project |
413 self.__forProject = True |
415 self.__forProject = True |
414 |
416 |
415 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
417 self.buttonBox.button( |
416 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
418 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
|
419 self.buttonBox.button( |
|
420 QDialogButtonBox.StandardButton.Close).setDefault(True) |
417 self.cancelButton.setEnabled(False) |
421 self.cancelButton.setEnabled(False) |
418 |
422 |
419 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker") |
423 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker") |
420 if ( |
424 if ( |
421 self.__data is None or |
425 self.__data is None or |
612 self.__project = e5App().getObject("Project") |
616 self.__project = e5App().getObject("Project") |
613 |
617 |
614 self.mainWidget.setCurrentWidget(self.progressTab) |
618 self.mainWidget.setCurrentWidget(self.progressTab) |
615 |
619 |
616 self.cancelled = False |
620 self.cancelled = False |
617 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
621 self.buttonBox.button( |
|
622 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
618 self.cancelButton.setEnabled(True) |
623 self.cancelButton.setEnabled(True) |
619 self.cancelButton.setDefault(True) |
624 self.cancelButton.setDefault(True) |
620 self.statisticsButton.setEnabled(False) |
625 self.statisticsButton.setEnabled(False) |
621 self.showButton.setEnabled(False) |
626 self.showButton.setEnabled(False) |
622 self.fixButton.setEnabled(False) |
627 self.fixButton.setEnabled(False) |
1006 |
1011 |
1007 self.checkProgress.setValue(self.progress) |
1012 self.checkProgress.setValue(self.progress) |
1008 self.checkProgressLabel.setPath(fn) |
1013 self.checkProgressLabel.setPath(fn) |
1009 |
1014 |
1010 # remove file from the list of jobs to do |
1015 # remove file from the list of jobs to do |
1011 fileItems = self.progressList.findItems(fn, Qt.MatchExactly) |
1016 fileItems = self.progressList.findItems(fn, Qt.MatchFlag.MatchExactly) |
1012 if fileItems: |
1017 if fileItems: |
1013 row = self.progressList.row(fileItems[0]) |
1018 row = self.progressList.row(fileItems[0]) |
1014 self.progressList.takeItem(row) |
1019 self.progressList.takeItem(row) |
1015 |
1020 |
1016 QApplication.processEvents() |
1021 QApplication.processEvents() |
1022 """ |
1027 """ |
1023 if not self.__finished: |
1028 if not self.__finished: |
1024 self.__finished = True |
1029 self.__finished = True |
1025 |
1030 |
1026 self.cancelled = True |
1031 self.cancelled = True |
1027 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
1032 self.buttonBox.button( |
1028 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
1033 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
|
1034 self.buttonBox.button( |
|
1035 QDialogButtonBox.StandardButton.Close).setDefault(True) |
1029 self.cancelButton.setEnabled(False) |
1036 self.cancelButton.setEnabled(False) |
1030 self.statisticsButton.setEnabled(True) |
1037 self.statisticsButton.setEnabled(True) |
1031 self.showButton.setEnabled(True) |
1038 self.showButton.setEnabled(True) |
1032 self.startButton.setEnabled(True) |
1039 self.startButton.setEnabled(True) |
1033 self.restartButton.setEnabled(True) |
1040 self.restartButton.setEnabled(True) |
1043 QApplication.processEvents() |
1050 QApplication.processEvents() |
1044 self.showButton.setEnabled(False) |
1051 self.showButton.setEnabled(False) |
1045 else: |
1052 else: |
1046 self.showButton.setEnabled(True) |
1053 self.showButton.setEnabled(True) |
1047 self.resultList.header().resizeSections( |
1054 self.resultList.header().resizeSections( |
1048 QHeaderView.ResizeToContents) |
1055 QHeaderView.ResizeMode.ResizeToContents) |
1049 self.resultList.header().setStretchLastSection(True) |
1056 self.resultList.header().setStretchLastSection(True) |
1050 |
1057 |
1051 self.checkProgress.setVisible(False) |
1058 self.checkProgress.setVisible(False) |
1052 self.checkProgressLabel.setVisible(False) |
1059 self.checkProgressLabel.setVisible(False) |
1053 |
1060 |
1175 @type bool |
1182 @type bool |
1176 """ |
1183 """ |
1177 from .CodeStyleCodeSelectionDialog import CodeStyleCodeSelectionDialog |
1184 from .CodeStyleCodeSelectionDialog import CodeStyleCodeSelectionDialog |
1178 dlg = CodeStyleCodeSelectionDialog(edit.text(), categories, |
1185 dlg = CodeStyleCodeSelectionDialog(edit.text(), categories, |
1179 showFixCodes, self) |
1186 showFixCodes, self) |
1180 if dlg.exec() == QDialog.Accepted: |
1187 if dlg.exec() == QDialog.DialogCode.Accepted: |
1181 edit.setText(dlg.getSelectedCodes()) |
1188 edit.setText(dlg.getSelectedCodes()) |
1182 |
1189 |
1183 @pyqtSlot() |
1190 @pyqtSlot() |
1184 def on_excludeMessagesSelectButton_clicked(self): |
1191 def on_excludeMessagesSelectButton_clicked(self): |
1185 """ |
1192 """ |
1666 Private slot called by a button of the button box clicked. |
1673 Private slot called by a button of the button box clicked. |
1667 |
1674 |
1668 @param button button that was clicked |
1675 @param button button that was clicked |
1669 @type QAbstractButton |
1676 @type QAbstractButton |
1670 """ |
1677 """ |
1671 if button == self.buttonBox.button(QDialogButtonBox.Close): |
1678 if button == self.buttonBox.button( |
|
1679 QDialogButtonBox.StandardButton.Close |
|
1680 ): |
1672 self.close() |
1681 self.close() |
1673 |
1682 |
1674 def __clearErrors(self, files): |
1683 def __clearErrors(self, files): |
1675 """ |
1684 """ |
1676 Private method to clear all warning markers of open editors to be |
1685 Private method to clear all warning markers of open editors to be |
1772 else: |
1781 else: |
1773 expectedImports = [] |
1782 expectedImports = [] |
1774 for row in range(self.futuresList.count()): |
1783 for row in range(self.futuresList.count()): |
1775 itm = self.futuresList.item(row) |
1784 itm = self.futuresList.item(row) |
1776 if itm.text() in expectedImports: |
1785 if itm.text() in expectedImports: |
1777 itm.setCheckState(Qt.Checked) |
1786 itm.setCheckState(Qt.CheckState.Checked) |
1778 else: |
1787 else: |
1779 itm.setCheckState(Qt.Unchecked) |
1788 itm.setCheckState(Qt.CheckState.Unchecked) |
1780 |
1789 |
1781 def __getSelectedFutureImports(self): |
1790 def __getSelectedFutureImports(self): |
1782 """ |
1791 """ |
1783 Private method to get the expected future imports. |
1792 Private method to get the expected future imports. |
1784 |
1793 |
1786 @rtype str |
1795 @rtype str |
1787 """ |
1796 """ |
1788 selectedFutures = [] |
1797 selectedFutures = [] |
1789 for row in range(self.futuresList.count()): |
1798 for row in range(self.futuresList.count()): |
1790 itm = self.futuresList.item(row) |
1799 itm = self.futuresList.item(row) |
1791 if itm.checkState() == Qt.Checked: |
1800 if itm.checkState() == Qt.CheckState.Checked: |
1792 selectedFutures.append(itm.text()) |
1801 selectedFutures.append(itm.text()) |
1793 return ", ".join(selectedFutures) |
1802 return ", ".join(selectedFutures) |
1794 |
1803 |
1795 def __initBuiltinsIgnoreList(self, builtinsIgnoreDict): |
1804 def __initBuiltinsIgnoreList(self, builtinsIgnoreDict): |
1796 """ |
1805 """ |
1840 """ |
1849 """ |
1841 from .CodeStyleAddBuiltinIgnoreDialog import ( |
1850 from .CodeStyleAddBuiltinIgnoreDialog import ( |
1842 CodeStyleAddBuiltinIgnoreDialog |
1851 CodeStyleAddBuiltinIgnoreDialog |
1843 ) |
1852 ) |
1844 dlg = CodeStyleAddBuiltinIgnoreDialog(self) |
1853 dlg = CodeStyleAddBuiltinIgnoreDialog(self) |
1845 if dlg.exec() == QDialog.Accepted: |
1854 if dlg.exec() == QDialog.DialogCode.Accepted: |
1846 left, right = dlg.getData() |
1855 left, right = dlg.getData() |
1847 QTreeWidgetItem(self.builtinsAssignmentList, [left, right]) |
1856 QTreeWidgetItem(self.builtinsAssignmentList, [left, right]) |
1848 |
1857 |
1849 @pyqtSlot() |
1858 @pyqtSlot() |
1850 def on_deleteBuiltinButton_clicked(self): |
1859 def on_deleteBuiltinButton_clicked(self): |
1871 else: |
1880 else: |
1872 enabledCategoriesList = list( |
1881 enabledCategoriesList = list( |
1873 CodeStyleCheckerDialog.checkCategories.keys()) |
1882 CodeStyleCheckerDialog.checkCategories.keys()) |
1874 for row in range(self.categoriesList.count()): |
1883 for row in range(self.categoriesList.count()): |
1875 itm = self.categoriesList.item(row) |
1884 itm = self.categoriesList.item(row) |
1876 if itm.data(Qt.UserRole) in enabledCategoriesList: |
1885 if itm.data(Qt.ItemDataRole.UserRole) in enabledCategoriesList: |
1877 itm.setCheckState(Qt.Checked) |
1886 itm.setCheckState(Qt.CheckState.Checked) |
1878 else: |
1887 else: |
1879 itm.setCheckState(Qt.Unchecked) |
1888 itm.setCheckState(Qt.CheckState.Unchecked) |
1880 |
1889 |
1881 def __getCategories(self, enabled, asList=False): |
1890 def __getCategories(self, enabled, asList=False): |
1882 """ |
1891 """ |
1883 Private method to get the enabled or disabled checker categories. |
1892 Private method to get the enabled or disabled checker categories. |
1884 |
1893 |
1888 Python list |
1897 Python list |
1889 @type bool |
1898 @type bool |
1890 @return checker categories as a list or comma separated string |
1899 @return checker categories as a list or comma separated string |
1891 @rtype str or list of str |
1900 @rtype str or list of str |
1892 """ |
1901 """ |
1893 state = Qt.Checked if enabled else Qt.Unchecked |
1902 state = Qt.CheckState.Checked if enabled else Qt.CheckState.Unchecked |
1894 |
1903 |
1895 checkerList = [] |
1904 checkerList = [] |
1896 for row in range(self.categoriesList.count()): |
1905 for row in range(self.categoriesList.count()): |
1897 itm = self.categoriesList.item(row) |
1906 itm = self.categoriesList.item(row) |
1898 if itm.checkState() == state: |
1907 if itm.checkState() == state: |
1899 checkerList.append(itm.data(Qt.UserRole)) |
1908 checkerList.append(itm.data(Qt.ItemDataRole.UserRole)) |
1900 if asList: |
1909 if asList: |
1901 return checkerList |
1910 return checkerList |
1902 else: |
1911 else: |
1903 return ", ".join(checkerList) |
1912 return ", ".join(checkerList) |
1904 |
1913 |
1994 """ |
2003 """ |
1995 pattern, ok = QInputDialog.getText( |
2004 pattern, ok = QInputDialog.getText( |
1996 self, |
2005 self, |
1997 self.tr("Commented Code Whitelist Pattern"), |
2006 self.tr("Commented Code Whitelist Pattern"), |
1998 self.tr("Enter a Commented Code Whitelist Pattern"), |
2007 self.tr("Enter a Commented Code Whitelist Pattern"), |
1999 QLineEdit.Normal) |
2008 QLineEdit.EchoMode.Normal) |
2000 if ok and pattern: |
2009 if ok and pattern: |
2001 QListWidgetItem(pattern, self.whitelistWidget) |
2010 QListWidgetItem(pattern, self.whitelistWidget) |
2002 |
2011 |
2003 @pyqtSlot() |
2012 @pyqtSlot() |
2004 def on_deleteWhitelistButton_clicked(self): |
2013 def on_deleteWhitelistButton_clicked(self): |