1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
<?xml version="1.0" standalone="no"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<chapter id="nautilus-python-overview-example"
xmlns:xi="http://www.w3.org/2001/XInclude">
<title>A Simple Extension</title>
<para>Create an empty file with the following code:</para>
<example>
<title>A Simple Extension</title>
<programlisting><xi:include href="../../examples/TestExtension.py" parse="text" /></programlisting>
</example>
<para>Save this file as TestExtension.py in the ~/.local/share/nautilus-python/extensions folder.
You may need to create this folder. To run, simply restart Nautilus.</para>
<para>Once Nautilus restarts, right-click on a file and you should see a new menu item,
"Showing #filename#". It is as simple as that!</para>
<para>As mentioned above, in order to
get loaded by Nautilus, a python extension must import the Nautilus module from gi.repository,
create a class derived from a nautilus *Provider and a gobject.GObject, and create the methods that
will be called by Nautilus when it requests information from its providers.
In this case, when someone right-clicks on a file, Nautilus will ask all of its
MenuProviders for additional menu items to show the user. When folders or files are clicked,
the get_file_items method is called and a list of Nautilus.MenuItems is expected.</para>
</chapter>
|