File: thunarx-python-property-page-provider.xml

package info (click to toggle)
thunarx-python 0.5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: xml: 1,500; ansic: 678; python: 136; makefile: 106; sh: 11
file content (126 lines) | stat: -rw-r--r-- 4,186 bytes parent folder | download | duplicates (2)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?xml version="1.0" standalone="no"?>
<!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-thunarx-python-property-page-provider">
  <refnamediv>
    <refname>Thunarx.PropertyPageProvider</refname>
    <refpurpose>Thunarx.PropertyPageProvider Reference</refpurpose>
  </refnamediv>

<!-- ******************************* -->
<!-- BEGIN OF SYNOPSIS -->
<!-- ******************************* -->

  <refsect1>
    <title>Synopsis</title>

    <classsynopsis language="python">
      <ooclass><classname>Thunarx.PropertyPageProvider</classname></ooclass>

      <methodsynopsis language="python">
        <methodname><link linkend="method-Thunarx-property-page-provider--get-pages">get_pages</link></methodname>
        <methodparam><parameter role="keyword">files</parameter></methodparam>
      </methodsynopsis>
    </classsynopsis>
  </refsect1>

<!-- ********************************** -->
<!-- BEGIN OF DESCRIPTION -->
<!-- ********************************** -->

  <refsect1 id="description-property-page-provider">
    <title>Description</title>

      <para>
      To add a property page to the file properties dialog, extensions must implement the ThunarxPropertyPageProvider interface. This interface has only one virtual method, get_pages, that is passed a list of Thunarx.FileInfo objects and returns a list of Thunarx.PropertyPage objects. 
      </para>
  </refsect1>

<example>
    <title>A Thunarx.PropertyPageProvider plugin</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 GObject, Gtk, Thunarx

class ThunarxPropertyPagePlugin(GObject.GObject, Thunarx.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:])

        hbox = Gtk.HBox(0, False)
        hbox.show()

        label = Gtk.Label('MD5Sum:')
        label.show()
        hbox.pack_start(label, True, True, 0)

        value_label = Gtk.Label()
        hbox.pack_start(value_label, True, True, 0)

        md5sum = hashlib.md5(filename.encode("utf-8")).hexdigest()
        value_label.set_text(md5sum)
        value_label.show()

        page = Thunarx.PropertyPage()
        page.set_label("MD5")
        page.add(hbox)

        return [page]
    </programlisting>
</example>

<!-- ****************************** -->
<!-- BEGIN OF METHODS -->
<!-- ****************************** -->

  <refsect1>
        <title>Passive Methods</title>

        <refsect2 id="method-Thunarx-property-page-provider--get-pages">
          <title>Thunarx.PropertyPageProvider.get_pages</title>

          <programlisting><methodsynopsis language="python">
            <methodname>get_pages</methodname>
        <methodparam><parameter role="keyword">files</parameter></methodparam>
          </methodsynopsis></programlisting>

          <variablelist>
            <varlistentry>
	            <term><parameter role="keyword">files</parameter>&nbsp;:</term>
	            <listitem><simpara>a list of <link linkend="class-thunarx-python-file-info"><classname>Thunarx.FileInfo</classname></link> objects.</simpara></listitem>
            </varlistentry>
            <varlistentry>
              <term><emphasis>Returns</emphasis>&nbsp;:</term>
              <listitem><simpara>a list of <link linkend="class-thunarx-python-property-page"><classname>Thunarx.PropertyPage</classname></link> objects</simpara></listitem>
            </varlistentry>
          </variablelist>

          <para>
                This function is called by Thunar when it wants property page items from the extension.  
                It is called in the main thread before a property page is shown, so it should return quickly.
          </para>
        </refsect2>
    </refsect1>

</refentry>