File: thunarx-renamer-plugin.py

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 (65 lines) | stat: -rw-r--r-- 2,076 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
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 2")
        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 [Thunarx.MenuItem(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()]