96 self.__editorAct.triggered[()].connect(self.__editorTabnanny) |
96 self.__editorAct.triggered[()].connect(self.__editorTabnanny) |
97 |
97 |
98 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
98 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
99 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
99 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
100 .showMenu.connect(self.__projectBrowserShowMenu) |
100 .showMenu.connect(self.__projectBrowserShowMenu) |
101 e5App().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened) |
101 e5App().getObject("ViewManager").editorOpenedEd.connect( |
102 e5App().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed) |
102 self.__editorOpened) |
|
103 e5App().getObject("ViewManager").editorClosedEd.connect( |
|
104 self.__editorClosed) |
103 |
105 |
104 for editor in e5App().getObject("ViewManager").getOpenEditors(): |
106 for editor in e5App().getObject("ViewManager").getOpenEditors(): |
105 self.__editorOpened(editor) |
107 self.__editorOpened(editor) |
106 |
108 |
107 return None, True |
109 return None, True |
108 |
110 |
109 def deactivate(self): |
111 def deactivate(self): |
110 """ |
112 """ |
111 Public method to deactivate this plugin. |
113 Public method to deactivate this plugin. |
112 """ |
114 """ |
113 e5App().getObject("Project").showMenu.disconnect(self.__projectShowMenu) |
115 e5App().getObject("Project").showMenu.disconnect( |
|
116 self.__projectShowMenu) |
114 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
117 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
115 .showMenu.disconnect(self.__projectBrowserShowMenu) |
118 .showMenu.disconnect(self.__projectBrowserShowMenu) |
116 e5App().getObject("ViewManager").editorOpenedEd.disconnect(self.__editorOpened) |
119 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
117 e5App().getObject("ViewManager").editorClosedEd.disconnect(self.__editorClosed) |
120 self.__editorOpened) |
|
121 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
|
122 self.__editorClosed) |
118 |
123 |
119 menu = e5App().getObject("Project").getMenu("Checks") |
124 menu = e5App().getObject("Project").getMenu("Checks") |
120 if menu: |
125 if menu: |
121 menu.removeAction(self.__projectAct) |
126 menu.removeAction(self.__projectAct) |
122 |
127 |
123 if self.__projectBrowserMenu: |
128 if self.__projectBrowserMenu: |
124 if self.__projectBrowserAct: |
129 if self.__projectBrowserAct: |
125 self.__projectBrowserMenu.removeAction(self.__projectBrowserAct) |
130 self.__projectBrowserMenu.removeAction( |
|
131 self.__projectBrowserAct) |
126 |
132 |
127 for editor in self.__editors: |
133 for editor in self.__editors: |
128 editor.showMenu.disconnect(self.__editorShowMenu) |
134 editor.showMenu.disconnect(self.__editorShowMenu) |
129 menu = editor.getMenu("Checks") |
135 menu = editor.getMenu("Checks") |
130 if menu is not None: |
136 if menu is not None: |
145 e5App().getObject("Project").getProjectLanguage() in \ |
151 e5App().getObject("Project").getProjectLanguage() in \ |
146 ["Python3", "Python2", "Python"]) |
152 ["Python3", "Python2", "Python"]) |
147 |
153 |
148 def __projectBrowserShowMenu(self, menuName, menu): |
154 def __projectBrowserShowMenu(self, menuName, menu): |
149 """ |
155 """ |
150 Private slot called, when the the project browser context menu or a submenu is |
156 Private slot called, when the the project browser context menu or a |
151 about to be shown. |
157 submenu is about to be shown. |
152 |
158 |
153 @param menuName name of the menu to be shown (string) |
159 @param menuName name of the menu to be shown (string) |
154 @param menu reference to the menu (QMenu) |
160 @param menu reference to the menu (QMenu) |
155 """ |
161 """ |
156 if menuName == "Checks" and \ |
162 if menuName == "Checks" and \ |
157 e5App().getObject("Project").getProjectLanguage() in \ |
163 e5App().getObject("Project").getProjectLanguage() in \ |
158 ["Python3", "Python2", "Python"]: |
164 ["Python3", "Python2", "Python"]: |
159 self.__projectBrowserMenu = menu |
165 self.__projectBrowserMenu = menu |
160 if self.__projectBrowserAct is None: |
166 if self.__projectBrowserAct is None: |
161 self.__projectBrowserAct = E5Action(self.trUtf8('Check Indentations'), |
167 self.__projectBrowserAct = E5Action( |
162 self.trUtf8('&Indentations...'), 0, 0, |
168 self.trUtf8('Check Indentations'), |
163 self, "") |
169 self.trUtf8('&Indentations...'), 0, 0, |
|
170 self, "") |
164 self.__projectBrowserAct.setWhatsThis(self.trUtf8( |
171 self.__projectBrowserAct.setWhatsThis(self.trUtf8( |
165 """<b>Check Indentations...</b>""" |
172 """<b>Check Indentations...</b>""" |
166 """<p>This checks Python files""" |
173 """<p>This checks Python files""" |
167 """ for bad indentations using tabnanny.</p>""" |
174 """ for bad indentations using tabnanny.</p>""" |
168 )) |
175 )) |
178 project = e5App().getObject("Project") |
185 project = e5App().getObject("Project") |
179 project.saveAllScripts() |
186 project.saveAllScripts() |
180 ppath = project.getProjectPath() |
187 ppath = project.getProjectPath() |
181 files = [os.path.join(ppath, file) \ |
188 files = [os.path.join(ppath, file) \ |
182 for file in project.pdata["SOURCES"] \ |
189 for file in project.pdata["SOURCES"] \ |
183 if file.endswith(tuple(Preferences.getPython("Python3Extensions")) + |
190 if file.endswith( |
184 tuple(Preferences.getPython("PythonExtensions")))] |
191 tuple(Preferences.getPython("Python3Extensions")) + |
|
192 tuple(Preferences.getPython("PythonExtensions")))] |
185 |
193 |
186 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog |
194 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog |
187 self.__projectTabnannyDialog = TabnannyDialog() |
195 self.__projectTabnannyDialog = TabnannyDialog() |
188 self.__projectTabnannyDialog.show() |
196 self.__projectTabnannyDialog.show() |
189 self.__projectTabnannyDialog.prepare(files, project) |
197 self.__projectTabnannyDialog.prepare(files, project) |
190 |
198 |
191 def __projectBrowserTabnanny(self): |
199 def __projectBrowserTabnanny(self): |
192 """ |
200 """ |
193 Private method to handle the tabnanny context menu action of the project |
201 Private method to handle the tabnanny context menu action of the |
194 sources browser. |
202 project sources browser. |
195 """ |
203 """ |
196 browser = e5App().getObject("ProjectBrowser").getProjectBrowser("sources") |
204 browser = e5App().getObject("ProjectBrowser").getProjectBrowser( |
|
205 "sources") |
197 itm = browser.model().item(browser.currentIndex()) |
206 itm = browser.model().item(browser.currentIndex()) |
198 try: |
207 try: |
199 fn = itm.fileName() |
208 fn = itm.fileName() |
200 except AttributeError: |
209 except AttributeError: |
201 fn = itm.dirName() |
210 fn = itm.dirName() |
238 @param editor reference to the editor |
247 @param editor reference to the editor |
239 """ |
248 """ |
240 if menuName == "Checks": |
249 if menuName == "Checks": |
241 if not self.__editorAct in menu.actions(): |
250 if not self.__editorAct in menu.actions(): |
242 menu.addAction(self.__editorAct) |
251 menu.addAction(self.__editorAct) |
243 self.__editorAct.setEnabled(editor.isPy3File() or editor.isPy2File()) |
252 self.__editorAct.setEnabled( |
|
253 editor.isPy3File() or editor.isPy2File()) |
244 |
254 |
245 def __editorTabnanny(self): |
255 def __editorTabnanny(self): |
246 """ |
256 """ |
247 Private slot to handle the tabnanny context menu action of the editors. |
257 Private slot to handle the tabnanny context menu action of the editors. |
248 """ |
258 """ |
249 editor = e5App().getObject("ViewManager").activeWindow() |
259 editor = e5App().getObject("ViewManager").activeWindow() |
250 if editor is not None: |
260 if editor is not None: |
251 if editor.checkDirty() and editor.getFileName() is not None: |
261 if editor.checkDirty() and editor.getFileName() is not None: |
252 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog |
262 from CheckerPlugins.Tabnanny.TabnannyDialog import \ |
|
263 TabnannyDialog |
253 self.__editorTabnannyDialog = TabnannyDialog() |
264 self.__editorTabnannyDialog = TabnannyDialog() |
254 self.__editorTabnannyDialog.show() |
265 self.__editorTabnannyDialog.show() |
255 self.__editorTabnannyDialog.start(editor.getFileName()) |
266 self.__editorTabnannyDialog.start(editor.getFileName()) |