diff -r 373da5610be1 -r b7e3e3b131ea PluginProjectKivy.py --- a/PluginProjectKivy.py Wed Jun 12 18:51:49 2013 +0200 +++ b/PluginProjectKivy.py Wed Jun 12 20:05:16 2013 +0200 @@ -7,9 +7,11 @@ Module implementing the Kivy project plug-in. """ +import os +import glob import fnmatch -from PyQt4.QtCore import QObject +from PyQt4.QtCore import QObject, QTranslator from E5Gui.E5Application import e5App @@ -31,6 +33,23 @@ pyqtApi = 2 # End-of-Header +error = "" + + +def apiFiles(language): + """ + Module function to return the API files made available by this plugin. + + @return list of API filenames (list of string) + """ + if language in ["Python2"]: + apisDir = \ + os.path.join(os.path.dirname(__file__), "ProjectKivy", "APIs") + apis = glob.glob(os.path.join(apisDir, '*.api')) + else: + apis = [] + return apis + class ProjectKivyPlugin(QObject): """ @@ -59,6 +78,9 @@ QObject.__init__(self, ui) self.__ui = ui self.__initialize() + + self.__translator = None + self.__loadTranslator() def __initialize(self): """ @@ -72,9 +94,16 @@ @return tuple of None and activation status (boolean) """ - self.__e5project.registerProjectType("Kivy", self.trUtf8("Kivy"), - self.fileTypesCallback, - lexerAssociationCallback=self.lexerAssociationCallback) + try: + self.__e5project.registerProjectType("Kivy", self.trUtf8("Kivy"), + self.fileTypesCallback, + lexerAssociationCallback=self.lexerAssociationCallback, + progLanguages=["Python2"]) + except TypeError: + # for backward compatibility + self.__e5project.registerProjectType("Kivy", self.trUtf8("Kivy"), + self.fileTypesCallback, + lexerAssociationCallback=self.lexerAssociationCallback) from Project.ProjectBrowser import SourcesBrowserFlag, FormsBrowserFlag, \ TranslationsBrowserFlag, OthersBrowserFlag @@ -87,15 +116,27 @@ LEXERS[self.KivyLexerKey] = self.KivyLexerEntry import QScintilla.Lexers - QScintilla.Lexers.registerLexer( - "Kivy", - self.trUtf8("Kivy"), - "dummy.kv", - self.getLexer, - [self.trUtf8('Kivy Files (*.kv)')], - [self.trUtf8('Kivy Files (*.kv)')], - ['*.kv', '*.kivy'] - ) + if self.__ui.versionIsNewer('5.3.5', '20130611'): + QScintilla.Lexers.registerLexer( + "Kivy", + self.trUtf8("Kivy"), + "dummy.kv", + self.getLexer, + [self.trUtf8('Kivy Files (*.kv *.kivy)')], + [self.trUtf8('Kivy Files (*.kv)')], + ['*.kv', '*.kivy'] + ) + else: + # work around a bug in older versions + QScintilla.Lexers.registerLexer( + "Kivy", + self.trUtf8("Kivy"), + "dummy.kv", + self.getLexer, + self.trUtf8('Kivy Files (*.kv *.kivy)'), + self.trUtf8('Kivy Files (*.kv)'), + ['*.kv', '*.kivy'] + ) return None, True @@ -112,6 +153,26 @@ self.__initialize() + def __loadTranslator(self): + """ + Private method to load the translation file. + """ + if self.__ui is not None: + loc = self.__ui.getLocale() + if loc and loc != "C": + locale_dir = \ + os.path.join(os.path.dirname(__file__), "ProjectKivy", "i18n") + translation = "django_%s" % loc + translator = QTranslator(None) + loaded = translator.load(translation, locale_dir) + if loaded: + self.__translator = translator + e5App().installTranslator(self.__translator) + else: + print("Warning: translation file '{0}' could not be loaded.".format( + translation)) + print("Using default.") + def fileTypesCallback(self): """ Public method get the filetype associations of the Kivy project type.