PluginExtensionProtobuf.py

changeset 10
362689624e2d
parent 8
24fdd6e43cd7
child 12
8ddcd9d47bdf
equal deleted inserted replaced
9:eb218f60e411 10:362689624e2d
12 from PyQt6.QtCore import QCoreApplication, QObject, QTranslator 12 from PyQt6.QtCore import QCoreApplication, QObject, QTranslator
13 13
14 from eric7 import Globals, Preferences 14 from eric7 import Globals, Preferences
15 from eric7.EricWidgets import EricMessageBox 15 from eric7.EricWidgets import EricMessageBox
16 from eric7.EricWidgets.EricApplication import ericApp 16 from eric7.EricWidgets.EricApplication import ericApp
17 from ExtensionProtobuf import protoclbr
17 from ExtensionProtobuf.ProjectProtocolsBrowser import ProjectProtocolsBrowser 18 from ExtensionProtobuf.ProjectProtocolsBrowser import ProjectProtocolsBrowser
18 19
19 # Start-Of-Header 20 # Start-Of-Header
20 name = "Protobuf and gRPC Extension Plugin" 21 name = "Protobuf and gRPC Extension Plugin"
21 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 22 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
22 autoactivate = True 23 autoactivate = True
23 deactivateable = True 24 deactivateable = True
24 version = "10.0.2" 25 version = "10.1.0"
25 className = "ProtobufExtensionPlugin" 26 className = "ProtobufExtensionPlugin"
26 packageName = "ExtensionProtobuf" 27 packageName = "ExtensionProtobuf"
27 shortDescription = "Support for the development of Protobuf and gRPC projects" 28 shortDescription = "Support for the development of Protobuf and gRPC projects"
28 longDescription = ( 29 longDescription = (
29 "This plugin adds support for the development of Protobuf and gRPC related" 30 "This plugin adds support for the development of Protobuf and gRPC related"
208 Public method to activate this plug-in. 209 Public method to activate this plug-in.
209 210
210 @return tuple of None and activation status 211 @return tuple of None and activation status
211 @rtype bool 212 @rtype bool
212 """ 213 """
214 from eric7.QScintilla import Lexers
215 from eric7.Utilities import ClassBrowsers
216
213 global error, protobufExtensionPluginObject 217 global error, protobufExtensionPluginObject
214 error = "" # clear previous error 218 error = "" # clear previous error
215 219
216 if self.__ui.versionIsNewer("22.12"): 220 if self.__ui.versionIsNewer("22.12"):
217 protobufExtensionPluginObject = self 221 protobufExtensionPluginObject = self
218 222
219 self.__browser = ProjectProtocolsBrowser(self) 223 self.__browser = ProjectProtocolsBrowser(self)
224
225 Lexers.registerLexer(
226 "Protocol Buffer",
227 self.tr("Protocol Buffer (protobuf)"),
228 "dummy.proto",
229 self.getLexer,
230 [self.tr("Protocol Buffer Files (*.proto)")],
231 [self.tr("Protocol Buffer Files (*.proto)")],
232 ["*.proto"],
233 os.path.join("ExtensionProtobuf", "icons", "protobuf"),
234 )
235
236 ClassBrowsers.registerClassBrowser(
237 "Protocol Buffer",
238 protoclbr.readmodule_ex,
239 protoclbr.scan,
240 self.getFileIcon,
241 [".proto"],
242 )
220 243
221 return None, True 244 return None, True
222 else: 245 else:
223 EricMessageBox.warning( 246 EricMessageBox.warning(
224 self.__ui, 247 self.__ui,
237 260
238 def deactivate(self): 261 def deactivate(self):
239 """ 262 """
240 Public method to deactivate this plug-in. 263 Public method to deactivate this plug-in.
241 """ 264 """
265 from eric7.QScintilla import Lexers
266 from eric7.Utilities import ClassBrowsers
267
268 Lexers.unregisterLexer("Protocol Buffer")
269 ClassBrowsers.registerClassBrowser("Protocol Buffer")
270
242 self.__browser.deactivate() 271 self.__browser.deactivate()
243 272
244 self.__initialize() 273 self.__initialize()
245 274
246 def __loadTranslator(self): 275 def __loadTranslator(self):
288 @param value the value to be set 317 @param value the value to be set
289 @type any 318 @type any
290 """ 319 """
291 Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value) 320 Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value)
292 321
322 def getLexer(self, parent=None):
323 """
324 Public method to instantiate a Pygments Protocol Buffer lexer object.
325
326 @param parent reference to the parent object
327 @type QObject
328 @return reference to the instanciated lexer object
329 @rtype QsciLexer
330 """
331 from eric7.QScintilla.Lexers.LexerPygments import LexerPygments
332
333 lexer = LexerPygments(parent, name="Protocol Buffer")
334 if lexer.canStyle():
335 return lexer
336 else:
337 return None
338
339 def getFileIcon(self, filename=""):
340 """
341 Public method to get the name of a file icon.
342
343 @param filename file name (defaults to "")
344 @type str (optional)
345 @return name of a file icon
346 @rtype str
347 """
348 return os.path.join("ExtensionProtobuf", "icons", "protobuf")
349
293 350
294 def installDependencies(pipInstall): 351 def installDependencies(pipInstall):
295 """ 352 """
296 Function to install dependencies of this plug-in. 353 Function to install dependencies of this plug-in.
297 354

eric ide

mercurial