--- a/Plugins/PluginTabnanny.py Sat Mar 22 09:12:19 2014 +0100 +++ b/Plugins/PluginTabnanny.py Sat Mar 22 09:45:56 2014 +0100 @@ -11,12 +11,12 @@ import os -from PyQt4.QtCore import QObject +from PyQt4.QtCore import QObject, pyqtSignal from E5Gui.E5Application import e5App - from E5Gui.E5Action import E5Action +from Utilities import determinePythonVersion import Preferences # Start-Of-Header @@ -40,7 +40,12 @@ class TabnannyPlugin(QObject): """ Class implementing the Tabnanny plugin. + + @signal indentChecked(str, bool, str, str) emited when the indent + check was done. """ + indentChecked = pyqtSignal(str, bool, str, str) + def __init__(self, ui): """ Constructor @@ -51,6 +56,17 @@ self.__ui = ui self.__initialize() + self.backgroundService = e5App().getObject("BackgroundService") + + path = os.path.join( + os.path.dirname(__file__), 'CheckerPlugins', 'Tabnanny') + for lang in ['Python2', 'Python3']: + self.backgroundService.serviceConnect( + 'indent', lang, path, 'Tabnanny', + lambda *args: self.indentChecked.emit(*args), + lambda fx, fn, ver, msg: self.indentChecked.emit( + fn, True, "1", msg)) + def __initialize(self): """ Private slot to (re)initialize the plugin. @@ -66,6 +82,24 @@ self.__editorAct = None self.__editorTabnannyDialog = None + def indentCheck(self, lang, filename, source): + """ + Method to prepare a style check on one Python source file in another + task. + + @param lang language of the file or None to determine by internal + algorithm (str or None) + @param filename source filename (string) + @param source string containing the code to check (string) + """ + if lang is None: + lang = 'Python{0}'.format(determinePythonVersion(filename, source)) + if lang not in ['Python2', 'Python3']: + return + + self.backgroundService.enqueueRequest( + 'indent', lang, filename, [source]) + def activate(self): """ Public method to activate this plugin. @@ -197,7 +231,7 @@ tuple(Preferences.getPython("PythonExtensions")))] from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog - self.__projectTabnannyDialog = TabnannyDialog() + self.__projectTabnannyDialog = TabnannyDialog(self) self.__projectTabnannyDialog.show() self.__projectTabnannyDialog.prepare(files, project) @@ -215,7 +249,7 @@ fn = itm.dirName() from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog - self.__projectBrowserTabnannyDialog = TabnannyDialog() + self.__projectBrowserTabnannyDialog = TabnannyDialog(self) self.__projectBrowserTabnannyDialog.show() self.__projectBrowserTabnannyDialog.start(fn) @@ -266,6 +300,6 @@ if editor.checkDirty() and editor.getFileName() is not None: from CheckerPlugins.Tabnanny.TabnannyDialog import \ TabnannyDialog - self.__editorTabnannyDialog = TabnannyDialog() + self.__editorTabnannyDialog = TabnannyDialog(self) self.__editorTabnannyDialog.show() self.__editorTabnannyDialog.start(editor.getFileName())