Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py

changeset 3972
efc9c803ebdc
parent 3971
b78b17dbdcef
child 4021
195a471c327b
equal deleted inserted replaced
3971:b78b17dbdcef 3972:efc9c803ebdc
63 63
64 self.checkProgress.setVisible(False) 64 self.checkProgress.setVisible(False)
65 self.checkProgressLabel.setVisible(False) 65 self.checkProgressLabel.setVisible(False)
66 self.checkProgressLabel.setMaximumWidth(600) 66 self.checkProgressLabel.setMaximumWidth(600)
67 67
68 # TODO: add code to handle a KeyError here (i.e. service is not loaded) 68 try:
69 self.syntaxCheckService = e5App().getObject('SyntaxCheckService') 69 self.syntaxCheckService = e5App().getObject('SyntaxCheckService')
70 self.syntaxCheckService.syntaxChecked.connect(self.__processResult) 70 self.syntaxCheckService.syntaxChecked.connect(self.__processResult)
71 except KeyError:
72 self.syntaxCheckService = None
71 self.filename = None 73 self.filename = None
72 74
73 def __resort(self): 75 def __resort(self):
74 """ 76 """
75 Private method to resort the tree. 77 Private method to resort the tree.
139 @param fn file or list of files or directory to be checked 141 @param fn file or list of files or directory to be checked
140 (string or list of strings) 142 (string or list of strings)
141 @param codestring string containing the code to be checked (string). 143 @param codestring string containing the code to be checked (string).
142 If this is given, fn must be a single file name. 144 If this is given, fn must be a single file name.
143 """ 145 """
144 if self.__project is None: 146 if self.syntaxCheckService is not None:
145 self.__project = e5App().getObject("Project") 147 if self.__project is None:
146 148 self.__project = e5App().getObject("Project")
147 self.cancelled = False 149
148 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 150 self.cancelled = False
149 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) 151 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
150 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 152 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
151 self.checkProgress.setVisible(True) 153 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
152 QApplication.processEvents() 154 self.checkProgress.setVisible(True)
153
154 if isinstance(fn, list):
155 self.files = fn
156 elif os.path.isdir(fn):
157 self.files = []
158 for ext in self.syntaxCheckService.getExtensions():
159 self.files.extend(
160 Utilities.direntries(fn, True, '*{0}'.format(ext), 0))
161 else:
162 self.files = [fn]
163
164 self.__clearErrors(self.files)
165
166 if codestring or len(self.files) > 0:
167 self.checkProgress.setMaximum(max(1, len(self.files)))
168 self.checkProgress.setVisible(len(self.files) > 1)
169 self.checkProgressLabel.setVisible(len(self.files) > 1)
170 QApplication.processEvents() 155 QApplication.processEvents()
171 156
172 # now go through all the files 157 if isinstance(fn, list):
173 self.progress = 0 158 self.files = fn
174 self.check(codestring) 159 elif os.path.isdir(fn):
160 self.files = []
161 for ext in self.syntaxCheckService.getExtensions():
162 self.files.extend(
163 Utilities.direntries(fn, True, '*{0}'.format(ext), 0))
164 else:
165 self.files = [fn]
166
167 self.__clearErrors(self.files)
168
169 if codestring or len(self.files) > 0:
170 self.checkProgress.setMaximum(max(1, len(self.files)))
171 self.checkProgress.setVisible(len(self.files) > 1)
172 self.checkProgressLabel.setVisible(len(self.files) > 1)
173 QApplication.processEvents()
174
175 # now go through all the files
176 self.progress = 0
177 self.check(codestring)
175 178
176 def check(self, codestring=''): 179 def check(self, codestring=''):
177 """ 180 """
178 Public method to start a check for one file. 181 Public method to start a check for one file.
179 182
180 The results are reported to the __processResult slot. 183 The results are reported to the __processResult slot.
181 @keyparam codestring optional sourcestring (str) 184 @keyparam codestring optional sourcestring (str)
182 """ 185 """
183 if not self.files: 186 if self.syntaxCheckService is None or not self.files:
184 self.__finish() 187 self.__finish()
185 return 188 return
186 189
187 self.filename = self.files.pop(0) 190 self.filename = self.files.pop(0)
188 self.checkProgress.setValue(self.progress) 191 self.checkProgress.setValue(self.progress)

eric ide

mercurial