66 self.backgroundService = e5App().getObject("BackgroundService") |
66 self.backgroundService = e5App().getObject("BackgroundService") |
67 |
67 |
68 path = os.path.join( |
68 path = os.path.join( |
69 os.path.dirname(__file__), 'CheckerPlugins', 'Tabnanny') |
69 os.path.dirname(__file__), 'CheckerPlugins', 'Tabnanny') |
70 self.backgroundService.serviceConnect( |
70 self.backgroundService.serviceConnect( |
71 'indent', 'Python2', path, 'Tabnanny', |
|
72 lambda *args: self.indentChecked.emit(*args), |
|
73 onErrorCallback=self.serviceErrorPy2, |
|
74 onBatchDone=self.batchJobDone) |
|
75 self.backgroundService.serviceConnect( |
|
76 'indent', 'Python3', path, 'Tabnanny', |
71 'indent', 'Python3', path, 'Tabnanny', |
77 lambda *args: self.indentChecked.emit(*args), |
72 lambda *args: self.indentChecked.emit(*args), |
78 onErrorCallback=self.serviceErrorPy3, |
73 onErrorCallback=self.serviceErrorPy3, |
79 onBatchDone=self.batchJobDone) |
74 onBatchDone=self.batchJobDone) |
80 |
75 |
87 |
82 |
88 @param fn file name (string) |
83 @param fn file name (string) |
89 @param msg message text (string) |
84 @param msg message text (string) |
90 """ |
85 """ |
91 self.error.emit(fn, msg) |
86 self.error.emit(fn, msg) |
92 |
|
93 def serviceErrorPy2(self, fx, lang, fn, msg): |
|
94 """ |
|
95 Public slot handling service errors for Python 2. |
|
96 |
|
97 @param fx service name (string) |
|
98 @param lang language (string) |
|
99 @param fn file name (string) |
|
100 @param msg message text (string) |
|
101 """ |
|
102 if fx in ['indent', 'batch_indent'] and lang == 'Python2': |
|
103 if fx == 'indent': |
|
104 self.__serviceError(fn, msg) |
|
105 else: |
|
106 self.__serviceError(self.tr("Python 2 batch check"), msg) |
|
107 self.batchJobDone(fx, lang) |
|
108 |
87 |
109 def serviceErrorPy3(self, fx, lang, fn, msg): |
88 def serviceErrorPy3(self, fx, lang, fn, msg): |
110 """ |
89 """ |
111 Public slot handling service errors for Python 2. |
90 Public slot handling service errors for Python 2. |
112 |
91 |
162 @param filename source filename (string) |
141 @param filename source filename (string) |
163 @param source string containing the code to check (string) |
142 @param source string containing the code to check (string) |
164 """ |
143 """ |
165 if lang is None: |
144 if lang is None: |
166 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
145 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
167 if lang not in ['Python2', 'Python3']: |
146 if lang != 'Python3': |
168 return |
147 return |
169 |
148 |
170 self.backgroundService.enqueueRequest( |
149 self.backgroundService.enqueueRequest( |
171 'indent', lang, filename, [source]) |
150 'indent', lang, filename, [source]) |
172 |
151 |
177 |
156 |
178 @param argumentsList list of arguments tuples with each tuple |
157 @param argumentsList list of arguments tuples with each tuple |
179 containing filename and source (string, string) |
158 containing filename and source (string, string) |
180 """ |
159 """ |
181 data = { |
160 data = { |
182 "Python2": [], |
|
183 "Python3": [], |
161 "Python3": [], |
184 } |
162 } |
185 for filename, source in argumentsList: |
163 for filename, source in argumentsList: |
186 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
164 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
187 if lang not in ['Python2', 'Python3']: |
165 if lang != 'Python3': |
188 continue |
166 continue |
189 else: |
167 else: |
190 data[lang].append((filename, source)) |
168 data[lang].append((filename, source)) |
191 |
169 |
192 self.queuedBatches = [] |
170 self.queuedBatches = [] |
193 for lang in ['Python2', 'Python3']: |
171 if data['Python3']: |
194 if data[lang]: |
172 self.queuedBatches.append('Python3') |
195 self.queuedBatches.append(lang) |
173 self.backgroundService.enqueueRequest( |
196 self.backgroundService.enqueueRequest('batch_indent', lang, "", |
174 'batch_indent', 'Python3', "", data['Python3']) |
197 data[lang]) |
175 self.batchesFinished = False |
198 self.batchesFinished = False |
|
199 |
176 |
200 def cancelIndentBatchCheck(self): |
177 def cancelIndentBatchCheck(self): |
201 """ |
178 """ |
202 Public method to cancel all batch jobs. |
179 Public method to cancel all batch jobs. |
203 """ |
180 """ |
204 for lang in ['Python2', 'Python3']: |
181 self.backgroundService.requestCancel('batch_style', 'Python3') |
205 self.backgroundService.requestCancel('batch_style', lang) |
|
206 |
182 |
207 def activate(self): |
183 def activate(self): |
208 """ |
184 """ |
209 Public method to activate this plugin. |
185 Public method to activate this plugin. |
210 |
186 |
290 @param menu reference to the menu (QMenu) |
266 @param menu reference to the menu (QMenu) |
291 """ |
267 """ |
292 if menuName == "Checks" and self.__projectAct is not None: |
268 if menuName == "Checks" and self.__projectAct is not None: |
293 self.__projectAct.setEnabled( |
269 self.__projectAct.setEnabled( |
294 e5App().getObject("Project").getProjectLanguage() in |
270 e5App().getObject("Project").getProjectLanguage() in |
295 ["Python3", "Python2", "Python", "MicroPython"]) |
271 ["Python3", "MicroPython"]) |
296 |
272 |
297 def __projectBrowserShowMenu(self, menuName, menu): |
273 def __projectBrowserShowMenu(self, menuName, menu): |
298 """ |
274 """ |
299 Private slot called, when the the project browser context menu or a |
275 Private slot called, when the the project browser context menu or a |
300 submenu is about to be shown. |
276 submenu is about to be shown. |
303 @param menu reference to the menu (QMenu) |
279 @param menu reference to the menu (QMenu) |
304 """ |
280 """ |
305 if ( |
281 if ( |
306 menuName == "Checks" and |
282 menuName == "Checks" and |
307 e5App().getObject("Project").getProjectLanguage() in |
283 e5App().getObject("Project").getProjectLanguage() in |
308 ["Python3", "Python2", "Python", "MicroPython"] |
284 ["Python3", "MicroPython"] |
309 ): |
285 ): |
310 self.__projectBrowserMenu = menu |
286 self.__projectBrowserMenu = menu |
311 if self.__projectBrowserAct is None: |
287 if self.__projectBrowserAct is None: |
312 self.__projectBrowserAct = E5Action( |
288 self.__projectBrowserAct = E5Action( |
313 self.tr('Check Indentations'), |
289 self.tr('Check Indentations'), |