232 """ |
232 """ |
233 Public method to activate this plugin. |
233 Public method to activate this plugin. |
234 |
234 |
235 @return tuple of None and activation status (boolean) |
235 @return tuple of None and activation status (boolean) |
236 """ |
236 """ |
237 menu = e5App().getObject("Project").getMenu("Checks") |
237 menu = ericApp().getObject("Project").getMenu("Checks") |
238 if menu: |
238 if menu: |
239 self.__projectAct = E5Action( |
239 self.__projectAct = EricAction( |
240 self.tr('Check Code Style'), |
240 self.tr('Check Code Style'), |
241 self.tr('&Code Style...'), 0, 0, |
241 self.tr('&Code Style...'), 0, 0, |
242 self, 'project_check_pep8') |
242 self, 'project_check_pep8') |
243 self.__projectAct.setStatusTip( |
243 self.__projectAct.setStatusTip( |
244 self.tr('Check code style.')) |
244 self.tr('Check code style.')) |
247 """<p>This checks Python files for compliance to the""" |
247 """<p>This checks Python files for compliance to the""" |
248 """ code style conventions given in various PEPs.</p>""" |
248 """ code style conventions given in various PEPs.</p>""" |
249 )) |
249 )) |
250 self.__projectAct.triggered.connect( |
250 self.__projectAct.triggered.connect( |
251 self.__projectCodeStyleCheck) |
251 self.__projectCodeStyleCheck) |
252 e5App().getObject("Project").addE5Actions([self.__projectAct]) |
252 ericApp().getObject("Project").addEricActions([self.__projectAct]) |
253 menu.addAction(self.__projectAct) |
253 menu.addAction(self.__projectAct) |
254 |
254 |
255 self.__editorAct = E5Action( |
255 self.__editorAct = EricAction( |
256 self.tr('Check Code Style'), |
256 self.tr('Check Code Style'), |
257 self.tr('&Code Style...'), 0, 0, |
257 self.tr('&Code Style...'), 0, 0, |
258 self, "") |
258 self, "") |
259 self.__editorAct.setWhatsThis(self.tr( |
259 self.__editorAct.setWhatsThis(self.tr( |
260 """<b>Check Code Style...</b>""" |
260 """<b>Check Code Style...</b>""" |
261 """<p>This checks Python files for compliance to the""" |
261 """<p>This checks Python files for compliance to the""" |
262 """ code style conventions given in various PEPs.</p>""" |
262 """ code style conventions given in various PEPs.</p>""" |
263 )) |
263 )) |
264 self.__editorAct.triggered.connect(self.__editorCodeStyleCheck) |
264 self.__editorAct.triggered.connect(self.__editorCodeStyleCheck) |
265 |
265 |
266 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
266 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) |
267 e5App().getObject("ProjectBrowser").getProjectBrowser( |
267 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
268 "sources").showMenu.connect(self.__projectBrowserShowMenu) |
268 "sources").showMenu.connect(self.__projectBrowserShowMenu) |
269 e5App().getObject("ViewManager").editorOpenedEd.connect( |
269 ericApp().getObject("ViewManager").editorOpenedEd.connect( |
270 self.__editorOpened) |
270 self.__editorOpened) |
271 e5App().getObject("ViewManager").editorClosedEd.connect( |
271 ericApp().getObject("ViewManager").editorClosedEd.connect( |
272 self.__editorClosed) |
272 self.__editorClosed) |
273 |
273 |
274 for editor in e5App().getObject("ViewManager").getOpenEditors(): |
274 for editor in ericApp().getObject("ViewManager").getOpenEditors(): |
275 self.__editorOpened(editor) |
275 self.__editorOpened(editor) |
276 |
276 |
277 return None, True |
277 return None, True |
278 |
278 |
279 def deactivate(self): |
279 def deactivate(self): |
280 """ |
280 """ |
281 Public method to deactivate this plugin. |
281 Public method to deactivate this plugin. |
282 """ |
282 """ |
283 e5App().getObject("Project").showMenu.disconnect( |
283 ericApp().getObject("Project").showMenu.disconnect( |
284 self.__projectShowMenu) |
284 self.__projectShowMenu) |
285 e5App().getObject("ProjectBrowser").getProjectBrowser( |
285 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
286 "sources").showMenu.disconnect(self.__projectBrowserShowMenu) |
286 "sources").showMenu.disconnect(self.__projectBrowserShowMenu) |
287 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
287 ericApp().getObject("ViewManager").editorOpenedEd.disconnect( |
288 self.__editorOpened) |
288 self.__editorOpened) |
289 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
289 ericApp().getObject("ViewManager").editorClosedEd.disconnect( |
290 self.__editorClosed) |
290 self.__editorClosed) |
291 |
291 |
292 menu = e5App().getObject("Project").getMenu("Checks") |
292 menu = ericApp().getObject("Project").getMenu("Checks") |
293 if menu: |
293 if menu: |
294 menu.removeAction(self.__projectAct) |
294 menu.removeAction(self.__projectAct) |
295 |
295 |
296 if self.__projectBrowserMenu and self.__projectBrowserAct: |
296 if self.__projectBrowserMenu and self.__projectBrowserAct: |
297 self.__projectBrowserMenu.removeAction( |
297 self.__projectBrowserMenu.removeAction( |
313 @param menuName name of the menu to be shown (string) |
313 @param menuName name of the menu to be shown (string) |
314 @param menu reference to the menu (QMenu) |
314 @param menu reference to the menu (QMenu) |
315 """ |
315 """ |
316 if menuName == "Checks" and self.__projectAct is not None: |
316 if menuName == "Checks" and self.__projectAct is not None: |
317 self.__projectAct.setEnabled( |
317 self.__projectAct.setEnabled( |
318 e5App().getObject("Project").getProjectLanguage() in |
318 ericApp().getObject("Project").getProjectLanguage() in |
319 ["Python3", "MicroPython"]) |
319 ["Python3", "MicroPython"]) |
320 |
320 |
321 def __projectBrowserShowMenu(self, menuName, menu): |
321 def __projectBrowserShowMenu(self, menuName, menu): |
322 """ |
322 """ |
323 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 |
326 @param menuName name of the menu to be shown (string) |
326 @param menuName name of the menu to be shown (string) |
327 @param menu reference to the menu (QMenu) |
327 @param menu reference to the menu (QMenu) |
328 """ |
328 """ |
329 if ( |
329 if ( |
330 menuName == "Checks" and |
330 menuName == "Checks" and |
331 e5App().getObject("Project").getProjectLanguage() in |
331 ericApp().getObject("Project").getProjectLanguage() in |
332 ["Python3", "MicroPython"] |
332 ["Python3", "MicroPython"] |
333 ): |
333 ): |
334 self.__projectBrowserMenu = menu |
334 self.__projectBrowserMenu = menu |
335 if self.__projectBrowserAct is None: |
335 if self.__projectBrowserAct is None: |
336 self.__projectBrowserAct = E5Action( |
336 self.__projectBrowserAct = EricAction( |
337 self.tr('Check Code Style'), |
337 self.tr('Check Code Style'), |
338 self.tr('&Code Style...'), 0, 0, |
338 self.tr('&Code Style...'), 0, 0, |
339 self, "") |
339 self, "") |
340 self.__projectBrowserAct.setWhatsThis(self.tr( |
340 self.__projectBrowserAct.setWhatsThis(self.tr( |
341 """<b>Check Code Style...</b>""" |
341 """<b>Check Code Style...</b>""" |
349 |
349 |
350 def __projectCodeStyleCheck(self): |
350 def __projectCodeStyleCheck(self): |
351 """ |
351 """ |
352 Private slot used to check the project files for code style. |
352 Private slot used to check the project files for code style. |
353 """ |
353 """ |
354 project = e5App().getObject("Project") |
354 project = ericApp().getObject("Project") |
355 project.saveAllScripts() |
355 project.saveAllScripts() |
356 ppath = project.getProjectPath() |
356 ppath = project.getProjectPath() |
357 files = [os.path.join(ppath, file) |
357 files = [os.path.join(ppath, file) |
358 for file in project.pdata["SOURCES"] |
358 for file in project.pdata["SOURCES"] |
359 if file.endswith( |
359 if file.endswith( |