eric6/Plugins/PluginSyntaxChecker.py

changeset 7256
4ef3b78ebb4e
parent 7229
53054eb5b15a
child 7335
07ed3d73bf58
equal deleted inserted replaced
7255:d595f6f9cbf8 7256:4ef3b78ebb4e
28 deactivateable = True 28 deactivateable = True
29 version = UI.Info.VersionOnly 29 version = UI.Info.VersionOnly
30 className = "SyntaxCheckerPlugin" 30 className = "SyntaxCheckerPlugin"
31 packageName = "__core__" 31 packageName = "__core__"
32 shortDescription = "Show the Syntax Checker dialog." 32 shortDescription = "Show the Syntax Checker dialog."
33 longDescription = """This plugin implements the Syntax Checker dialog.""" \ 33 longDescription = (
34 """ Syntax Checker is used to check Python source files for correct""" \ 34 """This plugin implements the Syntax Checker dialog."""
35 """ Syntax Checker is used to check Python source files for correct"""
35 """ syntax.""" 36 """ syntax."""
37 )
36 pyqtApi = 2 38 pyqtApi = 2
37 # End-Of-Header 39 # End-Of-Header
38 40
39 error = "" 41 error = ""
40 42
51 """ 53 """
52 super(SyntaxCheckerPlugin, self).__init__(ui) 54 super(SyntaxCheckerPlugin, self).__init__(ui)
53 self.__ui = ui 55 self.__ui = ui
54 self.__initialize() 56 self.__initialize()
55 57
56 from Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService import \ 58 from Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService import (
57 SyntaxCheckService 59 SyntaxCheckService
60 )
58 self.syntaxCheckService = SyntaxCheckService() 61 self.syntaxCheckService = SyntaxCheckService()
59 e5App().registerObject("SyntaxCheckService", self.syntaxCheckService) 62 e5App().registerObject("SyntaxCheckService", self.syntaxCheckService)
60 63
61 ericPath = getConfig('ericDir') 64 ericPath = getConfig('ericDir')
62 path = os.path.join(ericPath, 'Plugins', 'CheckerPlugins', 65 path = os.path.join(ericPath, 'Plugins', 'CheckerPlugins',
124 @param problems dictionary with the keys 'error' and 'warnings' which 127 @param problems dictionary with the keys 'error' and 'warnings' which
125 hold a list containing details about the error/ warnings 128 hold a list containing details about the error/ warnings
126 (file name, line number, column, codestring (only at syntax 129 (file name, line number, column, codestring (only at syntax
127 errors), the message, a list with arguments for the message) 130 errors), the message, a list with arguments for the message)
128 """ 131 """
129 from CheckerPlugins.SyntaxChecker.pyflakes.translations import \ 132 from CheckerPlugins.SyntaxChecker.pyflakes.translations import (
130 getTranslatedFlakesMessage 133 getTranslatedFlakesMessage
134 )
131 warnings = problems.get('warnings', []) 135 warnings = problems.get('warnings', [])
132 for warning in warnings: 136 for warning in warnings:
133 # Translate messages 137 # Translate messages
134 msg_args = warning.pop() 138 msg_args = warning.pop()
135 warning[4] = getTranslatedFlakesMessage(warning[4], msg_args) 139 warning[4] = getTranslatedFlakesMessage(warning[4], msg_args)
168 """<p>This checks Python files for syntax errors.</p>""" 172 """<p>This checks Python files for syntax errors.</p>"""
169 )) 173 ))
170 self.__editorAct.triggered.connect(self.__editorSyntaxCheck) 174 self.__editorAct.triggered.connect(self.__editorSyntaxCheck)
171 175
172 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) 176 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu)
173 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ 177 e5App().getObject("ProjectBrowser").getProjectBrowser(
174 .showMenu.connect(self.__projectBrowserShowMenu) 178 "sources").showMenu.connect(self.__projectBrowserShowMenu)
175 e5App().getObject("ViewManager").editorOpenedEd.connect( 179 e5App().getObject("ViewManager").editorOpenedEd.connect(
176 self.__editorOpened) 180 self.__editorOpened)
177 e5App().getObject("ViewManager").editorClosedEd.connect( 181 e5App().getObject("ViewManager").editorClosedEd.connect(
178 self.__editorClosed) 182 self.__editorClosed)
179 183
186 """ 190 """
187 Public method to deactivate this plugin. 191 Public method to deactivate this plugin.
188 """ 192 """
189 e5App().getObject("Project").showMenu.disconnect( 193 e5App().getObject("Project").showMenu.disconnect(
190 self.__projectShowMenu) 194 self.__projectShowMenu)
191 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ 195 e5App().getObject("ProjectBrowser").getProjectBrowser(
192 .showMenu.disconnect(self.__projectBrowserShowMenu) 196 "sources").showMenu.disconnect(self.__projectBrowserShowMenu)
193 e5App().getObject("ViewManager").editorOpenedEd.disconnect( 197 e5App().getObject("ViewManager").editorOpenedEd.disconnect(
194 self.__editorOpened) 198 self.__editorOpened)
195 e5App().getObject("ViewManager").editorClosedEd.disconnect( 199 e5App().getObject("ViewManager").editorClosedEd.disconnect(
196 self.__editorClosed) 200 self.__editorClosed)
197 201
231 about to be shown. 235 about to be shown.
232 236
233 @param menuName name of the menu to be shown (string) 237 @param menuName name of the menu to be shown (string)
234 @param menu reference to the menu (QMenu) 238 @param menu reference to the menu (QMenu)
235 """ 239 """
236 if menuName == "Checks" and \ 240 if (
237 e5App().getObject("Project").getProjectLanguage() in \ 241 menuName == "Checks" and
238 self.syntaxCheckService.getLanguages(): 242 e5App().getObject("Project").getProjectLanguage() in
243 self.syntaxCheckService.getLanguages()
244 ):
239 self.__projectBrowserMenu = menu 245 self.__projectBrowserMenu = menu
240 if self.__projectBrowserAct is None: 246 if self.__projectBrowserAct is None:
241 self.__projectBrowserAct = E5Action( 247 self.__projectBrowserAct = E5Action(
242 self.tr('Check Syntax'), 248 self.tr('Check Syntax'),
243 self.tr('&Syntax...'), 0, 0, 249 self.tr('&Syntax...'), 0, 0,
261 extensions = tuple(self.syntaxCheckService.getExtensions()) 267 extensions = tuple(self.syntaxCheckService.getExtensions())
262 files = [os.path.join(ppath, file) 268 files = [os.path.join(ppath, file)
263 for file in project.pdata["SOURCES"] 269 for file in project.pdata["SOURCES"]
264 if file.endswith(extensions)] 270 if file.endswith(extensions)]
265 271
266 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import \ 272 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import (
267 SyntaxCheckerDialog 273 SyntaxCheckerDialog
274 )
268 self.__projectSyntaxCheckerDialog = SyntaxCheckerDialog() 275 self.__projectSyntaxCheckerDialog = SyntaxCheckerDialog()
269 self.__projectSyntaxCheckerDialog.show() 276 self.__projectSyntaxCheckerDialog.show()
270 self.__projectSyntaxCheckerDialog.prepare(files, project) 277 self.__projectSyntaxCheckerDialog.prepare(files, project)
271 278
272 def __projectBrowserSyntaxCheck(self): 279 def __projectBrowserSyntaxCheck(self):
285 try: 292 try:
286 fn = itm.fileName() 293 fn = itm.fileName()
287 except AttributeError: 294 except AttributeError:
288 fn = itm.dirName() 295 fn = itm.dirName()
289 296
290 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import \ 297 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import (
291 SyntaxCheckerDialog 298 SyntaxCheckerDialog
299 )
292 self.__projectBrowserSyntaxCheckerDialog = SyntaxCheckerDialog() 300 self.__projectBrowserSyntaxCheckerDialog = SyntaxCheckerDialog()
293 self.__projectBrowserSyntaxCheckerDialog.show() 301 self.__projectBrowserSyntaxCheckerDialog.show()
294 self.__projectBrowserSyntaxCheckerDialog.start(fn) 302 self.__projectBrowserSyntaxCheckerDialog.start(fn)
295 303
296 def __editorOpened(self, editor): 304 def __editorOpened(self, editor):
336 Private slot to handle the syntax check context menu action of the 344 Private slot to handle the syntax check context menu action of the
337 editors. 345 editors.
338 """ 346 """
339 editor = e5App().getObject("ViewManager").activeWindow() 347 editor = e5App().getObject("ViewManager").activeWindow()
340 if editor is not None: 348 if editor is not None:
341 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import \ 349 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import (
342 SyntaxCheckerDialog 350 SyntaxCheckerDialog
351 )
343 self.__editorSyntaxCheckerDialog = SyntaxCheckerDialog() 352 self.__editorSyntaxCheckerDialog = SyntaxCheckerDialog()
344 self.__editorSyntaxCheckerDialog.show() 353 self.__editorSyntaxCheckerDialog.show()
345 if editor.isJavascriptFile(): 354 if editor.isJavascriptFile():
346 unnamed = "Unnamed.js" 355 unnamed = "Unnamed.js"
347 else: 356 else:

eric ide

mercurial