70 self.backgroundService = e5App().getObject("BackgroundService") |
70 self.backgroundService = e5App().getObject("BackgroundService") |
71 |
71 |
72 path = os.path.join( |
72 path = os.path.join( |
73 os.path.dirname(__file__), 'CheckerPlugins', 'CodeStyleChecker') |
73 os.path.dirname(__file__), 'CheckerPlugins', 'CodeStyleChecker') |
74 self.backgroundService.serviceConnect( |
74 self.backgroundService.serviceConnect( |
75 'style', 'Python2', path, 'CodeStyleChecker', |
|
76 self.__translateStyleCheck, |
|
77 onErrorCallback=self.serviceErrorPy2, |
|
78 onBatchDone=self.batchJobDone) |
|
79 self.backgroundService.serviceConnect( |
|
80 'style', 'Python3', path, 'CodeStyleChecker', |
75 'style', 'Python3', path, 'CodeStyleChecker', |
81 self.__translateStyleCheck, |
76 self.__translateStyleCheck, |
82 onErrorCallback=self.serviceErrorPy3, |
77 onErrorCallback=self.serviceErrorPy3, |
83 onBatchDone=self.batchJobDone) |
78 onBatchDone=self.batchJobDone) |
84 |
79 |
93 |
88 |
94 @param fn file name (string) |
89 @param fn file name (string) |
95 @param msg message text (string) |
90 @param msg message text (string) |
96 """ |
91 """ |
97 self.error.emit(fn, msg) |
92 self.error.emit(fn, msg) |
98 |
|
99 def serviceErrorPy2(self, fx, lang, fn, msg): |
|
100 """ |
|
101 Public slot handling service errors for Python 2. |
|
102 |
|
103 @param fx service name (string) |
|
104 @param lang language (string) |
|
105 @param fn file name (string) |
|
106 @param msg message text (string) |
|
107 """ |
|
108 if fx in ['style', 'batch_style'] and lang == 'Python2': |
|
109 if fx == 'style': |
|
110 self.__serviceError(fn, msg) |
|
111 else: |
|
112 self.__serviceError(self.tr("Python 2 batch check"), msg) |
|
113 self.batchJobDone(fx, lang) |
|
114 |
93 |
115 def serviceErrorPy3(self, fx, lang, fn, msg): |
94 def serviceErrorPy3(self, fx, lang, fn, msg): |
116 """ |
95 """ |
117 Public slot handling service errors for Python 2. |
96 Public slot handling service errors for Python 2. |
118 |
97 |
177 @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
156 @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
178 bool, str, dict, dict, list of str, str, str, bool) |
157 bool, str, dict, dict, list of str, str, str, bool) |
179 """ |
158 """ |
180 if lang is None: |
159 if lang is None: |
181 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
160 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
182 if lang not in ['Python2', 'Python3']: |
161 if lang != 'Python3': |
183 return |
162 return |
184 |
163 |
185 data = [source, args] |
164 data = [source, args] |
186 self.backgroundService.enqueueRequest('style', lang, filename, data) |
165 self.backgroundService.enqueueRequest('style', lang, filename, data) |
187 |
166 |
193 containing filename, source and args as given in styleCheck() |
172 containing filename, source and args as given in styleCheck() |
194 method |
173 method |
195 @type list of tuple of (str, str, list) |
174 @type list of tuple of (str, str, list) |
196 """ |
175 """ |
197 data = { |
176 data = { |
198 "Python2": [], |
|
199 "Python3": [], |
177 "Python3": [], |
200 } |
178 } |
201 for filename, source, args in argumentsList: |
179 for filename, source, args in argumentsList: |
202 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
180 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
203 if lang not in ['Python2', 'Python3']: |
181 if lang != 'Python3': |
204 continue |
182 continue |
205 else: |
183 else: |
206 data[lang].append((filename, source, args)) |
184 data[lang].append((filename, source, args)) |
207 |
185 |
208 self.queuedBatches = [] |
186 self.queuedBatches = [] |
209 for lang in ['Python2', 'Python3']: |
187 if data['Python3']: |
210 if data[lang]: |
188 self.queuedBatches.append('Python3') |
211 self.queuedBatches.append(lang) |
189 self.backgroundService.enqueueRequest('batch_style', 'Python3', "", |
212 self.backgroundService.enqueueRequest('batch_style', lang, "", |
190 data['Python3']) |
213 data[lang]) |
191 self.batchesFinished = False |
214 self.batchesFinished = False |
|
215 |
192 |
216 def cancelStyleBatchCheck(self): |
193 def cancelStyleBatchCheck(self): |
217 """ |
194 """ |
218 Public method to cancel all batch jobs. |
195 Public method to cancel all batch jobs. |
219 """ |
196 """ |
220 for lang in ['Python2', 'Python3']: |
197 self.backgroundService.requestCancel('batch_style', 'Python3') |
221 self.backgroundService.requestCancel('batch_style', lang) |
|
222 |
198 |
223 def __translateStyleCheck(self, fn, codeStyleCheckerStats, results): |
199 def __translateStyleCheck(self, fn, codeStyleCheckerStats, results): |
224 """ |
200 """ |
225 Private slot called after perfoming a style check on one file. |
201 Private slot called after perfoming a style check on one file. |
226 |
202 |
338 @param menu reference to the menu (QMenu) |
314 @param menu reference to the menu (QMenu) |
339 """ |
315 """ |
340 if menuName == "Checks" and self.__projectAct is not None: |
316 if menuName == "Checks" and self.__projectAct is not None: |
341 self.__projectAct.setEnabled( |
317 self.__projectAct.setEnabled( |
342 e5App().getObject("Project").getProjectLanguage() in |
318 e5App().getObject("Project").getProjectLanguage() in |
343 ["Python3", "Python2", "Python", "MicroPython"]) |
319 ["Python3", "MicroPython"]) |
344 |
320 |
345 def __projectBrowserShowMenu(self, menuName, menu): |
321 def __projectBrowserShowMenu(self, menuName, menu): |
346 """ |
322 """ |
347 Private slot called, when the the project browser menu or a submenu is |
323 Private slot called, when the the project browser menu or a submenu is |
348 about to be shown. |
324 about to be shown. |
351 @param menu reference to the menu (QMenu) |
327 @param menu reference to the menu (QMenu) |
352 """ |
328 """ |
353 if ( |
329 if ( |
354 menuName == "Checks" and |
330 menuName == "Checks" and |
355 e5App().getObject("Project").getProjectLanguage() in |
331 e5App().getObject("Project").getProjectLanguage() in |
356 ["Python3", "Python2", "Python", "MicroPython"] |
332 ["Python3", "MicroPython"] |
357 ): |
333 ): |
358 self.__projectBrowserMenu = menu |
334 self.__projectBrowserMenu = menu |
359 if self.__projectBrowserAct is None: |
335 if self.__projectBrowserAct is None: |
360 self.__projectBrowserAct = E5Action( |
336 self.__projectBrowserAct = E5Action( |
361 self.tr('Check Code Style'), |
337 self.tr('Check Code Style'), |