![]() _instances 30 31 def update_ui( self, window): 32 self. _instances = ExamplePyWindowHelper( self, window) 26 27 def deactivate( self, window): 28 self. _instances = 23 24 def activate( self, window): 25 self. ![]() _window 18 19 class ExamplePyPlugin( gedit. _plugin = None 13 14 def update_ui( self): 15 # Called whenever the window has been updated (active tab 16 # changed, etc.) 17 print " Plugin update for ", self. _plugin = plugin 8 9 def deactivate( self): 10 print " Plugin stopped for ", self. At the most minimal level, it just defines one class derived from gedit.Plugin defining activate, deactivate and update_ui:ġ import gedit 2 3 class ExamplePyWindowHelper: 4 def _init_( self, plugin, window): 5 print " Plugin created for ", window 6 self. The plugin is called examplepy, so we create examplepy.py. Website: optionally, the plugins website.This will show up in the about dialog of the plugin (plugins list in the preference dialog) Authors: a list of people who wrote the plugin.This will show up in the plugins list in the preference dialog Description: a short description of the plugin.IAge: the plugin version, this is always 2 ![]() As with normal Python applications you need to put a _init_.py in that directory) Module: the file in which your plugin is located (leaving out the extension. Loader: which loader Gedit needs to use for Python plugins this is python gedit-plugin file which will give Gedit information about our new plugin.Ĭopyright=Copyright © 2006 Jesse van den Kieboom As stated in Files needed we first need to create a. Now we are ready to actually write a plugin. The update_ui function is called when the plugin is requested to see if it needs to update its UI. This way every window has a separate object controlling it. This object will now handle that window and do whatever the plugin needs to do. Whenever a new Gedit window is created and activate is run, I instantiate a new object of this class and attach it to the window. The approach I find easy to implement (also implemented in the example) is to create a new class. On the other hand, when a window is destroyed the deactivate function is called. Whenever a new window is created the activate function on your plugin will be called with one argument (the window). This is what the activate and deactivate are for. However, plugins usually apply to windows. Plugins are therefore only instantiated once (during load) of the master Gedit application. When Gedit starts it looks for an existing Gedit instance, hands over control to that instance and exits. Now, Gedit is an application which usually only runs one instance, even if you launch it multiple times. A Python plugin is derived from the gedit.Plugin base class which defines the following functions (which you can override): It's important to read this section carefully. Most plugin writers find the way Gedit plugins work counterintuitive at first glance. Both of these files need to be placed in either the system-wide plugins directory /usr/lib/gedit-2/plugins/, or in the user plugins directory, which may need to be created, ~/.gnome2/gedit/plugins/. The second file is the actual Python code. One file ( pluginname.gedit-plugin) is to tell Gedit where the plugin can be found, what it's called, a short description, who's the author, etc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |