46 |
46 |
47 |
47 |
48 class CodeStyleCheckerPlugin(QObject): |
48 class CodeStyleCheckerPlugin(QObject): |
49 """ |
49 """ |
50 Class implementing the code style checker plug-in. |
50 Class implementing the code style checker plug-in. |
51 |
51 |
52 @signal styleChecked(str, dict, int, list) emitted when the style check was |
52 @signal styleChecked(str, dict, int, list) emitted when the style check was |
53 done for a file. |
53 done for a file. |
54 @signal batchFinished() emitted when a style check batch is done |
54 @signal batchFinished() emitted when a style check batch is done |
55 @signal error(str, str) emitted in case of an error |
55 @signal error(str, str) emitted in case of an error |
56 """ |
56 """ |
|
57 |
57 styleChecked = pyqtSignal(str, dict, int, list) |
58 styleChecked = pyqtSignal(str, dict, int, list) |
58 batchFinished = pyqtSignal() |
59 batchFinished = pyqtSignal() |
59 error = pyqtSignal(str, str) |
60 error = pyqtSignal(str, str) |
60 |
61 |
61 def __init__(self, ui): |
62 def __init__(self, ui): |
62 """ |
63 """ |
63 Constructor |
64 Constructor |
64 |
65 |
65 @param ui reference to the user interface object (UI.UserInterface) |
66 @param ui reference to the user interface object (UI.UserInterface) |
66 """ |
67 """ |
67 super().__init__(ui) |
68 super().__init__(ui) |
68 self.__ui = ui |
69 self.__ui = ui |
69 self.__initialize() |
70 self.__initialize() |
70 |
71 |
71 self.backgroundService = ericApp().getObject("BackgroundService") |
72 self.backgroundService = ericApp().getObject("BackgroundService") |
72 |
73 |
73 path = os.path.join( |
74 path = os.path.join( |
74 os.path.dirname(__file__), 'CheckerPlugins', 'CodeStyleChecker') |
75 os.path.dirname(__file__), "CheckerPlugins", "CodeStyleChecker" |
|
76 ) |
75 self.backgroundService.serviceConnect( |
77 self.backgroundService.serviceConnect( |
76 'style', 'Python3', path, 'CodeStyleChecker', |
78 "style", |
|
79 "Python3", |
|
80 path, |
|
81 "CodeStyleChecker", |
77 self.__translateStyleCheck, |
82 self.__translateStyleCheck, |
78 onErrorCallback=self.serviceErrorPy3, |
83 onErrorCallback=self.serviceErrorPy3, |
79 onBatchDone=self.batchJobDone) |
84 onBatchDone=self.batchJobDone, |
80 |
85 ) |
|
86 |
81 self.queuedBatches = [] |
87 self.queuedBatches = [] |
82 self.batchesFinished = True |
88 self.batchesFinished = True |
83 |
89 |
84 self.__wrapper = textwrap.TextWrapper(width=80) |
90 self.__wrapper = textwrap.TextWrapper(width=80) |
85 |
91 |
86 def __serviceError(self, fn, msg): |
92 def __serviceError(self, fn, msg): |
87 """ |
93 """ |
88 Private slot handling service errors. |
94 Private slot handling service errors. |
89 |
95 |
90 @param fn file name (string) |
96 @param fn file name (string) |
91 @param msg message text (string) |
97 @param msg message text (string) |
92 """ |
98 """ |
93 self.error.emit(fn, msg) |
99 self.error.emit(fn, msg) |
94 |
100 |
95 def serviceErrorPy3(self, fx, lang, fn, msg): |
101 def serviceErrorPy3(self, fx, lang, fn, msg): |
96 """ |
102 """ |
97 Public slot handling service errors for Python 3. |
103 Public slot handling service errors for Python 3. |
98 |
104 |
99 @param fx service name (string) |
105 @param fx service name (string) |
100 @param lang language (string) |
106 @param lang language (string) |
101 @param fn file name (string) |
107 @param fn file name (string) |
102 @param msg message text (string) |
108 @param msg message text (string) |
103 """ |
109 """ |
104 if fx in ['style', 'batch_style'] and lang == 'Python3': |
110 if fx in ["style", "batch_style"] and lang == "Python3": |
105 if fx == 'style': |
111 if fx == "style": |
106 self.__serviceError(fn, msg) |
112 self.__serviceError(fn, msg) |
107 else: |
113 else: |
108 self.__serviceError(self.tr("Python 3 batch check"), msg) |
114 self.__serviceError(self.tr("Python 3 batch check"), msg) |
109 self.batchJobDone(fx, lang) |
115 self.batchJobDone(fx, lang) |
110 |
116 |
111 def batchJobDone(self, fx, lang): |
117 def batchJobDone(self, fx, lang): |
112 """ |
118 """ |
113 Public slot handling the completion of a batch job. |
119 Public slot handling the completion of a batch job. |
114 |
120 |
115 @param fx service name (string) |
121 @param fx service name (string) |
116 @param lang language (string) |
122 @param lang language (string) |
117 """ |
123 """ |
118 if fx in ['style', 'batch_style']: |
124 if fx in ["style", "batch_style"]: |
119 if lang in self.queuedBatches: |
125 if lang in self.queuedBatches: |
120 self.queuedBatches.remove(lang) |
126 self.queuedBatches.remove(lang) |
121 # prevent sending the signal multiple times |
127 # prevent sending the signal multiple times |
122 if len(self.queuedBatches) == 0 and not self.batchesFinished: |
128 if len(self.queuedBatches) == 0 and not self.batchesFinished: |
123 self.batchFinished.emit() |
129 self.batchFinished.emit() |
124 self.batchesFinished = True |
130 self.batchesFinished = True |
125 |
131 |
126 def __initialize(self): |
132 def __initialize(self): |
127 """ |
133 """ |
128 Private slot to (re)initialize the plugin. |
134 Private slot to (re)initialize the plugin. |
129 """ |
135 """ |
130 self.__projectAct = None |
136 self.__projectAct = None |
131 self.__projectCodeStyleCheckerDialog = None |
137 self.__projectCodeStyleCheckerDialog = None |
132 |
138 |
133 self.__projectBrowserAct = None |
139 self.__projectBrowserAct = None |
134 self.__projectBrowserMenu = None |
140 self.__projectBrowserMenu = None |
135 self.__projectBrowserCodeStyleCheckerDialog = None |
141 self.__projectBrowserCodeStyleCheckerDialog = None |
136 |
142 |
137 self.__editors = [] |
143 self.__editors = [] |
138 self.__editorAct = None |
144 self.__editorAct = None |
139 self.__editorCodeStyleCheckerDialog = None |
145 self.__editorCodeStyleCheckerDialog = None |
140 |
146 |
141 def styleCheck(self, lang, filename, source, args): |
147 def styleCheck(self, lang, filename, source, args): |
156 encoding, backup) |
162 encoding, backup) |
157 @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
163 @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
158 bool, str, dict, dict, list of str, str, str, bool) |
164 bool, str, dict, dict, list of str, str, str, bool) |
159 """ |
165 """ |
160 if lang is None: |
166 if lang is None: |
161 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
167 lang = "Python{0}".format(determinePythonVersion(filename, source)) |
162 if lang != 'Python3': |
168 if lang != "Python3": |
163 return |
169 return |
164 |
170 |
165 data = [source, args] |
171 data = [source, args] |
166 self.backgroundService.enqueueRequest('style', lang, filename, data) |
172 self.backgroundService.enqueueRequest("style", lang, filename, data) |
167 |
173 |
168 def styleBatchCheck(self, argumentsList): |
174 def styleBatchCheck(self, argumentsList): |
169 """ |
175 """ |
170 Public method to prepare a style check on multiple Python source files. |
176 Public method to prepare a style check on multiple Python source files. |
171 |
177 |
172 @param argumentsList list of arguments tuples with each tuple |
178 @param argumentsList list of arguments tuples with each tuple |
173 containing filename, source and args as given in styleCheck() |
179 containing filename, source and args as given in styleCheck() |
174 method |
180 method |
175 @type list of tuple of (str, str, list) |
181 @type list of tuple of (str, str, list) |
176 """ |
182 """ |
177 data = { |
183 data = { |
178 "Python3": [], |
184 "Python3": [], |
179 } |
185 } |
180 for filename, source, args in argumentsList: |
186 for filename, source, args in argumentsList: |
181 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
187 lang = "Python{0}".format(determinePythonVersion(filename, source)) |
182 if lang != 'Python3': |
188 if lang != "Python3": |
183 continue |
189 continue |
184 else: |
190 else: |
185 data[lang].append((filename, source, args)) |
191 data[lang].append((filename, source, args)) |
186 |
192 |
187 self.queuedBatches = [] |
193 self.queuedBatches = [] |
188 if data['Python3']: |
194 if data["Python3"]: |
189 self.queuedBatches.append('Python3') |
195 self.queuedBatches.append("Python3") |
190 self.backgroundService.enqueueRequest('batch_style', 'Python3', "", |
196 self.backgroundService.enqueueRequest( |
191 data['Python3']) |
197 "batch_style", "Python3", "", data["Python3"] |
|
198 ) |
192 self.batchesFinished = False |
199 self.batchesFinished = False |
193 |
200 |
194 def cancelStyleBatchCheck(self): |
201 def cancelStyleBatchCheck(self): |
195 """ |
202 """ |
196 Public method to cancel all batch jobs. |
203 Public method to cancel all batch jobs. |
197 """ |
204 """ |
198 self.backgroundService.requestCancel('batch_style', 'Python3') |
205 self.backgroundService.requestCancel("batch_style", "Python3") |
199 |
206 |
200 def __translateStyleCheck(self, fn, codeStyleCheckerStats, results): |
207 def __translateStyleCheck(self, fn, codeStyleCheckerStats, results): |
201 """ |
208 """ |
202 Private slot called after performing a style check on one file. |
209 Private slot called after performing a style check on one file. |
203 |
210 |
204 @param fn filename of the just checked file |
211 @param fn filename of the just checked file |
205 @type str |
212 @type str |
206 @param codeStyleCheckerStats stats of style and name check |
213 @param codeStyleCheckerStats stats of style and name check |
207 @type dict |
214 @type dict |
208 @param results dictionary containing the check result data |
215 @param results dictionary containing the check result data |
209 (see CodesStyleChecker.__checkCodeStyle for details) |
216 (see CodesStyleChecker.__checkCodeStyle for details) |
210 @type dict |
217 @type dict |
211 """ |
218 """ |
212 from CheckerPlugins.CodeStyleChecker.translations import ( |
219 from CheckerPlugins.CodeStyleChecker.translations import getTranslatedMessage |
213 getTranslatedMessage |
220 |
214 ) |
|
215 |
|
216 fixes = 0 |
221 fixes = 0 |
217 for result in results: |
222 for result in results: |
218 msg = getTranslatedMessage(result["code"], result["args"]) |
223 msg = getTranslatedMessage(result["code"], result["args"]) |
219 |
224 |
220 if result["fixcode"]: |
225 if result["fixcode"]: |
221 fixes += 1 |
226 fixes += 1 |
222 trFixedMsg = getTranslatedMessage(result["fixcode"], |
227 trFixedMsg = getTranslatedMessage(result["fixcode"], result["fixargs"]) |
223 result["fixargs"]) |
228 |
224 |
|
225 msg += "\n" + QCoreApplication.translate( |
229 msg += "\n" + QCoreApplication.translate( |
226 'CodeStyleCheckerDialog', "Fix: {0}").format(trFixedMsg) |
230 "CodeStyleCheckerDialog", "Fix: {0}" |
227 |
231 ).format(trFixedMsg) |
|
232 |
228 result["display"] = "\n".join(self.__wrapper.wrap(msg)) |
233 result["display"] = "\n".join(self.__wrapper.wrap(msg)) |
229 self.styleChecked.emit(fn, codeStyleCheckerStats, fixes, results) |
234 self.styleChecked.emit(fn, codeStyleCheckerStats, fixes, results) |
230 |
235 |
231 def activate(self): |
236 def activate(self): |
232 """ |
237 """ |
233 Public method to activate this plugin. |
238 Public method to activate this plugin. |
234 |
239 |
235 @return tuple of None and activation status (boolean) |
240 @return tuple of None and activation status (boolean) |
236 """ |
241 """ |
237 menu = ericApp().getObject("Project").getMenu("Checks") |
242 menu = ericApp().getObject("Project").getMenu("Checks") |
238 if menu: |
243 if menu: |
239 self.__projectAct = EricAction( |
244 self.__projectAct = EricAction( |
240 self.tr('Check Code Style'), |
245 self.tr("Check Code Style"), |
241 self.tr('&Code Style...'), 0, 0, |
246 self.tr("&Code Style..."), |
242 self, 'project_check_pep8') |
247 0, |
243 self.__projectAct.setStatusTip( |
248 0, |
244 self.tr('Check code style.')) |
249 self, |
245 self.__projectAct.setWhatsThis(self.tr( |
250 "project_check_pep8", |
|
251 ) |
|
252 self.__projectAct.setStatusTip(self.tr("Check code style.")) |
|
253 self.__projectAct.setWhatsThis( |
|
254 self.tr( |
|
255 """<b>Check Code Style...</b>""" |
|
256 """<p>This checks Python files for compliance to the""" |
|
257 """ code style conventions given in various PEPs.</p>""" |
|
258 ) |
|
259 ) |
|
260 self.__projectAct.triggered.connect(self.__projectCodeStyleCheck) |
|
261 ericApp().getObject("Project").addEricActions([self.__projectAct]) |
|
262 menu.addAction(self.__projectAct) |
|
263 |
|
264 self.__editorAct = EricAction( |
|
265 self.tr("Check Code Style"), self.tr("&Code Style..."), 0, 0, self, "" |
|
266 ) |
|
267 self.__editorAct.setWhatsThis( |
|
268 self.tr( |
246 """<b>Check Code Style...</b>""" |
269 """<b>Check Code Style...</b>""" |
247 """<p>This checks Python files for compliance to the""" |
270 """<p>This checks Python files for compliance to the""" |
248 """ code style conventions given in various PEPs.</p>""" |
271 """ code style conventions given in various PEPs.</p>""" |
249 )) |
272 ) |
250 self.__projectAct.triggered.connect( |
273 ) |
251 self.__projectCodeStyleCheck) |
|
252 ericApp().getObject("Project").addEricActions([self.__projectAct]) |
|
253 menu.addAction(self.__projectAct) |
|
254 |
|
255 self.__editorAct = EricAction( |
|
256 self.tr('Check Code Style'), |
|
257 self.tr('&Code Style...'), 0, 0, |
|
258 self, "") |
|
259 self.__editorAct.setWhatsThis(self.tr( |
|
260 """<b>Check Code Style...</b>""" |
|
261 """<p>This checks Python files for compliance to the""" |
|
262 """ code style conventions given in various PEPs.</p>""" |
|
263 )) |
|
264 self.__editorAct.triggered.connect(self.__editorCodeStyleCheck) |
274 self.__editorAct.triggered.connect(self.__editorCodeStyleCheck) |
265 |
275 |
266 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) |
276 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) |
267 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
277 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
268 "sources").showMenu.connect(self.__projectBrowserShowMenu) |
278 "sources" |
269 ericApp().getObject("ViewManager").editorOpenedEd.connect( |
279 ).showMenu.connect(self.__projectBrowserShowMenu) |
270 self.__editorOpened) |
280 ericApp().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened) |
271 ericApp().getObject("ViewManager").editorClosedEd.connect( |
281 ericApp().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed) |
272 self.__editorClosed) |
282 |
273 |
|
274 for editor in ericApp().getObject("ViewManager").getOpenEditors(): |
283 for editor in ericApp().getObject("ViewManager").getOpenEditors(): |
275 self.__editorOpened(editor) |
284 self.__editorOpened(editor) |
276 |
285 |
277 return None, True |
286 return None, True |
278 |
287 |
279 def deactivate(self): |
288 def deactivate(self): |
280 """ |
289 """ |
281 Public method to deactivate this plugin. |
290 Public method to deactivate this plugin. |
282 """ |
291 """ |
283 ericApp().getObject("Project").showMenu.disconnect( |
292 ericApp().getObject("Project").showMenu.disconnect(self.__projectShowMenu) |
284 self.__projectShowMenu) |
|
285 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
293 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
286 "sources").showMenu.disconnect(self.__projectBrowserShowMenu) |
294 "sources" |
|
295 ).showMenu.disconnect(self.__projectBrowserShowMenu) |
287 ericApp().getObject("ViewManager").editorOpenedEd.disconnect( |
296 ericApp().getObject("ViewManager").editorOpenedEd.disconnect( |
288 self.__editorOpened) |
297 self.__editorOpened |
|
298 ) |
289 ericApp().getObject("ViewManager").editorClosedEd.disconnect( |
299 ericApp().getObject("ViewManager").editorClosedEd.disconnect( |
290 self.__editorClosed) |
300 self.__editorClosed |
291 |
301 ) |
|
302 |
292 menu = ericApp().getObject("Project").getMenu("Checks") |
303 menu = ericApp().getObject("Project").getMenu("Checks") |
293 if menu: |
304 if menu: |
294 menu.removeAction(self.__projectAct) |
305 menu.removeAction(self.__projectAct) |
295 |
306 |
296 if self.__projectBrowserMenu and self.__projectBrowserAct: |
307 if self.__projectBrowserMenu and self.__projectBrowserAct: |
297 self.__projectBrowserMenu.removeAction( |
308 self.__projectBrowserMenu.removeAction(self.__projectBrowserAct) |
298 self.__projectBrowserAct) |
309 |
299 |
|
300 for editor in self.__editors: |
310 for editor in self.__editors: |
301 editor.showMenu.disconnect(self.__editorShowMenu) |
311 editor.showMenu.disconnect(self.__editorShowMenu) |
302 menu = editor.getMenu("Checks") |
312 menu = editor.getMenu("Checks") |
303 if menu is not None: |
313 if menu is not None: |
304 menu.removeAction(self.__editorAct) |
314 menu.removeAction(self.__editorAct) |
305 |
315 |
306 self.__initialize() |
316 self.__initialize() |
307 |
317 |
308 def __projectShowMenu(self, menuName, menu): |
318 def __projectShowMenu(self, menuName, menu): |
309 """ |
319 """ |
310 Private slot called, when the the project menu or a submenu is |
320 Private slot called, when the the project menu or a submenu is |
311 about to be shown. |
321 about to be shown. |
312 |
322 |
313 @param menuName name of the menu to be shown (string) |
323 @param menuName name of the menu to be shown (string) |
314 @param menu reference to the menu (QMenu) |
324 @param menu reference to the menu (QMenu) |
315 """ |
325 """ |
316 if menuName == "Checks" and self.__projectAct is not None: |
326 if menuName == "Checks" and self.__projectAct is not None: |
317 self.__projectAct.setEnabled( |
327 self.__projectAct.setEnabled( |
318 ericApp().getObject("Project").getProjectLanguage() in |
328 ericApp().getObject("Project").getProjectLanguage() |
319 ["Python3", "MicroPython"]) |
329 in ["Python3", "MicroPython"] |
320 |
330 ) |
|
331 |
321 def __projectBrowserShowMenu(self, menuName, menu): |
332 def __projectBrowserShowMenu(self, menuName, menu): |
322 """ |
333 """ |
323 Private slot called, when the the project browser menu or a submenu is |
334 Private slot called, when the the project browser menu or a submenu is |
324 about to be shown. |
335 about to be shown. |
325 |
336 |
326 @param menuName name of the menu to be shown (string) |
337 @param menuName name of the menu to be shown (string) |
327 @param menu reference to the menu (QMenu) |
338 @param menu reference to the menu (QMenu) |
328 """ |
339 """ |
329 if ( |
340 if menuName == "Checks" and ericApp().getObject( |
330 menuName == "Checks" and |
341 "Project" |
331 ericApp().getObject("Project").getProjectLanguage() in |
342 ).getProjectLanguage() in ["Python3", "MicroPython"]: |
332 ["Python3", "MicroPython"] |
|
333 ): |
|
334 self.__projectBrowserMenu = menu |
343 self.__projectBrowserMenu = menu |
335 if self.__projectBrowserAct is None: |
344 if self.__projectBrowserAct is None: |
336 self.__projectBrowserAct = EricAction( |
345 self.__projectBrowserAct = EricAction( |
337 self.tr('Check Code Style'), |
346 self.tr("Check Code Style"), |
338 self.tr('&Code Style...'), 0, 0, |
347 self.tr("&Code Style..."), |
339 self, "") |
348 0, |
340 self.__projectBrowserAct.setWhatsThis(self.tr( |
349 0, |
341 """<b>Check Code Style...</b>""" |
350 self, |
342 """<p>This checks Python files for compliance to the""" |
351 "", |
343 """ code style conventions given in various PEPs.</p>""" |
352 ) |
344 )) |
353 self.__projectBrowserAct.setWhatsThis( |
|
354 self.tr( |
|
355 """<b>Check Code Style...</b>""" |
|
356 """<p>This checks Python files for compliance to the""" |
|
357 """ code style conventions given in various PEPs.</p>""" |
|
358 ) |
|
359 ) |
345 self.__projectBrowserAct.triggered.connect( |
360 self.__projectBrowserAct.triggered.connect( |
346 self.__projectBrowserCodeStyleCheck) |
361 self.__projectBrowserCodeStyleCheck |
|
362 ) |
347 if self.__projectBrowserAct not in menu.actions(): |
363 if self.__projectBrowserAct not in menu.actions(): |
348 menu.addAction(self.__projectBrowserAct) |
364 menu.addAction(self.__projectBrowserAct) |
349 |
365 |
350 def __projectCodeStyleCheck(self): |
366 def __projectCodeStyleCheck(self): |
351 """ |
367 """ |
352 Private slot used to check the project files for code style. |
368 Private slot used to check the project files for code style. |
353 """ |
369 """ |
354 project = ericApp().getObject("Project") |
370 project = ericApp().getObject("Project") |
355 project.saveAllScripts() |
371 project.saveAllScripts() |
356 ppath = project.getProjectPath() |
372 ppath = project.getProjectPath() |
357 files = [os.path.join(ppath, file) |
373 files = [ |
358 for file in project.pdata["SOURCES"] |
374 os.path.join(ppath, file) |
359 if file.endswith( |
375 for file in project.pdata["SOURCES"] |
360 tuple(Preferences.getPython("Python3Extensions")))] |
376 if file.endswith(tuple(Preferences.getPython("Python3Extensions"))) |
361 |
377 ] |
|
378 |
362 from CheckerPlugins.CodeStyleChecker import CodeStyleCheckerDialog |
379 from CheckerPlugins.CodeStyleChecker import CodeStyleCheckerDialog |
|
380 |
363 self.__projectCodeStyleCheckerDialog = ( |
381 self.__projectCodeStyleCheckerDialog = ( |
364 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
382 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
365 ) |
383 ) |
366 self.__projectCodeStyleCheckerDialog.show() |
384 self.__projectCodeStyleCheckerDialog.show() |
367 self.__projectCodeStyleCheckerDialog.prepare(files, project) |
385 self.__projectCodeStyleCheckerDialog.prepare(files, project) |
368 |
386 |
369 def __projectBrowserCodeStyleCheck(self): |
387 def __projectBrowserCodeStyleCheck(self): |
370 """ |
388 """ |
371 Private method to handle the code style check context menu action of |
389 Private method to handle the code style check context menu action of |
372 the project sources browser. |
390 the project sources browser. |
373 """ |
391 """ |
374 browser = ( |
392 browser = ericApp().getObject("ProjectBrowser").getProjectBrowser("sources") |
375 ericApp().getObject("ProjectBrowser").getProjectBrowser("sources") |
|
376 ) |
|
377 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: |
393 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: |
378 fn = [] |
394 fn = [] |
379 for itm in browser.getSelectedItems([ProjectBrowserFileItem]): |
395 for itm in browser.getSelectedItems([ProjectBrowserFileItem]): |
380 fn.append(itm.fileName()) |
396 fn.append(itm.fileName()) |
381 isDir = False |
397 isDir = False |
385 fn = itm.fileName() |
401 fn = itm.fileName() |
386 isDir = False |
402 isDir = False |
387 except AttributeError: |
403 except AttributeError: |
388 fn = itm.dirName() |
404 fn = itm.dirName() |
389 isDir = True |
405 isDir = True |
390 |
406 |
391 from CheckerPlugins.CodeStyleChecker import CodeStyleCheckerDialog |
407 from CheckerPlugins.CodeStyleChecker import CodeStyleCheckerDialog |
|
408 |
392 self.__projectBrowserCodeStyleCheckerDialog = ( |
409 self.__projectBrowserCodeStyleCheckerDialog = ( |
393 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
410 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
394 ) |
411 ) |
395 self.__projectBrowserCodeStyleCheckerDialog.show() |
412 self.__projectBrowserCodeStyleCheckerDialog.show() |
396 if isDir: |
413 if isDir: |
397 self.__projectBrowserCodeStyleCheckerDialog.start( |
414 self.__projectBrowserCodeStyleCheckerDialog.start(fn, save=True) |
398 fn, save=True) |
|
399 else: |
415 else: |
400 self.__projectBrowserCodeStyleCheckerDialog.start( |
416 self.__projectBrowserCodeStyleCheckerDialog.start( |
401 fn, save=True, repeat=True) |
417 fn, save=True, repeat=True |
402 |
418 ) |
|
419 |
403 def __editorOpened(self, editor): |
420 def __editorOpened(self, editor): |
404 """ |
421 """ |
405 Private slot called, when a new editor was opened. |
422 Private slot called, when a new editor was opened. |
406 |
423 |
407 @param editor reference to the new editor (QScintilla.Editor) |
424 @param editor reference to the new editor (QScintilla.Editor) |
408 """ |
425 """ |
409 menu = editor.getMenu("Checks") |
426 menu = editor.getMenu("Checks") |
410 if menu is not None: |
427 if menu is not None: |
411 menu.addAction(self.__editorAct) |
428 menu.addAction(self.__editorAct) |
412 editor.showMenu.connect(self.__editorShowMenu) |
429 editor.showMenu.connect(self.__editorShowMenu) |
413 self.__editors.append(editor) |
430 self.__editors.append(editor) |
414 |
431 |
415 def __editorClosed(self, editor): |
432 def __editorClosed(self, editor): |
416 """ |
433 """ |
417 Private slot called, when an editor was closed. |
434 Private slot called, when an editor was closed. |
418 |
435 |
419 @param editor reference to the editor (QScintilla.Editor) |
436 @param editor reference to the editor (QScintilla.Editor) |
420 """ |
437 """ |
421 with contextlib.suppress(ValueError): |
438 with contextlib.suppress(ValueError): |
422 self.__editors.remove(editor) |
439 self.__editors.remove(editor) |
423 |
440 |
424 def __editorShowMenu(self, menuName, menu, editor): |
441 def __editorShowMenu(self, menuName, menu, editor): |
425 """ |
442 """ |
426 Private slot called, when the the editor context menu or a submenu is |
443 Private slot called, when the the editor context menu or a submenu is |
427 about to be shown. |
444 about to be shown. |
428 |
445 |
429 @param menuName name of the menu to be shown (string) |
446 @param menuName name of the menu to be shown (string) |
430 @param menu reference to the menu (QMenu) |
447 @param menu reference to the menu (QMenu) |
431 @param editor reference to the editor |
448 @param editor reference to the editor |
432 """ |
449 """ |
433 if menuName == "Checks": |
450 if menuName == "Checks": |
434 if self.__editorAct not in menu.actions(): |
451 if self.__editorAct not in menu.actions(): |
435 menu.addAction(self.__editorAct) |
452 menu.addAction(self.__editorAct) |
436 self.__editorAct.setEnabled(editor.isPyFile()) |
453 self.__editorAct.setEnabled(editor.isPyFile()) |
437 |
454 |
438 def __editorCodeStyleCheck(self): |
455 def __editorCodeStyleCheck(self): |
439 """ |
456 """ |
440 Private slot to handle the code style check context menu action |
457 Private slot to handle the code style check context menu action |
441 of the editors. |
458 of the editors. |
442 """ |
459 """ |
443 editor = ericApp().getObject("ViewManager").activeWindow() |
460 editor = ericApp().getObject("ViewManager").activeWindow() |
444 if ( |
461 if ( |
445 editor is not None and |
462 editor is not None |
446 editor.checkDirty() and |
463 and editor.checkDirty() |
447 editor.getFileName() is not None |
464 and editor.getFileName() is not None |
448 ): |
465 ): |
449 from CheckerPlugins.CodeStyleChecker import ( |
466 from CheckerPlugins.CodeStyleChecker import CodeStyleCheckerDialog |
450 CodeStyleCheckerDialog |
467 |
451 ) |
|
452 self.__editorCodeStyleCheckerDialog = ( |
468 self.__editorCodeStyleCheckerDialog = ( |
453 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
469 CodeStyleCheckerDialog.CodeStyleCheckerDialog(self) |
454 ) |
470 ) |
455 self.__editorCodeStyleCheckerDialog.show() |
471 self.__editorCodeStyleCheckerDialog.show() |
456 self.__editorCodeStyleCheckerDialog.start( |
472 self.__editorCodeStyleCheckerDialog.start( |
457 editor.getFileName(), |
473 editor.getFileName(), save=True, repeat=True |
458 save=True, |
474 ) |
459 repeat=True) |
|