DataViews/CodeMetricsDialog.py

changeset 570
43a680c5c8e6
parent 454
d28d558f7484
child 791
9ec2ac20e54e
equal deleted inserted replaced
565:21191e634b47 570:43a680c5c8e6
6 """ 6 """
7 Module implementing a code metrics dialog. 7 Module implementing a code metrics dialog.
8 """ 8 """
9 9
10 import os 10 import os
11 import fnmatch
11 12
12 from PyQt4.QtCore import * 13 from PyQt4.QtCore import *
13 from PyQt4.QtGui import * 14 from PyQt4.QtGui import *
14 15
15 from .Ui_CodeMetricsDialog import Ui_CodeMetricsDialog 16 from .Ui_CodeMetricsDialog import Ui_CodeMetricsDialog
16 from . import CodeMetrics 17 from . import CodeMetrics
18
17 import Utilities 19 import Utilities
20
21 import UI.PixmapCache
18 22
19 class CodeMetricsDialog(QDialog, Ui_CodeMetricsDialog): 23 class CodeMetricsDialog(QDialog, Ui_CodeMetricsDialog):
20 """ 24 """
21 Class implementing a dialog to display the code metrics. 25 Class implementing a dialog to display the code metrics.
22 """ 26 """
44 self.__menu.addAction(self.trUtf8("Collapse all"), self.__resultCollapse) 48 self.__menu.addAction(self.trUtf8("Collapse all"), self.__resultCollapse)
45 self.__menu.addAction(self.trUtf8("Expand all"), self.__resultExpand) 49 self.__menu.addAction(self.trUtf8("Expand all"), self.__resultExpand)
46 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) 50 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu)
47 self.resultList.customContextMenuRequested.connect(self.__showContextMenu) 51 self.resultList.customContextMenuRequested.connect(self.__showContextMenu)
48 52
53 self.__fileList = []
54 self.__project = None
55 self.clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png"))
56 self.filterFrame.setVisible(False)
57
49 def __resizeResultColumns(self): 58 def __resizeResultColumns(self):
50 """ 59 """
51 Private method to resize the list columns. 60 Private method to resize the list columns.
52 """ 61 """
53 self.resultList.header().resizeSections(QHeaderView.ResizeToContents) 62 self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
82 @param col1 string for column 1 (string) 91 @param col1 string for column 1 (string)
83 """ 92 """
84 itm = QTreeWidgetItem(self.summaryList, [col0, col1]) 93 itm = QTreeWidgetItem(self.summaryList, [col0, col1])
85 itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight)) 94 itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight))
86 95
96 def prepare(self, fileList, project):
97 """
98 Public method to prepare the dialog with a list of filenames.
99
100 @param fileList list of filenames (list of strings)
101 @param project reference to the project object (Project)
102 """
103 self.__fileList = fileList[:]
104 self.__project = project
105
106 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
107 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
108 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
109
110 self.filterFrame.setVisible(True)
111
112 self.__data = self.__project.getData("OTHERTOOLSPARMS", "CodeMetrics")
113 if self.__data is None or "ExcludeFiles" not in self.__data:
114 self.__data = {"ExcludeFiles" : ""}
115 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"])
116
87 def start(self, fn): 117 def start(self, fn):
88 """ 118 """
89 Public slot to start the code metrics determination. 119 Public slot to start the code metrics determination.
90 120
91 @param fn file or list of files or directory to be show 121 @param fn file or list of files or directory to show
92 the code metrics for (string or list of strings) 122 the code metrics for (string or list of strings)
93 """ 123 """
124 self.cancelled = False
125 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
126 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
127 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
128 QApplication.processEvents()
129
94 loc = QLocale() 130 loc = QLocale()
95 if isinstance(fn, list): 131 if isinstance(fn, list):
96 files = fn 132 files = fn
97 elif os.path.isdir(fn): 133 elif os.path.isdir(fn):
98 files = Utilities.direntries(fn, True, '*.py', False) 134 files = Utilities.direntries(fn, True, '*.py', False)
198 if button == self.buttonBox.button(QDialogButtonBox.Close): 234 if button == self.buttonBox.button(QDialogButtonBox.Close):
199 self.close() 235 self.close()
200 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 236 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
201 self.__finish() 237 self.__finish()
202 238
239 @pyqtSlot()
240 def on_startButton_clicked(self):
241 """
242 Private slot to start a code metrics run.
243 """
244 fileList = self.__fileList[:]
245
246 filterString = self.excludeFilesEdit.text()
247 if "ExcludeFiles" not in self.__data or \
248 filterString != self.__data["ExcludeFiles"]:
249 self.__data["ExcludeFiles"] = filterString
250 self.__project.setData("OTHERTOOLSPARMS", "CodeMetrics", self.__data)
251 filterList = filterString.split(",")
252 if filterList:
253 for filter in filterList:
254 fileList = \
255 [f for f in fileList if not fnmatch.fnmatch(f, filter.strip())]
256
257 self.resultList.clear()
258 self.summaryList.clear()
259 self.start(fileList)
260
203 def __showContextMenu(self, coord): 261 def __showContextMenu(self, coord):
204 """ 262 """
205 Private slot to show the context menu of the listview. 263 Private slot to show the context menu of the listview.
206 264
207 @param coord the position of the mouse pointer (QPoint) 265 @param coord the position of the mouse pointer (QPoint)

eric ide

mercurial