Archive for September, 2005

Gedit Python Plugins

Friday, September 9th, 2005

I have been putting together a python plugin system for gedit, so far it seems to work:

Gedit showing the python console

I heavily used the nautilus-python, and epiphany source code to see how this is done, thanks to them !

Notice how the window title has been updated by the command in the console. The clever reader may also recognize the same python console as used in epiphany, simply because i just stole all it’s code, thanks Adam Hooper !

Now for the code, it looks like:

import gedit

# Inheriting from gedit.Plugin is the key here
class MyPlugin(gedit.Plugin):
	def __init__(self):
		gedit.Plugin.__init__(self)

	def activate(self, window):
		pass

	def deactivate(self, window):
		pass

	def update_ui(self, window):
		pass

The three callbacks are the same used for C plugins, you can do your init/deinit stuff and react to UI changes. The other thing to do is to write a xx.gedit-plugin file to tell gedit that there is a plugin:

[Gedit Plugin]
Module=console
IAge=2
Lang=python
Name=Python Console
Description=A Python Console inside gedit.
Authors=Raphael Slinckx 
Copyright=Copyright © 2005 Raphael Slinckx
Website=http://www.gedit.org

You must specify the langage type, so gedit knows which loader to use, and use Module to give the module name of your plugin, generally the filename without the .py extension, but it can also be a directory containing __init__.py !

Now, Paolo if you don’t mind, you can come back on IRC 🙂