eric6/Plugins/PluginSyntaxChecker.py

Tue, 19 Nov 2019 18:53:58 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 19 Nov 2019 18:53:58 +0100
changeset 7335
07ed3d73bf58
parent 7256
4ef3b78ebb4e
child 7360
9190402e4505
permissions
-rw-r--r--

Syntax Checker:
- added a syntax checker for JSON files
- added a syntax checker for YAML files

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
830
6caa4436dee2 Fixed a few smaller issues and some source code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
7 Module implementing the Syntax Checker plugin.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2407
diff changeset
10
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3621
diff changeset
13 from PyQt5.QtCore import QObject
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 53
diff changeset
15 from E5Gui.E5Action import E5Action
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 53
diff changeset
16 from E5Gui.E5Application import e5App
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
17 from eric6config import getConfig
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
3450
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
19 from Project.ProjectBrowserModel import ProjectBrowserFileItem
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 28
diff changeset
21 import Preferences
5316
31cbc97d4974 Got rid of the manually set version numbers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
22 import UI.Info
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 28
diff changeset
23
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 # Start-Of-Header
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 name = "Syntax Checker Plugin"
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 autoactivate = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 deactivateable = True
5316
31cbc97d4974 Got rid of the manually set version numbers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
29 version = UI.Info.VersionOnly
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 className = "SyntaxCheckerPlugin"
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 packageName = "__core__"
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 shortDescription = "Show the Syntax Checker dialog."
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
33 longDescription = (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
34 """This plugin implements the Syntax Checker dialog."""
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
35 """ Syntax Checker is used to check Python source files for correct"""
3036
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
36 """ syntax."""
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
37 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 pyqtApi = 2
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 # End-Of-Header
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 error = ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 830
diff changeset
43
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 class SyntaxCheckerPlugin(QObject):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 Class implementing the Syntax Checker plugin.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 def __init__(self, ui):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @param ui reference to the user interface object (UI.UserInterface)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2407
diff changeset
54 super(SyntaxCheckerPlugin, self).__init__(ui)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__ui = ui
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__initialize()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
58 from Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService import (
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
59 SyntaxCheckService
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
60 )
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
61 self.syntaxCheckService = SyntaxCheckService()
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
62 e5App().registerObject("SyntaxCheckService", self.syntaxCheckService)
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
63
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
64 ericPath = getConfig('ericDir')
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
65 path = os.path.join(ericPath, 'Plugins', 'CheckerPlugins',
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
66 'SyntaxChecker')
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
67
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
68 self.syntaxCheckService.addLanguage(
3525
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
69 'Python2', 'Python2', path, 'SyntaxCheck',
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
70 self.__getPythonOptions,
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
71 lambda: Preferences.getPython("PythonExtensions"),
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
72 self.__translateSyntaxCheck,
4231
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
73 self.syntaxCheckService.serviceErrorPy2)
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
74
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
75 self.syntaxCheckService.addLanguage(
3525
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
76 'Python3', 'Python3', path, 'SyntaxCheck',
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
77 self.__getPythonOptions,
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
78 lambda: Preferences.getPython("Python3Extensions"),
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
79 self.__translateSyntaxCheck,
4231
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
80 self.syntaxCheckService.serviceErrorPy3)
3525
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
81
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
82 # Jasy isn't yet compatible to Python2
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
83 self.syntaxCheckService.addLanguage(
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
84 'JavaScript', 'Python3', path,
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
85 'jsCheckSyntax',
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
86 lambda: [], # No options
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
87 lambda: ['.js'],
66f4b8646622 Reintegrated the js syntax checker and therefore improved the background service a little.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3523
diff changeset
88 lambda fn, problems:
4424
718d5ed464c1 Removed an __IGNORE_WARNING__ comment in the syntax checker plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4231
diff changeset
89 self.syntaxCheckService.syntaxChecked.emit(fn, problems),
4231
0b38613388c9 Implemented the batch check mode for the syntax checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
90 self.syntaxCheckService.serviceErrorJavaScript)
7335
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
91
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
92 # YAML syntax check via Python3
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
93 self.syntaxCheckService.addLanguage(
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
94 'YAML', 'Python3', path,
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
95 'yamlCheckSyntax',
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
96 lambda: [], # No options
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
97 lambda: ['.yml', '.yaml'],
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
98 lambda fn, problems:
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
99 self.syntaxCheckService.syntaxChecked.emit(fn, problems),
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
100 self.syntaxCheckService.serviceErrorYAML)
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
101
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
102 # JSON syntax check via Python3
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
103 self.syntaxCheckService.addLanguage(
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
104 'JSON', 'Python3', path,
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
105 'jsonCheckSyntax',
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
106 lambda: [], # No options
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
107 lambda: ['.json'],
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
108 lambda fn, problems:
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
109 self.syntaxCheckService.syntaxChecked.emit(fn, problems),
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
110 self.syntaxCheckService.serviceErrorJSON)
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
111
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 def __initialize(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 Private slot to (re)initialize the plugin.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 self.__projectAct = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.__projectSyntaxCheckerDialog = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__projectBrowserAct = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 self.__projectBrowserMenu = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.__projectBrowserSyntaxCheckerDialog = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.__editors = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__editorAct = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.__editorSyntaxCheckerDialog = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
127 def __getPythonOptions(self):
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
128 """
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
129 Private methode to determine the syntax check options.
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
130
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
131 @return state of checkFlakes and ignoreStarImportWarnings (bool, bool)
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
132 """
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
133 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck")
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
134 ignoreStarImportWarnings = Preferences.getFlakes(
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
135 "IgnoreStarImportWarnings")
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
136 return checkFlakes, ignoreStarImportWarnings
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
137
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
138 def __translateSyntaxCheck(self, fn, problems):
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
139 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3558
diff changeset
140 Private slot to translate the resulting messages.
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
141
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
142 If checkFlakes is True, warnings contains a list of strings containing
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
143 the warnings (marker, file name, line number, message)
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
144 The values are only valid, if nok is False.
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
145
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
146 @param fn filename of the checked file (str)
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
147 @param problems dictionary with the keys 'error' and 'warnings' which
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
148 hold a list containing details about the error/ warnings
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
149 (file name, line number, column, codestring (only at syntax
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
150 errors), the message, a list with arguments for the message)
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
151 """
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
152 from CheckerPlugins.SyntaxChecker.pyflakes.translations import (
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456 3447
diff changeset
153 getTranslatedFlakesMessage
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
154 )
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
155 warnings = problems.get('warnings', [])
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
156 for warning in warnings:
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
157 # Translate messages
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
158 msg_args = warning.pop()
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456 3447
diff changeset
159 warning[4] = getTranslatedFlakesMessage(warning[4], msg_args)
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
160
3412
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
161 problems['warnings'] = warnings
9364dab2d472 Plug-in docu updated, now the return values of the syntax checker is a dictionary
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
162 self.syntaxCheckService.syntaxChecked.emit(fn, problems)
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
163
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 def activate(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 Public method to activate this plugin.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @return tuple of None and activation status (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
170 menu = e5App().getObject("Project").getMenu("Checks")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 if menu:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3006
diff changeset
172 self.__projectAct = E5Action(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
173 self.tr('Check Syntax'),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
174 self.tr('&Syntax...'), 0, 0,
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3006
diff changeset
175 self, 'project_check_syntax')
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
176 self.__projectAct.setStatusTip(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
177 self.tr('Check syntax.'))
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
178 self.__projectAct.setWhatsThis(self.tr(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 """<b>Check Syntax...</b>"""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 """<p>This checks Python files for syntax errors.</p>"""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 ))
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
182 self.__projectAct.triggered.connect(self.__projectSyntaxCheck)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 53
diff changeset
183 e5App().getObject("Project").addE5Actions([self.__projectAct])
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 menu.addAction(self.__projectAct)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3006
diff changeset
186 self.__editorAct = E5Action(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
187 self.tr('Check Syntax'),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
188 self.tr('&Syntax...'), 0, 0,
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3006
diff changeset
189 self, "")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
190 self.__editorAct.setWhatsThis(self.tr(
3036
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
191 """<b>Check Syntax...</b>"""
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
192 """<p>This checks Python files for syntax errors.</p>"""
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 ))
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
194 self.__editorAct.triggered.connect(self.__editorSyntaxCheck)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
495
b31b0bffa5b0 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
196 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu)
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
197 e5App().getObject("ProjectBrowser").getProjectBrowser(
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
198 "sources").showMenu.connect(self.__projectBrowserShowMenu)
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
199 e5App().getObject("ViewManager").editorOpenedEd.connect(
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
200 self.__editorOpened)
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
201 e5App().getObject("ViewManager").editorClosedEd.connect(
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
202 self.__editorClosed)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
204 for editor in e5App().getObject("ViewManager").getOpenEditors():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 self.__editorOpened(editor)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 return None, True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 def deactivate(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 Public method to deactivate this plugin.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 """
3006
66b769f458c9 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3004
diff changeset
213 e5App().getObject("Project").showMenu.disconnect(
66b769f458c9 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3004
diff changeset
214 self.__projectShowMenu)
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
215 e5App().getObject("ProjectBrowser").getProjectBrowser(
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
216 "sources").showMenu.disconnect(self.__projectBrowserShowMenu)
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
217 e5App().getObject("ViewManager").editorOpenedEd.disconnect(
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
218 self.__editorOpened)
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
219 e5App().getObject("ViewManager").editorClosedEd.disconnect(
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
220 self.__editorClosed)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
222 menu = e5App().getObject("Project").getMenu("Checks")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 if menu:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 menu.removeAction(self.__projectAct)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 if self.__projectBrowserMenu:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 if self.__projectBrowserAct:
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
228 self.__projectBrowserMenu.removeAction(
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
229 self.__projectBrowserAct)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 for editor in self.__editors:
495
b31b0bffa5b0 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
232 editor.showMenu.disconnect(self.__editorShowMenu)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 menu = editor.getMenu("Checks")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 if menu is not None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 menu.removeAction(self.__editorAct)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 self.__initialize()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 def __projectShowMenu(self, menuName, menu):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 830
diff changeset
241 Private slot called, when the the project menu or a submenu is
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 about to be shown.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @param menuName name of the menu to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 @param menu reference to the menu (QMenu)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 if menuName == "Checks" and self.__projectAct is not None:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
248 self.__projectAct.setEnabled(
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
249 e5App().getObject("Project").getProjectLanguage() in
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
250 self.syntaxCheckService.getLanguages())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 def __projectBrowserShowMenu(self, menuName, menu):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 830
diff changeset
254 Private slot called, when the the project browser menu or a submenu is
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 about to be shown.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 @param menuName name of the menu to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 @param menu reference to the menu (QMenu)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 """
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
260 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
261 menuName == "Checks" and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
262 e5App().getObject("Project").getProjectLanguage() in
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
263 self.syntaxCheckService.getLanguages()
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
264 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 self.__projectBrowserMenu = menu
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 if self.__projectBrowserAct is None:
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
267 self.__projectBrowserAct = E5Action(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
268 self.tr('Check Syntax'),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
269 self.tr('&Syntax...'), 0, 0,
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
270 self, "")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3180
diff changeset
271 self.__projectBrowserAct.setWhatsThis(self.tr(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 """<b>Check Syntax...</b>"""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 """<p>This checks Python files for syntax errors.</p>"""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 ))
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
275 self.__projectBrowserAct.triggered.connect(
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 495
diff changeset
276 self.__projectBrowserSyntaxCheck)
3621
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
277 if self.__projectBrowserAct not in menu.actions():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 menu.addAction(self.__projectBrowserAct)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 def __projectSyntaxCheck(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3558
diff changeset
282 Private slot used to check the project files for syntax errors.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 """
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
284 project = e5App().getObject("Project")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 project.saveAllScripts()
571
1a4101cb87eb Added filename filters to the syntax checker and tabnanny dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 564
diff changeset
286 ppath = project.getProjectPath()
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
287 extensions = tuple(self.syntaxCheckService.getExtensions())
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
288 files = [os.path.join(ppath, file)
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
289 for file in project.pdata["SOURCES"]
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
290 if file.endswith(extensions)]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
292 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import (
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
293 SyntaxCheckerDialog
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
294 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 self.__projectSyntaxCheckerDialog = SyntaxCheckerDialog()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 self.__projectSyntaxCheckerDialog.show()
571
1a4101cb87eb Added filename filters to the syntax checker and tabnanny dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 564
diff changeset
297 self.__projectSyntaxCheckerDialog.prepare(files, project)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 def __projectBrowserSyntaxCheck(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 """
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
301 Private method to handle the syntax check context menu action of the
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
302 project sources browser.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 """
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
304 browser = e5App().getObject("ProjectBrowser").getProjectBrowser(
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
305 "sources")
3450
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
306 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1:
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
307 fn = []
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
308 for itm in browser.getSelectedItems([ProjectBrowserFileItem]):
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
309 fn.append(itm.fileName())
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
310 else:
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
311 itm = browser.model().item(browser.currentIndex())
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
312 try:
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
313 fn = itm.fileName()
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
314 except AttributeError:
2f7c8fd8e3f5 Added capability to check multiple files from the project sources browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3447
diff changeset
315 fn = itm.dirName()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
317 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import (
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
318 SyntaxCheckerDialog
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
319 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 self.__projectBrowserSyntaxCheckerDialog = SyntaxCheckerDialog()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 self.__projectBrowserSyntaxCheckerDialog.show()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 self.__projectBrowserSyntaxCheckerDialog.start(fn)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 def __editorOpened(self, editor):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 Private slot called, when a new editor was opened.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 @param editor reference to the new editor (QScintilla.Editor)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 menu = editor.getMenu("Checks")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 if menu is not None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 menu.addAction(self.__editorAct)
495
b31b0bffa5b0 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 454
diff changeset
333 editor.showMenu.connect(self.__editorShowMenu)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 self.__editors.append(editor)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 def __editorClosed(self, editor):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 Private slot called, when an editor was closed.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 @param editor reference to the editor (QScintilla.Editor)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 self.__editors.remove(editor)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 except ValueError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 pass
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 def __editorShowMenu(self, menuName, menu, editor):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 830
diff changeset
349 Private slot called, when the the editor context menu or a submenu is
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 about to be shown.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 @param menuName name of the menu to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 @param menu reference to the menu (QMenu)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 @param editor reference to the editor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 if menuName == "Checks":
3621
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
357 if self.__editorAct not in menu.actions():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 menu.addAction(self.__editorAct)
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
359 self.__editorAct.setEnabled(
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
360 editor.getLanguage() in self.syntaxCheckService.getLanguages())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 def __editorSyntaxCheck(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 """
3004
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
364 Private slot to handle the syntax check context menu action of the
c4bf32c791d0 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2712
diff changeset
365 editors.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
367 editor = e5App().getObject("ViewManager").activeWindow()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 if editor is not None:
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
369 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import (
3438
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
370 SyntaxCheckerDialog
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
371 )
3438
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
372 self.__editorSyntaxCheckerDialog = SyntaxCheckerDialog()
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
373 self.__editorSyntaxCheckerDialog.show()
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
374 if editor.isJavascriptFile():
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
375 unnamed = "Unnamed.js"
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
376 else:
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
377 unnamed = "Unnamed.py"
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
378 self.__editorSyntaxCheckerDialog.start(
29717a5e8b97 Started improving JavaScript support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3345
diff changeset
379 editor.getFileName() or unnamed, editor.text())

eric ide

mercurial