File: thunarx-python-renamer-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 (140 lines) | stat: -rw-r--r-- 4,533 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?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-renamer-provider">
  <refnamediv>
    <refname>Thunarx.RenamerProvider</refname>
    <refpurpose>Thunarx.RenamerProvider Reference</refpurpose>
  </refnamediv>

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

  <refsect1>
    <title>Synopsis</title>

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

      <methodsynopsis language="python">
        <methodname><link linkend="method-Thunarx-renamer-provider--get-renamers">get_renamers</link></methodname>
        <methodparam><parameter role="keyword">files</parameter></methodparam>
      </methodsynopsis>
    </classsynopsis>
  </refsect1>

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

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

      <para>
The Thunarx.RenamerProvider interface is implemented by extensions which provide additional bulk renamers that should be used by the bulk rename dialog in Thunar.
      </para>
      
      <example>
        <title>A Thunarx.RenamerProvider Extension</title>
        <programlisting>
from gi.repository import GObject, Gtk, Thunarx

class ThunarxPythonRenamer(Thunarx.Renamer):
    __gtype_name__ = "ThunarxPythonRenamer"
    prefix = GObject.property(type=str)
    
    def __init__(self):
        Thunarx.Renamer.__init__(self)

        # Set properties to be saved in the settings files
        self.set_property("prefix", "__")
        
        self.set_name("Example Python Renamer")
        self.set_help_url("http://www.google.com")
     
        hbox = Gtk.HBox(0, False)
        
        label = Gtk.Label("Prefix:")
        hbox.pack_start(label, False, False, 0)
        
        self.entry = Gtk.Entry()
        self.entry.set_text(self.get_property("prefix"))
        self.entry.connect("changed", self.entry_changed)
        hbox.pack_start(self.entry, False, False, 0)
        
        label.show()
        self.entry.show()
        self.add(hbox)
        hbox.show()
    
    def do_process(self, file, text, index):
        prefix = self.entry.get_text()
        return prefix + text

    def entry_changed(self, widget):
        self.set_property("prefix", widget.get_text())
        
        # Emitting this will cause the do_process method to be called
        self.emit("changed")

    def do_get_menu_items(self, window, files):
        return [Gtk.Action(name="TPR:SomeAction", label="Some Action", tooltip=None, icon=Gtk.STOCK_OPEN)]

    def do_load(self, settings):
        """
        Loads settings saved in ~/.config/Thunar/renamerrc
        """
        if settings.haskey("Prefix"):
            self.set_property("prefix", settings["Prefix"])
            self.entry.set_text(self.get_property("prefix"))

    def do_save(self, settings):
        """
        If do_save is overriden, you must rebuild the settings dictionary and then
        return it.
        """
        settings["Prefix"] = self.get_property("prefix")
        return settings

class ThunarxRenamerPlugin(GObject.GObject, Thunarx.RenamerProvider):
    def __init__(self):
        pass
    
    def get_renamers(self):
        return [ThunarxPythonRenamer()]
        </programlisting>
      </example>
  </refsect1>

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

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

        <refsect2 id="method-Thunarx-renamer-provider--get-renamers">
          <title>Thunarx.RenamerProvider.get_renamers</title>

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

          <variablelist>
            <varlistentry>
              <term><emphasis>Returns</emphasis>&nbsp;:</term>
              <listitem><simpara>the list of Thunarx.Renamer objects provided by the specified provider.</simpara></listitem>
            </varlistentry>
          </variablelist>

          <para>
Returns the list of ThunarxRenamers provided by the specified provider.
          </para>
        </refsect2>
    </refsect1>

</refentry>