{"id":25,"date":"2005-09-09T18:15:01","date_gmt":"2005-09-09T17:15:01","guid":{"rendered":"https:\/\/raphael.slinckx.net\/blog\/?p=25"},"modified":"2006-06-19T22:39:36","modified_gmt":"2006-06-19T20:39:36","slug":"gedit-python-plugins","status":"publish","type":"post","link":"https:\/\/raphael.slinckx.net\/blog\/2005-09-09\/gedit-python-plugins","title":{"rendered":"Gedit Python Plugins"},"content":{"rendered":"<p>I have been putting together a python plugin system for gedit, so far it seems to work:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/raphael.slinckx.net\/images\/gedit-python.png\" alt=\"Gedit showing the python console\" \/><\/p>\n<p>I heavily used the <a href=\"http:\/\/cvs.gnome.org\/viewcvs\/nautilus-python\/src\/\">nautilus-python<\/a>, and <a href=\"http:\/\/cvs.gnome.org\/viewcvs\/epiphany\/src\/\">epiphany source code<\/a> to see how this is done, thanks to them !<\/p>\n<p>Notice how the window title has been updated by the command in the console. The clever reader may also recognize the same <a href=\"http:\/\/cvs.gnome.org\/viewcvs\/epiphany-extensions\/extensions\/python-console\/console.py?rev=1.1&#038;view=markup\">python console<\/a> as used in epiphany, simply because i just stole all it&#8217;s code, thanks Adam Hooper !<\/p>\n<p>Now for the code, it looks like:<\/p>\n<pre>\r\nimport gedit\r\n\r\n# Inheriting from gedit.Plugin is the key here\r\nclass MyPlugin(gedit.Plugin):\r\n\tdef __init__(self):\r\n\t\tgedit.Plugin.__init__(self)\r\n\r\n\tdef activate(self, window):\r\n\t\tpass\r\n\r\n\tdef deactivate(self, window):\r\n\t\tpass\r\n\r\n\tdef update_ui(self, window):\r\n\t\tpass\r\n<\/pre>\n<p>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:<\/p>\n<pre>\r\n[Gedit Plugin]\r\nModule=console\r\nIAge=2\r\nLang=python\r\nName=Python Console\r\nDescription=A Python Console inside gedit.\r\nAuthors=Raphael Slinckx <raphael @slinckx.net>\r\nCopyright=Copyright \u00c2\u00a9 2005 Raphael Slinckx\r\nWebsite=http:\/\/www.gedit.org\r\n<\/raphael><\/pre>\n<p>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 <code>__init__.py<\/code> !<\/p>\n<p>Now, Paolo if you don&#8217;t mind, you can come back on IRC \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been putting together a python plugin system for gedit, so far it seems to work: 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-planet-gnome","category-software"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}