22 sys.path.insert(0, os.path.dirname(__file__)) |
22 sys.path.insert(0, os.path.dirname(__file__)) |
23 |
23 |
24 from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale |
24 from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale |
25 from PyQt5.QtWidgets import ( |
25 from PyQt5.QtWidgets import ( |
26 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
26 QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, |
27 QApplication |
27 QApplication, QMenu |
28 ) |
28 ) |
29 |
29 |
30 from .Ui_CyclomaticComplexityDialog import Ui_CyclomaticComplexityDialog |
30 from .Ui_CyclomaticComplexityDialog import Ui_CyclomaticComplexityDialog |
31 from E5Gui.E5Application import e5App |
31 from E5Gui.E5Application import e5App |
32 |
32 |
96 "<tr><td><b>F</b></td><td>Function</td></tr>" |
96 "<tr><td><b>F</b></td><td>Function</td></tr>" |
97 "<tr><td><b>M</b></td><td>Method</td></tr>" |
97 "<tr><td><b>M</b></td><td>Method</td></tr>" |
98 "</table>" |
98 "</table>" |
99 )) |
99 )) |
100 |
100 |
|
101 self.__mappedType = { |
|
102 "class": "C", |
|
103 "function": "F", |
|
104 "method": "M", |
|
105 } |
|
106 self.__typeColors = { |
|
107 "class": Qt.blue, |
|
108 "function": Qt.darkCyan, |
|
109 "method": Qt.magenta, |
|
110 } |
101 self.__rankColors = { |
111 self.__rankColors = { |
102 "A": Qt.green, |
112 "A": Qt.green, |
103 "B": Qt.green, |
113 "B": Qt.green, |
104 "C": Qt.yellow, |
114 "C": Qt.yellow, |
105 "D": Qt.yellow, |
115 "D": Qt.yellow, |
106 "E": Qt.red, |
116 "E": Qt.red, |
107 "F": Qt.red, |
117 "F": Qt.red, |
108 } |
118 } |
|
119 |
|
120 self.__menu = QMenu(self) |
|
121 self.__menu.addAction(self.tr("Collapse all"), |
|
122 self.__resultCollapse) |
|
123 self.__menu.addAction(self.tr("Expand all"), self.__resultExpand) |
|
124 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) |
|
125 self.resultList.customContextMenuRequested.connect( |
|
126 self.__showContextMenu) |
109 |
127 |
110 def __resizeResultColumns(self): |
128 def __resizeResultColumns(self): |
111 """ |
129 """ |
112 Private method to resize the list columns. |
130 Private method to resize the list columns. |
113 """ |
131 """ |
147 "{0:6}".format(values["lineno"]), |
165 "{0:6}".format(values["lineno"]), |
148 ]) |
166 ]) |
149 itm.setTextAlignment(2, Qt.Alignment(Qt.AlignRight)) |
167 itm.setTextAlignment(2, Qt.Alignment(Qt.AlignRight)) |
150 itm.setTextAlignment(3, Qt.Alignment(Qt.AlignHCenter)) |
168 itm.setTextAlignment(3, Qt.Alignment(Qt.AlignHCenter)) |
151 itm.setTextAlignment(4, Qt.Alignment(Qt.AlignRight)) |
169 itm.setTextAlignment(4, Qt.Alignment(Qt.AlignRight)) |
152 if values["rank"] in ["A", "B", "C", "D", "E", "F"]: |
170 if values["rank"] in self.__rankColors: |
153 itm.setBackground(3, self.__rankColors[values["rank"]]) |
171 itm.setBackground(3, self.__rankColors[values["rank"]]) |
|
172 if values["type"] in self.__typeColors: |
|
173 itm.setForeground(0, self.__typeColors[values["type"]]) |
154 |
174 |
155 if "methods" in values: |
175 if "methods" in values: |
156 itm.setExpanded(True) |
176 itm.setExpanded(True) |
157 for method in values["methods"]: |
177 for method in values["methods"]: |
158 self.__createResultItem(itm, method) |
178 self.__createResultItem(itm, method) |
423 from radon.complexity import cc_rank |
437 from radon.complexity import cc_rank |
424 |
438 |
425 if not self.__finished: |
439 if not self.__finished: |
426 self.__finished = True |
440 self.__finished = True |
427 |
441 |
428 # reenable updates of the list |
442 # re-enable updates of the list |
429 self.resultList.setSortingEnabled(True) |
443 self.resultList.setSortingEnabled(True) |
|
444 self.resultList.sortItems(0, Qt.AscendingOrder) |
430 self.resultList.sortItems(1, Qt.AscendingOrder) |
445 self.resultList.sortItems(1, Qt.AscendingOrder) |
431 self.resultList.setUpdatesEnabled(True) |
446 self.resultList.setUpdatesEnabled(True) |
432 |
447 |
433 self.cancelled = True |
448 self.cancelled = True |
434 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
449 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
509 for filter in filterList: |
524 for filter in filterList: |
510 fileList = \ |
525 fileList = \ |
511 [f for f in fileList if not fnmatch.fnmatch(f, filter)] |
526 [f for f in fileList if not fnmatch.fnmatch(f, filter)] |
512 |
527 |
513 self.start(fileList) |
528 self.start(fileList) |
|
529 |
|
530 def __showContextMenu(self, coord): |
|
531 """ |
|
532 Private slot to show the context menu of the resultlist. |
|
533 |
|
534 @param coord the position of the mouse pointer (QPoint) |
|
535 """ |
|
536 if self.resultList.topLevelItemCount() > 0: |
|
537 self.__menu.popup(self.mapToGlobal(coord)) |
|
538 |
|
539 def __resultCollapse(self): |
|
540 """ |
|
541 Private slot to collapse all entries of the resultlist. |
|
542 """ |
|
543 for index in range(self.resultList.topLevelItemCount()): |
|
544 self.resultList.topLevelItem(index).setExpanded(False) |
|
545 |
|
546 def __resultExpand(self): |
|
547 """ |
|
548 Private slot to expand all entries of the resultlist. |
|
549 """ |
|
550 for index in range(self.resultList.topLevelItemCount()): |
|
551 self.resultList.topLevelItem(index).setExpanded(True) |