Plugins/PluginPep8Checker.py

changeset 2980
2cb4e3c50b37
parent 2973
284c7f4bc875
equal deleted inserted replaced
2979:e2eee1b09664 2980:2cb4e3c50b37
2 2
3 # Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the PEP 8 Checker plugin. 7 Module implementing the code style checker plug-in.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QObject 12 from PyQt4.QtCore import QObject
16 from E5Gui.E5Action import E5Action 16 from E5Gui.E5Action import E5Action
17 17
18 import Preferences 18 import Preferences
19 19
20 # Start-Of-Header 20 # Start-Of-Header
21 name = "PEP 8 Checker Plugin" 21 name = "Code Style Checker Plugin"
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 22 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
23 autoactivate = True 23 autoactivate = True
24 deactivateable = True 24 deactivateable = True
25 version = "5.4.0" 25 version = "5.4.0"
26 className = "Pep8CheckerPlugin" 26 className = "Pep8CheckerPlugin"
38 error = "" 38 error = ""
39 39
40 40
41 class Pep8CheckerPlugin(QObject): 41 class Pep8CheckerPlugin(QObject):
42 """ 42 """
43 Class implementing the PEP 8 Checker plugin. 43 Class implementing the code style checker plug-in.
44 """ 44 """
45 def __init__(self, ui): 45 def __init__(self, ui):
46 """ 46 """
47 Constructor 47 Constructor
48 48
78 self.__projectAct = E5Action( 78 self.__projectAct = E5Action(
79 self.trUtf8('Check Code Style'), 79 self.trUtf8('Check Code Style'),
80 self.trUtf8('&Code Style...'), 0, 0, 80 self.trUtf8('&Code Style...'), 0, 0,
81 self, 'project_check_pep8') 81 self, 'project_check_pep8')
82 self.__projectAct.setStatusTip( 82 self.__projectAct.setStatusTip(
83 self.trUtf8('Check PEP 8 compliance.')) 83 self.trUtf8('Check code style.'))
84 self.__projectAct.setWhatsThis(self.trUtf8( 84 self.__projectAct.setWhatsThis(self.trUtf8(
85 """<b>Check Code Style...</b>""" 85 """<b>Check Code Style...</b>"""
86 """<p>This checks Python files for compliance to the""" 86 """<p>This checks Python files for compliance to the"""
87 """ code style conventions given in various PEPs.</p>""" 87 """ code style conventions given in various PEPs.</p>"""
88 )) 88 ))
184 if not self.__projectBrowserAct in menu.actions(): 184 if not self.__projectBrowserAct in menu.actions():
185 menu.addAction(self.__projectBrowserAct) 185 menu.addAction(self.__projectBrowserAct)
186 186
187 def __projectPep8Check(self): 187 def __projectPep8Check(self):
188 """ 188 """
189 Public slot used to check the project files for PEP 8 compliance. 189 Public slot used to check the project files for code style.
190 """ 190 """
191 project = e5App().getObject("Project") 191 project = e5App().getObject("Project")
192 project.saveAllScripts() 192 project.saveAllScripts()
193 ppath = project.getProjectPath() 193 ppath = project.getProjectPath()
194 files = [os.path.join(ppath, file) 194 files = [os.path.join(ppath, file)
203 self.__projectPep8CheckerDialog.show() 203 self.__projectPep8CheckerDialog.show()
204 self.__projectPep8CheckerDialog.prepare(files, project) 204 self.__projectPep8CheckerDialog.prepare(files, project)
205 205
206 def __projectBrowserPep8Check(self): 206 def __projectBrowserPep8Check(self):
207 """ 207 """
208 Private method to handle the PEP 8 check context menu action of 208 Private method to handle the code style check context menu action of
209 the project sources browser. 209 the project sources browser.
210 """ 210 """
211 browser = e5App().getObject("ProjectBrowser")\ 211 browser = e5App().getObject("ProjectBrowser")\
212 .getProjectBrowser("sources") 212 .getProjectBrowser("sources")
213 itm = browser.model().item(browser.currentIndex()) 213 itm = browser.model().item(browser.currentIndex())
267 self.__editorAct.setEnabled( 267 self.__editorAct.setEnabled(
268 editor.isPy3File() or editor.isPy2File()) 268 editor.isPy3File() or editor.isPy2File())
269 269
270 def __editorPep8Check(self): 270 def __editorPep8Check(self):
271 """ 271 """
272 Private slot to handle the PEP 8 check context menu action 272 Private slot to handle the code style check context menu action
273 of the editors. 273 of the editors.
274 """ 274 """
275 editor = e5App().getObject("ViewManager").activeWindow() 275 editor = e5App().getObject("ViewManager").activeWindow()
276 if editor is not None: 276 if editor is not None:
277 if editor.checkDirty() and editor.getFileName() is not None: 277 if editor.checkDirty() and editor.getFileName() is not None:

eric ide

mercurial