9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 import os |
12 import os |
13 |
13 |
14 from PyQt4.QtCore import QObject |
14 from PyQt4.QtCore import QObject, pyqtSignal |
15 |
15 |
16 from E5Gui.E5Application import e5App |
16 from E5Gui.E5Application import e5App |
17 |
|
18 from E5Gui.E5Action import E5Action |
17 from E5Gui.E5Action import E5Action |
19 |
18 |
|
19 from Utilities import determinePythonVersion |
20 import Preferences |
20 import Preferences |
21 |
21 |
22 # Start-Of-Header |
22 # Start-Of-Header |
23 name = "Tabnanny Plugin" |
23 name = "Tabnanny Plugin" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
38 |
38 |
39 |
39 |
40 class TabnannyPlugin(QObject): |
40 class TabnannyPlugin(QObject): |
41 """ |
41 """ |
42 Class implementing the Tabnanny plugin. |
42 Class implementing the Tabnanny plugin. |
|
43 |
|
44 @signal indentChecked(str, bool, str, str) emited when the indent |
|
45 check was done. |
43 """ |
46 """ |
|
47 indentChecked = pyqtSignal(str, bool, str, str) |
|
48 |
44 def __init__(self, ui): |
49 def __init__(self, ui): |
45 """ |
50 """ |
46 Constructor |
51 Constructor |
47 |
52 |
48 @param ui reference to the user interface object (UI.UserInterface) |
53 @param ui reference to the user interface object (UI.UserInterface) |
49 """ |
54 """ |
50 super(TabnannyPlugin, self).__init__(ui) |
55 super(TabnannyPlugin, self).__init__(ui) |
51 self.__ui = ui |
56 self.__ui = ui |
52 self.__initialize() |
57 self.__initialize() |
53 |
58 |
|
59 self.backgroundService = e5App().getObject("BackgroundService") |
|
60 |
|
61 path = os.path.join( |
|
62 os.path.dirname(__file__), 'CheckerPlugins', 'Tabnanny') |
|
63 for lang in ['Python2', 'Python3']: |
|
64 self.backgroundService.serviceConnect( |
|
65 'indent', lang, path, 'Tabnanny', |
|
66 lambda *args: self.indentChecked.emit(*args), |
|
67 lambda fx, fn, ver, msg: self.indentChecked.emit( |
|
68 fn, True, "1", msg)) |
|
69 |
54 def __initialize(self): |
70 def __initialize(self): |
55 """ |
71 """ |
56 Private slot to (re)initialize the plugin. |
72 Private slot to (re)initialize the plugin. |
57 """ |
73 """ |
58 self.__projectAct = None |
74 self.__projectAct = None |
63 self.__projectBrowserTabnannyDialog = None |
79 self.__projectBrowserTabnannyDialog = None |
64 |
80 |
65 self.__editors = [] |
81 self.__editors = [] |
66 self.__editorAct = None |
82 self.__editorAct = None |
67 self.__editorTabnannyDialog = None |
83 self.__editorTabnannyDialog = None |
|
84 |
|
85 def indentCheck(self, lang, filename, source): |
|
86 """ |
|
87 Method to prepare a style check on one Python source file in another |
|
88 task. |
|
89 |
|
90 @param lang language of the file or None to determine by internal |
|
91 algorithm (str or None) |
|
92 @param filename source filename (string) |
|
93 @param source string containing the code to check (string) |
|
94 """ |
|
95 if lang is None: |
|
96 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
|
97 if lang not in ['Python2', 'Python3']: |
|
98 return |
|
99 |
|
100 self.backgroundService.enqueueRequest( |
|
101 'indent', lang, filename, [source]) |
68 |
102 |
69 def activate(self): |
103 def activate(self): |
70 """ |
104 """ |
71 Public method to activate this plugin. |
105 Public method to activate this plugin. |
72 |
106 |
195 if file.endswith( |
229 if file.endswith( |
196 tuple(Preferences.getPython("Python3Extensions")) + |
230 tuple(Preferences.getPython("Python3Extensions")) + |
197 tuple(Preferences.getPython("PythonExtensions")))] |
231 tuple(Preferences.getPython("PythonExtensions")))] |
198 |
232 |
199 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog |
233 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog |
200 self.__projectTabnannyDialog = TabnannyDialog() |
234 self.__projectTabnannyDialog = TabnannyDialog(self) |
201 self.__projectTabnannyDialog.show() |
235 self.__projectTabnannyDialog.show() |
202 self.__projectTabnannyDialog.prepare(files, project) |
236 self.__projectTabnannyDialog.prepare(files, project) |
203 |
237 |
204 def __projectBrowserTabnanny(self): |
238 def __projectBrowserTabnanny(self): |
205 """ |
239 """ |
213 fn = itm.fileName() |
247 fn = itm.fileName() |
214 except AttributeError: |
248 except AttributeError: |
215 fn = itm.dirName() |
249 fn = itm.dirName() |
216 |
250 |
217 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog |
251 from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog |
218 self.__projectBrowserTabnannyDialog = TabnannyDialog() |
252 self.__projectBrowserTabnannyDialog = TabnannyDialog(self) |
219 self.__projectBrowserTabnannyDialog.show() |
253 self.__projectBrowserTabnannyDialog.show() |
220 self.__projectBrowserTabnannyDialog.start(fn) |
254 self.__projectBrowserTabnannyDialog.start(fn) |
221 |
255 |
222 def __editorOpened(self, editor): |
256 def __editorOpened(self, editor): |
223 """ |
257 """ |
264 editor = e5App().getObject("ViewManager").activeWindow() |
298 editor = e5App().getObject("ViewManager").activeWindow() |
265 if editor is not None: |
299 if editor is not None: |
266 if editor.checkDirty() and editor.getFileName() is not None: |
300 if editor.checkDirty() and editor.getFileName() is not None: |
267 from CheckerPlugins.Tabnanny.TabnannyDialog import \ |
301 from CheckerPlugins.Tabnanny.TabnannyDialog import \ |
268 TabnannyDialog |
302 TabnannyDialog |
269 self.__editorTabnannyDialog = TabnannyDialog() |
303 self.__editorTabnannyDialog = TabnannyDialog(self) |
270 self.__editorTabnannyDialog.show() |
304 self.__editorTabnannyDialog.show() |
271 self.__editorTabnannyDialog.start(editor.getFileName()) |
305 self.__editorTabnannyDialog.start(editor.getFileName()) |