Thunarx.RenamerProvider

Thunarx.RenamerProvider — Thunarx.RenamerProvider Reference

Synopsis

 Thunarx.RenamerProvider {
  get_renamers(files);
}

Description

The Thunarx.RenamerProvider interface is implemented by extensions which provide additional bulk renamers that should be used by the bulk rename dialog in Thunar.

Example 5. A Thunarx.RenamerProvider Extension

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
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()]

Passive Methods

Thunarx.RenamerProvider.get_renamers

get_renamers(files);

Returns :

the list of Thunarx.Renamer objects provided by the specified provider.

Returns the list of ThunarxRenamers provided by the specified provider.