9 |
9 |
10 import os |
10 import os |
11 import fnmatch |
11 import fnmatch |
12 |
12 |
13 from PyQt4.QtCore import pyqtSlot, Qt, QLocale, qVersion |
13 from PyQt4.QtCore import pyqtSlot, Qt, QLocale, qVersion |
14 from PyQt4.QtGui import QDialog, QDialogButtonBox, QMenu, QHeaderView, QTreeWidgetItem, \ |
14 from PyQt4.QtGui import QDialog, QDialogButtonBox, QMenu, QHeaderView, \ |
15 QApplication |
15 QTreeWidgetItem, QApplication |
16 |
16 |
17 from .Ui_CodeMetricsDialog import Ui_CodeMetricsDialog |
17 from .Ui_CodeMetricsDialog import Ui_CodeMetricsDialog |
18 from . import CodeMetrics |
18 from . import CodeMetrics |
19 |
19 |
20 import Utilities |
20 import Utilities |
34 self.setupUi(self) |
34 self.setupUi(self) |
35 |
35 |
36 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
36 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
37 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
37 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
38 |
38 |
39 self.summaryList.headerItem().setText(self.summaryList.columnCount(), "") |
39 self.summaryList.headerItem().setText( |
|
40 self.summaryList.columnCount(), "") |
40 self.summaryList.header().resizeSection(0, 200) |
41 self.summaryList.header().resizeSection(0, 200) |
41 self.summaryList.header().resizeSection(1, 100) |
42 self.summaryList.header().resizeSection(1, 100) |
42 |
43 |
43 self.resultList.headerItem().setText(self.resultList.columnCount(), "") |
44 self.resultList.headerItem().setText(self.resultList.columnCount(), "") |
44 |
45 |
45 self.cancelled = False |
46 self.cancelled = False |
46 |
47 |
47 self.__menu = QMenu(self) |
48 self.__menu = QMenu(self) |
48 self.__menu.addAction(self.trUtf8("Collapse all"), self.__resultCollapse) |
49 self.__menu.addAction(self.trUtf8("Collapse all"), |
|
50 self.__resultCollapse) |
49 self.__menu.addAction(self.trUtf8("Expand all"), self.__resultExpand) |
51 self.__menu.addAction(self.trUtf8("Expand all"), self.__resultExpand) |
50 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) |
52 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) |
51 self.resultList.customContextMenuRequested.connect(self.__showContextMenu) |
53 self.resultList.customContextMenuRequested.connect( |
|
54 self.__showContextMenu) |
52 |
55 |
53 self.__fileList = [] |
56 self.__fileList = [] |
54 self.__project = None |
57 self.__project = None |
55 self.filterFrame.setVisible(False) |
58 self.filterFrame.setVisible(False) |
56 |
59 |
180 self.__resizeResultColumns() |
183 self.__resizeResultColumns() |
181 |
184 |
182 # now do the summary stuff |
185 # now do the summary stuff |
183 docstrings = total['lines'] - total['comments'] - \ |
186 docstrings = total['lines'] - total['comments'] - \ |
184 total['empty lines'] - total['non-commentary lines'] |
187 total['empty lines'] - total['non-commentary lines'] |
185 self.__createSummaryItem(self.trUtf8("files"), loc.toString(total['files'])) |
188 self.__createSummaryItem(self.trUtf8("files"), |
186 self.__createSummaryItem(self.trUtf8("lines"), loc.toString(total['lines'])) |
189 loc.toString(total['files'])) |
187 self.__createSummaryItem(self.trUtf8("bytes"), loc.toString(total['bytes'])) |
190 self.__createSummaryItem(self.trUtf8("lines"), |
188 self.__createSummaryItem(self.trUtf8("comments"), loc.toString(total['comments'])) |
191 loc.toString(total['lines'])) |
|
192 self.__createSummaryItem(self.trUtf8("bytes"), |
|
193 loc.toString(total['bytes'])) |
|
194 self.__createSummaryItem(self.trUtf8("comments"), |
|
195 loc.toString(total['comments'])) |
189 self.__createSummaryItem(self.trUtf8("empty lines"), |
196 self.__createSummaryItem(self.trUtf8("empty lines"), |
190 loc.toString(total['empty lines'])) |
197 loc.toString(total['empty lines'])) |
191 self.__createSummaryItem(self.trUtf8("non-commentary lines"), |
198 self.__createSummaryItem(self.trUtf8("non-commentary lines"), |
192 loc.toString(total['non-commentary lines'])) |
199 loc.toString(total['non-commentary lines'])) |
193 self.__createSummaryItem(self.trUtf8("documentation lines"), |
200 self.__createSummaryItem(self.trUtf8("documentation lines"), |
213 v.append('') |
220 v.append('') |
214 return v |
221 return v |
215 |
222 |
216 def __finish(self): |
223 def __finish(self): |
217 """ |
224 """ |
218 Private slot called when the action finished or the user pressed the button. |
225 Private slot called when the action finished or the user pressed the |
|
226 button. |
219 """ |
227 """ |
220 self.cancelled = True |
228 self.cancelled = True |
221 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
229 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
222 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
230 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
223 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
231 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
224 |
232 |
225 if qVersion() >= "5.0.0": |
233 if qVersion() >= "5.0.0": |
226 self.resultList.header().setSectionResizeMode(QHeaderView.Interactive) |
234 self.resultList.header().setSectionResizeMode( |
227 self.summaryList.header().setSectionResizeMode(QHeaderView.Interactive) |
235 QHeaderView.Interactive) |
|
236 self.summaryList.header().setSectionResizeMode( |
|
237 QHeaderView.Interactive) |
228 else: |
238 else: |
229 self.resultList.header().setResizeMode(QHeaderView.Interactive) |
239 self.resultList.header().setResizeMode(QHeaderView.Interactive) |
230 self.summaryList.header().setResizeMode(QHeaderView.Interactive) |
240 self.summaryList.header().setResizeMode(QHeaderView.Interactive) |
231 |
241 |
232 def on_buttonBox_clicked(self, button): |
242 def on_buttonBox_clicked(self, button): |
249 |
259 |
250 filterString = self.excludeFilesEdit.text() |
260 filterString = self.excludeFilesEdit.text() |
251 if "ExcludeFiles" not in self.__data or \ |
261 if "ExcludeFiles" not in self.__data or \ |
252 filterString != self.__data["ExcludeFiles"]: |
262 filterString != self.__data["ExcludeFiles"]: |
253 self.__data["ExcludeFiles"] = filterString |
263 self.__data["ExcludeFiles"] = filterString |
254 self.__project.setData("OTHERTOOLSPARMS", "CodeMetrics", self.__data) |
264 self.__project.setData("OTHERTOOLSPARMS", "CodeMetrics", |
|
265 self.__data) |
255 filterList = filterString.split(",") |
266 filterList = filterString.split(",") |
256 if filterList: |
267 if filterList: |
257 for filter in filterList: |
268 for filter in filterList: |
258 fileList = \ |
269 fileList = [f for f in fileList |
259 [f for f in fileList if not fnmatch.fnmatch(f, filter.strip())] |
270 if not fnmatch.fnmatch(f, filter.strip())] |
260 |
271 |
261 self.resultList.clear() |
272 self.resultList.clear() |
262 self.summaryList.clear() |
273 self.summaryList.clear() |
263 self.start(fileList) |
274 self.start(fileList) |
264 |
275 |