Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py

changeset 571
1a4101cb87eb
parent 564
b3d966393ba9
child 678
d388291f5b6c
equal deleted inserted replaced
570:43a680c5c8e6 571:1a4101cb87eb
6 """ 6 """
7 Module implementing a simple Python syntax checker. 7 Module implementing a simple Python syntax checker.
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 E5Gui.E5Application import e5App 16 from E5Gui.E5Application import e5App
51 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) 52 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder)
52 53
53 self.noResults = True 54 self.noResults = True
54 self.cancelled = False 55 self.cancelled = False
55 self.__lastFileItem = None 56 self.__lastFileItem = None
57
58 self.__fileList = []
59 self.__project = None
60 self.clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png"))
61 self.filterFrame.setVisible(False)
56 62
57 def __resort(self): 63 def __resort(self):
58 """ 64 """
59 Private method to resort the tree. 65 Private method to resort the tree.
60 """ 66 """
88 itm.setData(0, self.filenameRole, file) 94 itm.setData(0, self.filenameRole, file)
89 itm.setData(0, self.lineRole, int(line)) 95 itm.setData(0, self.lineRole, int(line))
90 itm.setData(0, self.errorRole, error) 96 itm.setData(0, self.errorRole, error)
91 itm.setData(0, self.warningRole, isWarning) 97 itm.setData(0, self.warningRole, isWarning)
92 98
99 def prepare(self, fileList, project):
100 """
101 Public method to prepare the dialog with a list of filenames.
102
103 @param fileList list of filenames (list of strings)
104 @param project reference to the project object (Project)
105 """
106 self.__fileList = fileList[:]
107 self.__project = project
108
109 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
110 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
111 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
112
113 self.filterFrame.setVisible(True)
114
115 self.__data = self.__project.getData("CHECKERSPARMS", "SyntaxChecker")
116 if self.__data is None or "ExcludeFiles" not in self.__data:
117 self.__data = {"ExcludeFiles" : ""}
118 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"])
119
93 def start(self, fn, codestring = ""): 120 def start(self, fn, codestring = ""):
94 """ 121 """
95 Public slot to start the syntax check. 122 Public slot to start the syntax check.
96 123
97 @param fn file or list of files or directory to be checked 124 @param fn file or list of files or directory to be checked
98 (string or list of strings) 125 (string or list of strings)
99 @param codestring string containing the code to be checked (string). 126 @param codestring string containing the code to be checked (string).
100 If this is given, file must be a single file name. 127 If this is given, file must be a single file name.
101 """ 128 """
129 self.cancelled = False
130 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
131 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
132 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
133 QApplication.processEvents()
134
102 if isinstance(fn, list): 135 if isinstance(fn, list):
103 files = fn 136 files = fn
104 elif os.path.isdir(fn): 137 elif os.path.isdir(fn):
105 files = [] 138 files = []
106 for ext in Preferences.getPython("Python3Extensions"): 139 for ext in Preferences.getPython("Python3Extensions"):
196 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 229 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
197 self.__finish() 230 self.__finish()
198 elif button == self.showButton: 231 elif button == self.showButton:
199 self.on_showButton_clicked() 232 self.on_showButton_clicked()
200 233
234 @pyqtSlot()
235 def on_startButton_clicked(self):
236 """
237 Private slot to start a code metrics run.
238 """
239 fileList = self.__fileList[:]
240
241 filterString = self.excludeFilesEdit.text()
242 if "ExcludeFiles" not in self.__data or \
243 filterString != self.__data["ExcludeFiles"]:
244 self.__data["ExcludeFiles"] = filterString
245 self.__project.setData("CHECKERSPARMS", "SyntaxChecker", self.__data)
246 filterList = filterString.split(",")
247 if filterList:
248 for filter in filterList:
249 fileList = \
250 [f for f in fileList if not fnmatch.fnmatch(f, filter.strip())]
251
252 self.resultList.clear()
253 self.start(fileList)
254
201 def on_resultList_itemActivated(self, itm, col): 255 def on_resultList_itemActivated(self, itm, col):
202 """ 256 """
203 Private slot to handle the activation of an item. 257 Private slot to handle the activation of an item.
204 258
205 @param itm reference to the activated item (QTreeWidgetItem) 259 @param itm reference to the activated item (QTreeWidgetItem)

eric ide

mercurial