26 deactivateable = True |
26 deactivateable = True |
27 version = "10.0.0" |
27 version = "10.0.0" |
28 className = "ProjectKivyPlugin" |
28 className = "ProjectKivyPlugin" |
29 packageName = "ProjectKivy" |
29 packageName = "ProjectKivy" |
30 shortDescription = "Project support for Kivy projects." |
30 shortDescription = "Project support for Kivy projects." |
31 longDescription = ( |
31 longDescription = """This plugin implements project support for Kivy projects.""" |
32 """This plugin implements project support for Kivy projects.""" |
|
33 ) |
|
34 needsRestart = False |
32 needsRestart = False |
35 pyqtApi = 2 |
33 pyqtApi = 2 |
36 # End-of-Header |
34 # End-of-Header |
37 |
35 |
38 error = "" |
36 error = "" |
39 |
37 |
40 |
38 |
41 def apiFiles(language): |
39 def apiFiles(language): |
42 """ |
40 """ |
43 Module function to return the API files made available by this plugin. |
41 Module function to return the API files made available by this plugin. |
44 |
42 |
45 @param language language to get API file for |
43 @param language language to get API file for |
46 @type str |
44 @type str |
47 @return list of API filenames |
45 @return list of API filenames |
48 @rtype list of str |
46 @rtype list of str |
49 """ |
47 """ |
50 if language in ["Python3"]: |
48 if language in ["Python3"]: |
51 apisDir = os.path.join(os.path.dirname(__file__), |
49 apisDir = os.path.join(os.path.dirname(__file__), "ProjectKivy", "APIs") |
52 "ProjectKivy", "APIs") |
50 return glob.glob(os.path.join(apisDir, "*.api")) |
53 return glob.glob(os.path.join(apisDir, '*.api')) |
|
54 else: |
51 else: |
55 return [] |
52 return [] |
56 |
53 |
57 |
54 |
58 class ProjectKivyPlugin(QObject): |
55 class ProjectKivyPlugin(QObject): |
59 """ |
56 """ |
60 Class implementing the Kivy project plugin. |
57 Class implementing the Kivy project plugin. |
61 """ |
58 """ |
|
59 |
62 lexerAssociations = { |
60 lexerAssociations = { |
63 "*.kv": "Pygments|Kivy", |
61 "*.kv": "Pygments|Kivy", |
64 "*.kivy": "Pygments|Kivy", |
62 "*.kivy": "Pygments|Kivy", |
65 } |
63 } |
66 |
64 |
67 KivyLexerKey = 'KivyLexer' |
65 KivyLexerKey = "KivyLexer" |
68 KivyLexerEntry = ( |
66 KivyLexerEntry = ( |
69 'ProjectKivy.KivyLexer', |
67 "ProjectKivy.KivyLexer", |
70 'Kivy', |
68 "Kivy", |
71 ('kivy', 'kv'), |
69 ("kivy", "kv"), |
72 ('*.kv', '*.kivy'), |
70 ("*.kv", "*.kivy"), |
73 ('application/x-kivy',) |
71 ("application/x-kivy",), |
74 ) |
72 ) |
75 |
73 |
76 def __init__(self, ui): |
74 def __init__(self, ui): |
77 """ |
75 """ |
78 Constructor |
76 Constructor |
79 |
77 |
80 @param ui reference to the user interface object |
78 @param ui reference to the user interface object |
81 @type UserInterface |
79 @type UserInterface |
82 """ |
80 """ |
83 QObject.__init__(self, ui) |
81 QObject.__init__(self, ui) |
84 self.__ui = ui |
82 self.__ui = ui |
85 self.__initialize() |
83 self.__initialize() |
86 |
84 |
87 self.__translator = None |
85 self.__translator = None |
88 self.__loadTranslator() |
86 self.__loadTranslator() |
89 |
87 |
90 def __initialize(self): |
88 def __initialize(self): |
91 """ |
89 """ |
92 Private slot to (re)initialize the plugin. |
90 Private slot to (re)initialize the plugin. |
93 """ |
91 """ |
94 self.__ericProject = ericApp().getObject("Project") |
92 self.__ericProject = ericApp().getObject("Project") |
95 |
93 |
96 def activate(self): |
94 def activate(self): |
97 """ |
95 """ |
98 Public method to activate this plugin. |
96 Public method to activate this plugin. |
99 |
97 |
100 @return tuple of None and activation status |
98 @return tuple of None and activation status |
101 @rtype bool |
99 @rtype bool |
102 """ |
100 """ |
103 self.__ericProject.registerProjectType( |
101 self.__ericProject.registerProjectType( |
104 "Kivy", self.tr("Kivy"), self.fileTypesCallback, |
102 "Kivy", |
|
103 self.tr("Kivy"), |
|
104 self.fileTypesCallback, |
105 lexerAssociationCallback=self.lexerAssociationCallback, |
105 lexerAssociationCallback=self.lexerAssociationCallback, |
106 progLanguages=["Python3"]) |
106 progLanguages=["Python3"], |
107 |
107 ) |
|
108 |
108 from Project.ProjectBrowser import ( |
109 from Project.ProjectBrowser import ( |
109 SourcesBrowserFlag, FormsBrowserFlag, TranslationsBrowserFlag, |
110 SourcesBrowserFlag, |
110 OthersBrowserFlag |
111 FormsBrowserFlag, |
111 ) |
112 TranslationsBrowserFlag, |
|
113 OthersBrowserFlag, |
|
114 ) |
|
115 |
112 Preferences.setProjectBrowserFlagsDefault( |
116 Preferences.setProjectBrowserFlagsDefault( |
113 "Kivy", |
117 "Kivy", |
114 SourcesBrowserFlag | |
118 SourcesBrowserFlag |
115 FormsBrowserFlag | |
119 | FormsBrowserFlag |
116 TranslationsBrowserFlag | |
120 | TranslationsBrowserFlag |
117 OthersBrowserFlag, |
121 | OthersBrowserFlag, |
118 ) |
122 ) |
119 |
123 |
120 LEXERS[self.KivyLexerKey] = self.KivyLexerEntry |
124 LEXERS[self.KivyLexerKey] = self.KivyLexerEntry |
121 import QScintilla.Lexers |
125 import QScintilla.Lexers |
|
126 |
122 QScintilla.Lexers.registerLexer( |
127 QScintilla.Lexers.registerLexer( |
123 "Pygments|Kivy", |
128 "Pygments|Kivy", |
124 self.tr("Kivy"), |
129 self.tr("Kivy"), |
125 "dummy.kv", |
130 "dummy.kv", |
126 self.getLexer, |
131 self.getLexer, |
127 [self.tr('Kivy Files (*.kv *.kivy)')], |
132 [self.tr("Kivy Files (*.kv *.kivy)")], |
128 [self.tr('Kivy Files (*.kv)')], |
133 [self.tr("Kivy Files (*.kv)")], |
129 ['*.kv', '*.kivy'] |
134 ["*.kv", "*.kivy"], |
130 ) |
135 ) |
131 |
136 |
132 return None, True |
137 return None, True |
133 |
138 |
134 def deactivate(self): |
139 def deactivate(self): |
135 """ |
140 """ |
136 Public method to deactivate this plugin. |
141 Public method to deactivate this plugin. |
137 """ |
142 """ |
138 self.__ericProject.unregisterProjectType("Kivy") |
143 self.__ericProject.unregisterProjectType("Kivy") |
139 |
144 |
140 import QScintilla.Lexers |
145 import QScintilla.Lexers |
|
146 |
141 QScintilla.Lexers.unregisterLexer("Kivy") |
147 QScintilla.Lexers.unregisterLexer("Kivy") |
142 if self.KivyLexerKey in LEXERS: |
148 if self.KivyLexerKey in LEXERS: |
143 del LEXERS[self.KivyLexerKey] |
149 del LEXERS[self.KivyLexerKey] |
144 |
150 |
145 self.__initialize() |
151 self.__initialize() |
146 |
152 |
147 def __loadTranslator(self): |
153 def __loadTranslator(self): |
148 """ |
154 """ |
149 Private method to load the translation file. |
155 Private method to load the translation file. |
150 """ |
156 """ |
151 if self.__ui is not None: |
157 if self.__ui is not None: |
152 loc = self.__ui.getLocale() |
158 loc = self.__ui.getLocale() |
153 if loc and loc != "C": |
159 if loc and loc != "C": |
154 locale_dir = os.path.join( |
160 locale_dir = os.path.join( |
155 os.path.dirname(__file__), "ProjectKivy", "i18n") |
161 os.path.dirname(__file__), "ProjectKivy", "i18n" |
|
162 ) |
156 translation = "kivy_{0}".format(loc) |
163 translation = "kivy_{0}".format(loc) |
157 translator = QTranslator(None) |
164 translator = QTranslator(None) |
158 loaded = translator.load(translation, locale_dir) |
165 loaded = translator.load(translation, locale_dir) |
159 if loaded: |
166 if loaded: |
160 self.__translator = translator |
167 self.__translator = translator |
161 ericApp().installTranslator(self.__translator) |
168 ericApp().installTranslator(self.__translator) |
162 else: |
169 else: |
163 print("Warning: translation file '{0}' could not be" |
170 print( |
164 " loaded.".format(translation)) |
171 "Warning: translation file '{0}' could not be" |
|
172 " loaded.".format(translation) |
|
173 ) |
165 print("Using default.") |
174 print("Using default.") |
166 |
175 |
167 def fileTypesCallback(self): |
176 def fileTypesCallback(self): |
168 """ |
177 """ |
169 Public method get the filetype associations of the Kivy project type. |
178 Public method get the filetype associations of the Kivy project type. |
170 |
179 |
171 @return dictionary with file type associations |
180 @return dictionary with file type associations |
172 @rtype dict |
181 @rtype dict |
173 """ |
182 """ |
174 if self.__ericProject.getProjectType() == "Kivy": |
183 if self.__ericProject.getProjectType() == "Kivy": |
175 return { |
184 return { |
177 "*.kivy": "SOURCES", |
186 "*.kivy": "SOURCES", |
178 "*.py": "SOURCES", |
187 "*.py": "SOURCES", |
179 } |
188 } |
180 else: |
189 else: |
181 return {} |
190 return {} |
182 |
191 |
183 def lexerAssociationCallback(self, filename): |
192 def lexerAssociationCallback(self, filename): |
184 """ |
193 """ |
185 Public method to get the lexer association of the Kivy project type for |
194 Public method to get the lexer association of the Kivy project type for |
186 a file. |
195 a file. |
187 |
196 |
188 @param filename name of the file |
197 @param filename name of the file |
189 @type str |
198 @type str |
190 @return name of the lexer (Pygments lexers are prefixed with |
199 @return name of the lexer (Pygments lexers are prefixed with |
191 'Pygments|') |
200 'Pygments|') |
192 @rtype str |
201 @rtype str |
193 """ |
202 """ |
194 for pattern, language in self.lexerAssociations.items(): |
203 for pattern, language in self.lexerAssociations.items(): |
195 if fnmatch.fnmatch(filename, pattern): |
204 if fnmatch.fnmatch(filename, pattern): |
196 return language |
205 return language |
197 |
206 |
198 return "" |
207 return "" |
199 |
208 |
200 def getLexer(self, parent=None): |
209 def getLexer(self, parent=None): |
201 """ |
210 """ |
202 Public method to instantiate a Pygments Kivy lexer object. |
211 Public method to instantiate a Pygments Kivy lexer object. |
203 |
212 |
204 @param parent reference to the parent object |
213 @param parent reference to the parent object |
205 @type QObject |
214 @type QObject |
206 @return reference to the instanciated lexer object |
215 @return reference to the instanciated lexer object |
207 @rtype QsciLexer |
216 @rtype QsciLexer |
208 """ |
217 """ |
209 from QScintilla.Lexers.LexerPygments import LexerPygments |
218 from QScintilla.Lexers.LexerPygments import LexerPygments |
|
219 |
210 lexer = LexerPygments(parent, name="Kivy") |
220 lexer = LexerPygments(parent, name="Kivy") |
211 if lexer.canStyle(): |
221 if lexer.canStyle(): |
212 return lexer |
222 return lexer |
213 else: |
223 else: |
214 return None |
224 return None |
215 |
225 |
|
226 |
216 # |
227 # |
217 # eflag: noqa = M801, M811 |
228 # eflag: noqa = M801, M811 |