[nautilus-python] docs: Move examples into external files
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-python] docs: Move examples into external files
- Date: Thu, 11 Aug 2022 11:39:33 +0000 (UTC)
commit 6e48aa4ed699e326bf420e22428839f7b6f096c3
Author: Jan Tojnar <jtojnar gmail com>
Date: Thu Aug 11 02:08:52 2022 +0200
docs: Move examples into external files
That way, we can easily test them and apply other development tools.
docs/reference/nautilus-python-column-provider.xml | 32 +------------
docs/reference/nautilus-python-info-provider.xml | 26 +----------
.../nautilus-python-location-widget-provider.xml | 16 +------
docs/reference/nautilus-python-menu-provider.xml | 43 +-----------------
.../reference/nautilus-python-overview-example.xml | 30 +------------
.../nautilus-python-property-page-provider.xml | 52 +---------------------
examples/TestExtension.py | 28 ++++++++++++
7 files changed, 39 insertions(+), 188 deletions(-)
---
diff --git a/docs/reference/nautilus-python-column-provider.xml
b/docs/reference/nautilus-python-column-provider.xml
index 8adf2e3..c73fd5f 100644
--- a/docs/reference/nautilus-python-column-provider.xml
+++ b/docs/reference/nautilus-python-column-provider.xml
@@ -2,7 +2,7 @@
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<refentry id="class-nautilus-python-column-provider">
+<refentry id="class-nautilus-python-column-provider" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>Nautilus.ColumnProvider</refname>
<refpurpose>Nautilus.ColumnProvider Reference</refpurpose>
@@ -44,35 +44,7 @@
<example>
<title>Nautilus.ColumnProvider Example</title>
- <programlisting>
-import os
-
-# A way to get unquote working with python 2 and 3
-try:
- from urllib import unquote
-except ImportError:
- from urllib.parse import unquote
-
-from gi.repository import GObject, Nautilus
-
-class ColumnExtension(GObject.GObject, Nautilus.ColumnProvider, Nautilus.InfoProvider):
- def __init__(self):
- pass
-
- def get_columns(self):
- return Nautilus.Column(name="NautilusPython::block_size_column",
- attribute="block_size",
- label="Block size",
- description="Get the block size"),
-
- def update_file_info(self, file):
- if file.get_uri_scheme() != 'file':
- return
-
- filename = unquote(file.get_uri()[7:])
-
- file.add_string_attribute('block_size', str(os.stat(filename).st_blksize))
- </programlisting>
+ <programlisting><xi:include href="../../examples/block-size-column.py" parse="text" /></programlisting>
</example>
</refsect1>
diff --git a/docs/reference/nautilus-python-info-provider.xml
b/docs/reference/nautilus-python-info-provider.xml
index 74e1e42..336590d 100644
--- a/docs/reference/nautilus-python-info-provider.xml
+++ b/docs/reference/nautilus-python-info-provider.xml
@@ -2,7 +2,7 @@
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<refentry id="class-nautilus-python-info-provider">
+<refentry id="class-nautilus-python-info-provider" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>Nautilus.InfoProvider</refname>
<refpurpose>Nautilus.InfoProvider Reference</refpurpose>
@@ -62,29 +62,7 @@
<example>
<title>Nautilus.InfoProvider Example</title>
- <programlisting>
-from gi.repository import Nautilus, GObject
-
-class UpdateFileInfoAsync(GObject.GObject, Nautilus.InfoProvider):
- def __init__(self):
- self.timers = []
- pass
-
- def update_file_info_full(self, provider, handle, closure, file):
- print("update_file_info_full")
- self.timers.append(GObject.timeout_add_seconds(3, self.update_cb, provider, handle, closure))
- return Nautilus.OperationResult.IN_PROGRESS
-
- def update_cb(self, provider, handle, closure):
- print("update_cb")
- Nautilus.info_provider_update_complete_invoke(closure, provider, handle,
Nautilus.OperationResult.FAILED)
-
- def cancel_update(self, provider, handle):
- print("cancel_update")
- for t in self.timers:
- GObject.source_remove(t)
- self.timers = []
- </programlisting>
+ <programlisting><xi:include href="../../examples/docs/update-file-info-async.py" parse="text"
/></programlisting>
</example>
</refsect1>
diff --git a/docs/reference/nautilus-python-location-widget-provider.xml
b/docs/reference/nautilus-python-location-widget-provider.xml
index a4380a2..152b966 100644
--- a/docs/reference/nautilus-python-location-widget-provider.xml
+++ b/docs/reference/nautilus-python-location-widget-provider.xml
@@ -2,7 +2,7 @@
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<refentry id="class-nautilus-python-location-widget-provider">
+<refentry id="class-nautilus-python-location-widget-provider" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>Nautilus.LocationWidgetProvider</refname>
<refpurpose>Nautilus.LocationWidgetProvider Reference</refpurpose>
@@ -39,19 +39,7 @@
<example>
<title>Nautilus.LocationWidgetProvider Example</title>
- <programlisting>
-from gi.repository import Nautilus, GObject, Gtk
-
-class ColumnExtension(GObject.GObject, Nautilus.LocationWidgetProvider):
- def __init__(self):
- pass
-
- def get_widget(self, uri, window):
- entry = Gtk.Entry()
- entry.set_text(uri)
- entry.show()
- return entry
- </programlisting>
+ <programlisting><xi:include href="../../examples/docs/location-widget-provider.py" parse="text"
/></programlisting>
</example>
</refsect1>
diff --git a/docs/reference/nautilus-python-menu-provider.xml
b/docs/reference/nautilus-python-menu-provider.xml
index 69e3f81..63f1ecf 100644
--- a/docs/reference/nautilus-python-menu-provider.xml
+++ b/docs/reference/nautilus-python-menu-provider.xml
@@ -2,7 +2,7 @@
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<refentry id="class-nautilus-python-menu-provider">
+<refentry id="class-nautilus-python-menu-provider" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>Nautilus.MenuProvider</refname>
<refpurpose>Nautilus.MenuProvider Reference</refpurpose>
@@ -70,46 +70,7 @@
<example>
<title>Nautilus.MenuProvider Example</title>
- <programlisting>
-from gi.repository import Nautilus, GObject
-
-class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
- def __init__(self):
- pass
-
- def get_file_items(self, window, files):
- top_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo',
- label='Foo',
- tip='',
- icon='')
-
- submenu = Nautilus.Menu()
- top_menuitem.set_submenu(submenu)
-
- sub_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Bar',
- label='Bar',
- tip='',
- icon='')
- submenu.append_item(sub_menuitem)
-
- return top_menuitem,
-
- def get_background_items(self, window, file):
- submenu = Nautilus.Menu()
- submenu.append_item(Nautilus.MenuItem(name='ExampleMenuProvider::Bar2',
- label='Bar2',
- tip='',
- icon=''))
-
- menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo2',
- label='Foo2',
- tip='',
- icon='')
- menuitem.set_submenu(submenu)
-
- return menuitem,
-
- </programlisting>
+ <programlisting><xi:include href="../../examples/docs/submenu.py" parse="text" /></programlisting>
</example>
diff --git a/docs/reference/nautilus-python-overview-example.xml
b/docs/reference/nautilus-python-overview-example.xml
index 2efa71f..887e266 100644
--- a/docs/reference/nautilus-python-overview-example.xml
+++ b/docs/reference/nautilus-python-overview-example.xml
@@ -10,35 +10,7 @@
<example>
<title>A Simple Extension</title>
- <programlisting>
-from gi.repository import Nautilus, GObject
-
-class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
- def __init__(self):
- pass
-
- def menu_activate_cb(self, menu, file):
- print "menu_activate_cb",file
-
- def get_file_items(self, window, files):
- if len(files) != 1:
- return
-
- file = files[0]
-
- item = Nautilus.MenuItem(
- name="SimpleMenuExtension::Show_File_Name",
- label="Showing %s" % file.get_name(),
- tip="Showing %s" % file.get_name()
- )
- item.connect('activate', self.menu_activate_cb, file)
-
- return [item]
-
- # Even though we're not using background items, Nautilus will generate
- # a warning if the method isn't present
- def get_background_items(self, window, file):
- return None</programlisting>
+ <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.
diff --git a/docs/reference/nautilus-python-property-page-provider.xml
b/docs/reference/nautilus-python-property-page-provider.xml
index 2afa2f9..04d1e04 100644
--- a/docs/reference/nautilus-python-property-page-provider.xml
+++ b/docs/reference/nautilus-python-property-page-provider.xml
@@ -2,7 +2,7 @@
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<refentry id="class-nautilus-python-property-page-provider">
+<refentry id="class-nautilus-python-property-page-provider" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>Nautilus.PropertyPageProvider</refname>
<refpurpose>Nautilus.PropertyPageProvider Reference</refpurpose>
@@ -39,55 +39,7 @@
<example>
<title>Nautilus.PropertyPageProvider Example</title>
- <programlisting>
-import hashlib
-
-# A way to get unquote working with python 2 and 3
-try:
- from urllib import unquote
-except ImportError:
- from urllib.parse import unquote
-
-from gi.repository import Nautilus, Gtk, GObject
-
-class MD5SumPropertyPage(GObject.GObject, Nautilus.PropertyPageProvider):
- def __init__(self):
- pass
-
- def get_property_pages(self, files):
- if len(files) != 1:
- return
-
- file = files[0]
- if file.get_uri_scheme() != 'file':
- return
-
- if file.is_directory():
- return
-
- filename = unquote(file.get_uri()[7:])
-
- self.property_label = Gtk.Label('MD5Sum')
- self.property_label.show()
-
- self.hbox = Gtk.HBox(homogeneous=False, spacing=0)
- self.hbox.show()
-
- label = Gtk.Label('MD5Sum:')
- label.show()
- self.hbox.pack_start(label, False, False, 0)
-
- self.value_label = Gtk.Label()
- self.hbox.pack_start(self.value_label, False, False, 0)
-
- md5sum = hashlib.md5(filename.encode("utf-8")).hexdigest()
- self.value_label.set_text(md5sum)
- self.value_label.show()
-
- return Nautilus.PropertyPage(name="NautilusPython::md5_sum",
- label=self.property_label,
- page=self.hbox),
- </programlisting>
+ <programlisting><xi:include href="../../examples/md5sum-property-page.py" parse="text"
/></programlisting>
</example>
</refsect1>
diff --git a/examples/TestExtension.py b/examples/TestExtension.py
new file mode 100644
index 0000000..1137d31
--- /dev/null
+++ b/examples/TestExtension.py
@@ -0,0 +1,28 @@
+from gi.repository import Nautilus, GObject
+
+class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
+ def __init__(self):
+ pass
+
+ def menu_activate_cb(self, menu, file):
+ print "menu_activate_cb",file
+
+ def get_file_items(self, window, files):
+ if len(files) != 1:
+ return
+
+ file = files[0]
+
+ item = Nautilus.MenuItem(
+ name="SimpleMenuExtension::Show_File_Name",
+ label="Showing %s" % file.get_name(),
+ tip="Showing %s" % file.get_name()
+ )
+ item.connect('activate', self.menu_activate_cb, file)
+
+ return [item]
+
+ # Even though we're not using background items, Nautilus will generate
+ # a warning if the method isn't present
+ def get_background_items(self, window, file):
+ return None
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]