eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

branch
maintenance
changeset 8176
31965986ecd1
parent 8166
bd5cd5858503
child 8186
655b658aa7ee
equal deleted inserted replaced
8153:e01ae92db699 8176:31965986ecd1
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']
80 "CheckerCategories", 80 "CheckerCategories",
81 "Miscellaneous"), 81 "Miscellaneous"),
82 "N": QCoreApplication.translate( 82 "N": QCoreApplication.translate(
83 "CheckerCategories", 83 "CheckerCategories",
84 "Naming"), 84 "Naming"),
85 "P": QCoreApplication.translate(
86 "CheckerCategories",
87 "'pathlib' Usage"),
85 "S": QCoreApplication.translate( 88 "S": QCoreApplication.translate(
86 "CheckerCategories", 89 "CheckerCategories",
87 "Security"), 90 "Security"),
88 "W": QCoreApplication.translate( 91 "W": QCoreApplication.translate(
89 "CheckerCategories", 92 "CheckerCategories",
106 @param parent reference to the parent widget 109 @param parent reference to the parent widget
107 @type QWidget 110 @type QWidget
108 """ 111 """
109 super(CodeStyleCheckerDialog, self).__init__(parent) 112 super(CodeStyleCheckerDialog, self).__init__(parent)
110 self.setupUi(self) 113 self.setupUi(self)
111 self.setWindowFlags(Qt.Window) 114 self.setWindowFlags(Qt.WindowType.Window)
112 115
113 self.__project = project 116 self.__project = project
114 117
115 self.optionsTabWidget.setCurrentIndex(0) 118 self.optionsTabWidget.setCurrentIndex(0)
116 119
126 self.docTypeComboBox.addItem(self.tr("PEP-257"), "pep257") 129 self.docTypeComboBox.addItem(self.tr("PEP-257"), "pep257")
127 self.docTypeComboBox.addItem(self.tr("Eric"), "eric") 130 self.docTypeComboBox.addItem(self.tr("Eric"), "eric")
128 131
129 for category, text in CodeStyleCheckerDialog.checkCategories.items(): 132 for category, text in CodeStyleCheckerDialog.checkCategories.items():
130 itm = QListWidgetItem(text, self.categoriesList) 133 itm = QListWidgetItem(text, self.categoriesList)
131 itm.setData(Qt.UserRole, category) 134 itm.setData(Qt.ItemDataRole.UserRole, category)
132 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) 135 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable)
133 itm.setCheckState(Qt.Unchecked) 136 itm.setCheckState(Qt.CheckState.Unchecked)
134 137
135 for future in CodeStyleCheckerDialog.availableFutures: 138 for future in CodeStyleCheckerDialog.availableFutures:
136 itm = QListWidgetItem(future, self.futuresList) 139 itm = QListWidgetItem(future, self.futuresList)
137 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) 140 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable)
138 itm.setCheckState(Qt.Unchecked) 141 itm.setCheckState(Qt.CheckState.Unchecked)
139 142
140 self.dsaHighRiskCombo.addItems( 143 self.dsaHighRiskCombo.addItems(
141 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) 144 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa)
142 self.dsaMediumRiskCombo.addItems( 145 self.dsaMediumRiskCombo.addItems(
143 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) 146 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa)
151 CodeStyleCheckerDialog.cryptoBitSelectionsEc) 154 CodeStyleCheckerDialog.cryptoBitSelectionsEc)
152 155
153 self.statisticsButton.setEnabled(False) 156 self.statisticsButton.setEnabled(False)
154 self.showButton.setEnabled(False) 157 self.showButton.setEnabled(False)
155 self.cancelButton.setEnabled(True) 158 self.cancelButton.setEnabled(True)
156 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 159 self.buttonBox.button(
160 QDialogButtonBox.StandardButton.Close).setEnabled(False)
157 161
158 self.resultList.headerItem().setText(self.resultList.columnCount(), "") 162 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
159 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) 163 self.resultList.header().setSortIndicator(
164 0, Qt.SortOrder.AscendingOrder)
160 165
161 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus")) 166 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus"))
162 self.deleteBuiltinButton.setIcon(UI.PixmapCache.getIcon("minus")) 167 self.deleteBuiltinButton.setIcon(UI.PixmapCache.getIcon("minus"))
163 self.addWhitelistButton.setIcon(UI.PixmapCache.getIcon("plus")) 168 self.addWhitelistButton.setIcon(UI.PixmapCache.getIcon("plus"))
164 self.deleteWhitelistButton.setIcon(UI.PixmapCache.getIcon("minus")) 169 self.deleteWhitelistButton.setIcon(UI.PixmapCache.getIcon("minus"))
215 """ 220 """
216 if self.__errorItem is None: 221 if self.__errorItem is None:
217 self.__errorItem = QTreeWidgetItem(self.resultList, [ 222 self.__errorItem = QTreeWidgetItem(self.resultList, [
218 self.tr("Errors")]) 223 self.tr("Errors")])
219 self.__errorItem.setExpanded(True) 224 self.__errorItem.setExpanded(True)
220 self.__errorItem.setForeground(0, Qt.red) 225 self.__errorItem.setForeground(0, Qt.GlobalColor.red)
221 226
222 msg = "{0} ({1})".format(self.__project.getRelativePath(filename), 227 msg = "{0} ({1})".format(self.__project.getRelativePath(filename),
223 message) 228 message)
224 if not self.resultList.findItems(msg, Qt.MatchExactly): 229 if not self.resultList.findItems(msg, Qt.MatchFlag.MatchExactly):
225 itm = QTreeWidgetItem(self.__errorItem, [msg]) 230 itm = QTreeWidgetItem(self.__errorItem, [msg])
226 itm.setForeground(0, Qt.red) 231 itm.setForeground(0, Qt.GlobalColor.red)
227 itm.setFirstColumnSpanned(True) 232 itm.setFirstColumnSpanned(True)
228 233
229 def __createFileErrorItem(self, filename, message): 234 def __createFileErrorItem(self, filename, message):
230 """ 235 """
231 Private method to create an error entry for a given file. 236 Private method to create an error entry for a given file.
283 itm.setIcon(1, UI.PixmapCache.getIcon("warning")) 288 itm.setIcon(1, UI.PixmapCache.getIcon("warning"))
284 elif msgCode.startswith(("A", "N")): 289 elif msgCode.startswith(("A", "N")):
285 itm.setIcon(1, UI.PixmapCache.getIcon("namingError")) 290 itm.setIcon(1, UI.PixmapCache.getIcon("namingError"))
286 elif msgCode.startswith("D"): 291 elif msgCode.startswith("D"):
287 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError")) 292 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError"))
293 elif msgCode.startswith("P"):
294 itm.setIcon(1, UI.PixmapCache.getIcon("dirClosed"))
288 elif msgCode.startswith("S"): 295 elif msgCode.startswith("S"):
289 if "severity" in result: 296 if "severity" in result:
290 if result["severity"] == "H": 297 if result["severity"] == "H":
291 itm.setIcon(1, UI.PixmapCache.getIcon("securityLow")) 298 itm.setIcon(1, UI.PixmapCache.getIcon("securityLow"))
292 elif result["severity"] == "M": 299 elif result["severity"] == "M":
307 msgCode not in self.__noFixCodesList 314 msgCode not in self.__noFixCodesList
308 ): 315 ):
309 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable")) 316 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable"))
310 fixable = True 317 fixable = True
311 318
312 itm.setTextAlignment(0, Qt.AlignRight) 319 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
313 itm.setTextAlignment(1, Qt.AlignHCenter) 320 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignHCenter)
314 321
315 itm.setTextAlignment(0, Qt.AlignVCenter) 322 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignVCenter)
316 itm.setTextAlignment(1, Qt.AlignVCenter) 323 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignVCenter)
317 itm.setTextAlignment(2, Qt.AlignVCenter) 324 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignVCenter)
318 325
319 itm.setData(0, self.filenameRole, filename) 326 itm.setData(0, self.filenameRole, filename)
320 itm.setData(0, self.lineRole, int(result["line"])) 327 itm.setData(0, self.lineRole, int(result["line"]))
321 itm.setData(0, self.positionRole, int(result["offset"])) 328 itm.setData(0, self.positionRole, int(result["offset"]))
322 itm.setData(0, self.messageRole, result["display"]) 329 itm.setData(0, self.messageRole, result["display"])
410 """ 417 """
411 self.__fileOrFileList = fileList[:] 418 self.__fileOrFileList = fileList[:]
412 self.__project = project 419 self.__project = project
413 self.__forProject = True 420 self.__forProject = True
414 421
415 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 422 self.buttonBox.button(
416 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 423 QDialogButtonBox.StandardButton.Close).setEnabled(True)
424 self.buttonBox.button(
425 QDialogButtonBox.StandardButton.Close).setDefault(True)
417 self.cancelButton.setEnabled(False) 426 self.cancelButton.setEnabled(False)
418 427
419 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker") 428 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker")
420 if ( 429 if (
421 self.__data is None or 430 self.__data is None or
612 self.__project = e5App().getObject("Project") 621 self.__project = e5App().getObject("Project")
613 622
614 self.mainWidget.setCurrentWidget(self.progressTab) 623 self.mainWidget.setCurrentWidget(self.progressTab)
615 624
616 self.cancelled = False 625 self.cancelled = False
617 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 626 self.buttonBox.button(
627 QDialogButtonBox.StandardButton.Close).setEnabled(False)
618 self.cancelButton.setEnabled(True) 628 self.cancelButton.setEnabled(True)
619 self.cancelButton.setDefault(True) 629 self.cancelButton.setDefault(True)
620 self.statisticsButton.setEnabled(False) 630 self.statisticsButton.setEnabled(False)
621 self.showButton.setEnabled(False) 631 self.showButton.setEnabled(False)
622 self.fixButton.setEnabled(False) 632 self.fixButton.setEnabled(False)
1006 1016
1007 self.checkProgress.setValue(self.progress) 1017 self.checkProgress.setValue(self.progress)
1008 self.checkProgressLabel.setPath(fn) 1018 self.checkProgressLabel.setPath(fn)
1009 1019
1010 # remove file from the list of jobs to do 1020 # remove file from the list of jobs to do
1011 fileItems = self.progressList.findItems(fn, Qt.MatchExactly) 1021 fileItems = self.progressList.findItems(fn, Qt.MatchFlag.MatchExactly)
1012 if fileItems: 1022 if fileItems:
1013 row = self.progressList.row(fileItems[0]) 1023 row = self.progressList.row(fileItems[0])
1014 self.progressList.takeItem(row) 1024 self.progressList.takeItem(row)
1015 1025
1016 QApplication.processEvents() 1026 QApplication.processEvents()
1022 """ 1032 """
1023 if not self.__finished: 1033 if not self.__finished:
1024 self.__finished = True 1034 self.__finished = True
1025 1035
1026 self.cancelled = True 1036 self.cancelled = True
1027 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 1037 self.buttonBox.button(
1028 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 1038 QDialogButtonBox.StandardButton.Close).setEnabled(True)
1039 self.buttonBox.button(
1040 QDialogButtonBox.StandardButton.Close).setDefault(True)
1029 self.cancelButton.setEnabled(False) 1041 self.cancelButton.setEnabled(False)
1030 self.statisticsButton.setEnabled(True) 1042 self.statisticsButton.setEnabled(True)
1031 self.showButton.setEnabled(True) 1043 self.showButton.setEnabled(True)
1032 self.startButton.setEnabled(True) 1044 self.startButton.setEnabled(True)
1033 self.restartButton.setEnabled(True) 1045 self.restartButton.setEnabled(True)
1043 QApplication.processEvents() 1055 QApplication.processEvents()
1044 self.showButton.setEnabled(False) 1056 self.showButton.setEnabled(False)
1045 else: 1057 else:
1046 self.showButton.setEnabled(True) 1058 self.showButton.setEnabled(True)
1047 self.resultList.header().resizeSections( 1059 self.resultList.header().resizeSections(
1048 QHeaderView.ResizeToContents) 1060 QHeaderView.ResizeMode.ResizeToContents)
1049 self.resultList.header().setStretchLastSection(True) 1061 self.resultList.header().setStretchLastSection(True)
1050 1062
1051 self.checkProgress.setVisible(False) 1063 self.checkProgress.setVisible(False)
1052 self.checkProgressLabel.setVisible(False) 1064 self.checkProgressLabel.setVisible(False)
1053 1065
1175 @type bool 1187 @type bool
1176 """ 1188 """
1177 from .CodeStyleCodeSelectionDialog import CodeStyleCodeSelectionDialog 1189 from .CodeStyleCodeSelectionDialog import CodeStyleCodeSelectionDialog
1178 dlg = CodeStyleCodeSelectionDialog(edit.text(), categories, 1190 dlg = CodeStyleCodeSelectionDialog(edit.text(), categories,
1179 showFixCodes, self) 1191 showFixCodes, self)
1180 if dlg.exec() == QDialog.Accepted: 1192 if dlg.exec() == QDialog.DialogCode.Accepted:
1181 edit.setText(dlg.getSelectedCodes()) 1193 edit.setText(dlg.getSelectedCodes())
1182 1194
1183 @pyqtSlot() 1195 @pyqtSlot()
1184 def on_excludeMessagesSelectButton_clicked(self): 1196 def on_excludeMessagesSelectButton_clicked(self):
1185 """ 1197 """
1666 Private slot called by a button of the button box clicked. 1678 Private slot called by a button of the button box clicked.
1667 1679
1668 @param button button that was clicked 1680 @param button button that was clicked
1669 @type QAbstractButton 1681 @type QAbstractButton
1670 """ 1682 """
1671 if button == self.buttonBox.button(QDialogButtonBox.Close): 1683 if button == self.buttonBox.button(
1684 QDialogButtonBox.StandardButton.Close
1685 ):
1672 self.close() 1686 self.close()
1673 1687
1674 def __clearErrors(self, files): 1688 def __clearErrors(self, files):
1675 """ 1689 """
1676 Private method to clear all warning markers of open editors to be 1690 Private method to clear all warning markers of open editors to be
1772 else: 1786 else:
1773 expectedImports = [] 1787 expectedImports = []
1774 for row in range(self.futuresList.count()): 1788 for row in range(self.futuresList.count()):
1775 itm = self.futuresList.item(row) 1789 itm = self.futuresList.item(row)
1776 if itm.text() in expectedImports: 1790 if itm.text() in expectedImports:
1777 itm.setCheckState(Qt.Checked) 1791 itm.setCheckState(Qt.CheckState.Checked)
1778 else: 1792 else:
1779 itm.setCheckState(Qt.Unchecked) 1793 itm.setCheckState(Qt.CheckState.Unchecked)
1780 1794
1781 def __getSelectedFutureImports(self): 1795 def __getSelectedFutureImports(self):
1782 """ 1796 """
1783 Private method to get the expected future imports. 1797 Private method to get the expected future imports.
1784 1798
1786 @rtype str 1800 @rtype str
1787 """ 1801 """
1788 selectedFutures = [] 1802 selectedFutures = []
1789 for row in range(self.futuresList.count()): 1803 for row in range(self.futuresList.count()):
1790 itm = self.futuresList.item(row) 1804 itm = self.futuresList.item(row)
1791 if itm.checkState() == Qt.Checked: 1805 if itm.checkState() == Qt.CheckState.Checked:
1792 selectedFutures.append(itm.text()) 1806 selectedFutures.append(itm.text())
1793 return ", ".join(selectedFutures) 1807 return ", ".join(selectedFutures)
1794 1808
1795 def __initBuiltinsIgnoreList(self, builtinsIgnoreDict): 1809 def __initBuiltinsIgnoreList(self, builtinsIgnoreDict):
1796 """ 1810 """
1840 """ 1854 """
1841 from .CodeStyleAddBuiltinIgnoreDialog import ( 1855 from .CodeStyleAddBuiltinIgnoreDialog import (
1842 CodeStyleAddBuiltinIgnoreDialog 1856 CodeStyleAddBuiltinIgnoreDialog
1843 ) 1857 )
1844 dlg = CodeStyleAddBuiltinIgnoreDialog(self) 1858 dlg = CodeStyleAddBuiltinIgnoreDialog(self)
1845 if dlg.exec() == QDialog.Accepted: 1859 if dlg.exec() == QDialog.DialogCode.Accepted:
1846 left, right = dlg.getData() 1860 left, right = dlg.getData()
1847 QTreeWidgetItem(self.builtinsAssignmentList, [left, right]) 1861 QTreeWidgetItem(self.builtinsAssignmentList, [left, right])
1848 1862
1849 @pyqtSlot() 1863 @pyqtSlot()
1850 def on_deleteBuiltinButton_clicked(self): 1864 def on_deleteBuiltinButton_clicked(self):
1871 else: 1885 else:
1872 enabledCategoriesList = list( 1886 enabledCategoriesList = list(
1873 CodeStyleCheckerDialog.checkCategories.keys()) 1887 CodeStyleCheckerDialog.checkCategories.keys())
1874 for row in range(self.categoriesList.count()): 1888 for row in range(self.categoriesList.count()):
1875 itm = self.categoriesList.item(row) 1889 itm = self.categoriesList.item(row)
1876 if itm.data(Qt.UserRole) in enabledCategoriesList: 1890 if itm.data(Qt.ItemDataRole.UserRole) in enabledCategoriesList:
1877 itm.setCheckState(Qt.Checked) 1891 itm.setCheckState(Qt.CheckState.Checked)
1878 else: 1892 else:
1879 itm.setCheckState(Qt.Unchecked) 1893 itm.setCheckState(Qt.CheckState.Unchecked)
1880 1894
1881 def __getCategories(self, enabled, asList=False): 1895 def __getCategories(self, enabled, asList=False):
1882 """ 1896 """
1883 Private method to get the enabled or disabled checker categories. 1897 Private method to get the enabled or disabled checker categories.
1884 1898
1888 Python list 1902 Python list
1889 @type bool 1903 @type bool
1890 @return checker categories as a list or comma separated string 1904 @return checker categories as a list or comma separated string
1891 @rtype str or list of str 1905 @rtype str or list of str
1892 """ 1906 """
1893 state = Qt.Checked if enabled else Qt.Unchecked 1907 state = Qt.CheckState.Checked if enabled else Qt.CheckState.Unchecked
1894 1908
1895 checkerList = [] 1909 checkerList = []
1896 for row in range(self.categoriesList.count()): 1910 for row in range(self.categoriesList.count()):
1897 itm = self.categoriesList.item(row) 1911 itm = self.categoriesList.item(row)
1898 if itm.checkState() == state: 1912 if itm.checkState() == state:
1899 checkerList.append(itm.data(Qt.UserRole)) 1913 checkerList.append(itm.data(Qt.ItemDataRole.UserRole))
1900 if asList: 1914 if asList:
1901 return checkerList 1915 return checkerList
1902 else: 1916 else:
1903 return ", ".join(checkerList) 1917 return ", ".join(checkerList)
1904 1918
1994 """ 2008 """
1995 pattern, ok = QInputDialog.getText( 2009 pattern, ok = QInputDialog.getText(
1996 self, 2010 self,
1997 self.tr("Commented Code Whitelist Pattern"), 2011 self.tr("Commented Code Whitelist Pattern"),
1998 self.tr("Enter a Commented Code Whitelist Pattern"), 2012 self.tr("Enter a Commented Code Whitelist Pattern"),
1999 QLineEdit.Normal) 2013 QLineEdit.EchoMode.Normal)
2000 if ok and pattern: 2014 if ok and pattern:
2001 QListWidgetItem(pattern, self.whitelistWidget) 2015 QListWidgetItem(pattern, self.whitelistWidget)
2002 2016
2003 @pyqtSlot() 2017 @pyqtSlot()
2004 def on_deleteWhitelistButton_clicked(self): 2018 def on_deleteWhitelistButton_clicked(self):

eric ide

mercurial