Plugins/PluginSyntaxChecker.py

changeset 53
c3eb7cc1ff8b
parent 40
c2e5472b112c
child 55
b5c84934de9c
equal deleted inserted replaced
52:ba69827929ee 53:c3eb7cc1ff8b
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QObject, SIGNAL 12 from PyQt4.QtCore import QObject, SIGNAL
13 13
14 from E4Gui.E4Application import e4App 14 from E4Gui.E4Application import e5App
15 15
16 from E4Gui.E4Action import E4Action 16 from E4Gui.E4Action import E4Action
17 17
18 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import SyntaxCheckerDialog 18 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import SyntaxCheckerDialog
19 19
68 """ 68 """
69 Public method to activate this plugin. 69 Public method to activate this plugin.
70 70
71 @return tuple of None and activation status (boolean) 71 @return tuple of None and activation status (boolean)
72 """ 72 """
73 menu = e4App().getObject("Project").getMenu("Checks") 73 menu = e5App().getObject("Project").getMenu("Checks")
74 if menu: 74 if menu:
75 self.__projectAct = E4Action(self.trUtf8('Check Syntax'), 75 self.__projectAct = E4Action(self.trUtf8('Check Syntax'),
76 self.trUtf8('&Syntax...'), 0, 0, 76 self.trUtf8('&Syntax...'), 0, 0,
77 self, 'project_check_syntax') 77 self, 'project_check_syntax')
78 self.__projectAct.setStatusTip(\ 78 self.__projectAct.setStatusTip(\
81 """<b>Check Syntax...</b>""" 81 """<b>Check Syntax...</b>"""
82 """<p>This checks Python files for syntax errors.</p>""" 82 """<p>This checks Python files for syntax errors.</p>"""
83 )) 83 ))
84 self.connect(self.__projectAct, SIGNAL('triggered()'), 84 self.connect(self.__projectAct, SIGNAL('triggered()'),
85 self.__projectSyntaxCheck) 85 self.__projectSyntaxCheck)
86 e4App().getObject("Project").addE4Actions([self.__projectAct]) 86 e5App().getObject("Project").addE4Actions([self.__projectAct])
87 menu.addAction(self.__projectAct) 87 menu.addAction(self.__projectAct)
88 88
89 self.__editorAct = E4Action(self.trUtf8('Check Syntax'), 89 self.__editorAct = E4Action(self.trUtf8('Check Syntax'),
90 self.trUtf8('&Syntax...'), 0, 0, 90 self.trUtf8('&Syntax...'), 0, 0,
91 self, "") 91 self, "")
93 """<b>Check Syntax...</b>""" 93 """<b>Check Syntax...</b>"""
94 """<p>This checks Python files for syntax errors.</p>""" 94 """<p>This checks Python files for syntax errors.</p>"""
95 )) 95 ))
96 self.connect(self.__editorAct, SIGNAL('triggered()'), self.__editorSyntaxCheck) 96 self.connect(self.__editorAct, SIGNAL('triggered()'), self.__editorSyntaxCheck)
97 97
98 self.connect(e4App().getObject("Project"), SIGNAL("showMenu"), 98 self.connect(e5App().getObject("Project"), SIGNAL("showMenu"),
99 self.__projectShowMenu) 99 self.__projectShowMenu)
100 self.connect(e4App().getObject("ProjectBrowser").getProjectBrowser("sources"), 100 self.connect(e5App().getObject("ProjectBrowser").getProjectBrowser("sources"),
101 SIGNAL("showMenu"), self.__projectBrowserShowMenu) 101 SIGNAL("showMenu"), self.__projectBrowserShowMenu)
102 self.connect(e4App().getObject("ViewManager"), SIGNAL("editorOpenedEd"), 102 self.connect(e5App().getObject("ViewManager"), SIGNAL("editorOpenedEd"),
103 self.__editorOpened) 103 self.__editorOpened)
104 self.connect(e4App().getObject("ViewManager"), SIGNAL("editorClosedEd"), 104 self.connect(e5App().getObject("ViewManager"), SIGNAL("editorClosedEd"),
105 self.__editorClosed) 105 self.__editorClosed)
106 106
107 for editor in e4App().getObject("ViewManager").getOpenEditors(): 107 for editor in e5App().getObject("ViewManager").getOpenEditors():
108 self.__editorOpened(editor) 108 self.__editorOpened(editor)
109 109
110 return None, True 110 return None, True
111 111
112 def deactivate(self): 112 def deactivate(self):
113 """ 113 """
114 Public method to deactivate this plugin. 114 Public method to deactivate this plugin.
115 """ 115 """
116 self.disconnect(e4App().getObject("Project"), SIGNAL("showMenu"), 116 self.disconnect(e5App().getObject("Project"), SIGNAL("showMenu"),
117 self.__projectShowMenu) 117 self.__projectShowMenu)
118 self.disconnect(e4App().getObject("ProjectBrowser").getProjectBrowser("sources"), 118 self.disconnect(e5App().getObject("ProjectBrowser").getProjectBrowser("sources"),
119 SIGNAL("showMenu"), self.__projectBrowserShowMenu) 119 SIGNAL("showMenu"), self.__projectBrowserShowMenu)
120 self.disconnect(e4App().getObject("ViewManager"), SIGNAL("editorOpenedEd"), 120 self.disconnect(e5App().getObject("ViewManager"), SIGNAL("editorOpenedEd"),
121 self.__editorOpened) 121 self.__editorOpened)
122 self.disconnect(e4App().getObject("ViewManager"), SIGNAL("editorClosedEd"), 122 self.disconnect(e5App().getObject("ViewManager"), SIGNAL("editorClosedEd"),
123 self.__editorClosed) 123 self.__editorClosed)
124 124
125 menu = e4App().getObject("Project").getMenu("Checks") 125 menu = e5App().getObject("Project").getMenu("Checks")
126 if menu: 126 if menu:
127 menu.removeAction(self.__projectAct) 127 menu.removeAction(self.__projectAct)
128 128
129 if self.__projectBrowserMenu: 129 if self.__projectBrowserMenu:
130 if self.__projectBrowserAct: 130 if self.__projectBrowserAct:
146 @param menuName name of the menu to be shown (string) 146 @param menuName name of the menu to be shown (string)
147 @param menu reference to the menu (QMenu) 147 @param menu reference to the menu (QMenu)
148 """ 148 """
149 if menuName == "Checks" and self.__projectAct is not None: 149 if menuName == "Checks" and self.__projectAct is not None:
150 self.__projectAct.setEnabled(\ 150 self.__projectAct.setEnabled(\
151 e4App().getObject("Project").getProjectLanguage() == "Python3") 151 e5App().getObject("Project").getProjectLanguage() == "Python3")
152 152
153 def __projectBrowserShowMenu(self, menuName, menu): 153 def __projectBrowserShowMenu(self, menuName, menu):
154 """ 154 """
155 Private slot called, when the the project browser menu or a submenu is 155 Private slot called, when the the project browser menu or a submenu is
156 about to be shown. 156 about to be shown.
157 157
158 @param menuName name of the menu to be shown (string) 158 @param menuName name of the menu to be shown (string)
159 @param menu reference to the menu (QMenu) 159 @param menu reference to the menu (QMenu)
160 """ 160 """
161 if menuName == "Checks" and \ 161 if menuName == "Checks" and \
162 e4App().getObject("Project").getProjectLanguage() == "Python3": 162 e5App().getObject("Project").getProjectLanguage() == "Python3":
163 self.__projectBrowserMenu = menu 163 self.__projectBrowserMenu = menu
164 if self.__projectBrowserAct is None: 164 if self.__projectBrowserAct is None:
165 self.__projectBrowserAct = E4Action(self.trUtf8('Check Syntax'), 165 self.__projectBrowserAct = E4Action(self.trUtf8('Check Syntax'),
166 self.trUtf8('&Syntax...'), 0, 0, 166 self.trUtf8('&Syntax...'), 0, 0,
167 self, "") 167 self, "")
176 176
177 def __projectSyntaxCheck(self): 177 def __projectSyntaxCheck(self):
178 """ 178 """
179 Public slot used to check the project files for bad indentations. 179 Public slot used to check the project files for bad indentations.
180 """ 180 """
181 project = e4App().getObject("Project") 181 project = e5App().getObject("Project")
182 project.saveAllScripts() 182 project.saveAllScripts()
183 files = [os.path.join(project.ppath, file) \ 183 files = [os.path.join(project.ppath, file) \
184 for file in project.pdata["SOURCES"] \ 184 for file in project.pdata["SOURCES"] \
185 if file.endswith(tuple(Preferences.getPython("Python3Extensions")))] 185 if file.endswith(tuple(Preferences.getPython("Python3Extensions")))]
186 186
191 def __projectBrowserSyntaxCheck(self): 191 def __projectBrowserSyntaxCheck(self):
192 """ 192 """
193 Private method to handle the syntax check context menu action of the project 193 Private method to handle the syntax check context menu action of the project
194 sources browser. 194 sources browser.
195 """ 195 """
196 browser = e4App().getObject("ProjectBrowser").getProjectBrowser("sources") 196 browser = e5App().getObject("ProjectBrowser").getProjectBrowser("sources")
197 itm = browser.model().item(browser.currentIndex()) 197 itm = browser.model().item(browser.currentIndex())
198 try: 198 try:
199 fn = itm.fileName() 199 fn = itm.fileName()
200 except AttributeError: 200 except AttributeError:
201 fn = itm.dirName() 201 fn = itm.dirName()
243 243
244 def __editorSyntaxCheck(self): 244 def __editorSyntaxCheck(self):
245 """ 245 """
246 Private slot to handle the syntax check context menu action of the editors. 246 Private slot to handle the syntax check context menu action of the editors.
247 """ 247 """
248 editor = e4App().getObject("ViewManager").activeWindow() 248 editor = e5App().getObject("ViewManager").activeWindow()
249 if editor is not None: 249 if editor is not None:
250 self.__editorSyntaxCheckerDialog = SyntaxCheckerDialog() 250 self.__editorSyntaxCheckerDialog = SyntaxCheckerDialog()
251 self.__editorSyntaxCheckerDialog.show() 251 self.__editorSyntaxCheckerDialog.show()
252 self.__editorSyntaxCheckerDialog.start(editor.getFileName(), 252 self.__editorSyntaxCheckerDialog.start(editor.getFileName(),
253 editor.text()) 253 editor.text())

eric ide

mercurial