[Xfce4-commits] <thunarx-python:master> Reworked the renamer plugin example slightly

Adam Plumb noreply at xfce.org
Thu May 27 18:14:04 CEST 2010


Updating branch refs/heads/master
         to 9de2a5e6ecad3f7f0c7d9bb5a8f15a28382e9598 (commit)
       from 4b353168b92a063511b7cb4474351839c893065d (commit)

commit 9de2a5e6ecad3f7f0c7d9bb5a8f15a28382e9598
Author: Adam Plumb <adamplumb at gmail.com>
Date:   Thu Jan 14 09:16:03 2010 -0500

    Reworked the renamer plugin example slightly

 examples/thunarx-renamer-plugin.py |   37 +++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/examples/thunarx-renamer-plugin.py b/examples/thunarx-renamer-plugin.py
index 4dcc500..046b5de 100644
--- a/examples/thunarx-renamer-plugin.py
+++ b/examples/thunarx-renamer-plugin.py
@@ -4,39 +4,41 @@ import gobject
 
 class ThunarxPythonRenamer(thunarx.Renamer):
     __gtype_name__ = "ThunarxPythonRenamer"
-    test = gobject.property(type=str)
+    prefix = gobject.property(type=str)
     
     def __init__(self):
         thunarx.Renamer.__init__(self)
 
         # Set properties to be saved in the settings files
-        self.set_property("test", "blah")
+        self.set_property("prefix", "__")
         
-        self.set_name("Adam's Renamer")
+        self.set_name("Example Python Renamer")
         self.set_help_url("http://www.google.com")
      
         hbox = gtk.HBox(0, False)
         
-        label = gtk.Label("Setting 1:")
+        label = gtk.Label("Prefix:")
         hbox.pack_start(label, False, False, 0)
         
-        entry = gtk.Entry()
-        entry.connect("changed", self.do_changed)
-        hbox.pack_start(entry, 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()
-        entry.show()
+        self.entry.show()
         self.add(hbox)
         hbox.show()
     
     def do_process(self, file, text, index):
-        if text.startswith("__"):
-            return text.replace("__", "")
-        else:
-            return "__" + text
+        prefix = self.entry.get_text()
+        return prefix + text
 
-    def do_changed(self, widget):
-        pass
+    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_actions(self, window, files):
         return [gtk.Action("TPR:SomeAction", "Some Action", None, gtk.STOCK_OPEN)]
@@ -45,15 +47,16 @@ class ThunarxPythonRenamer(thunarx.Renamer):
         """
         Loads settings saved in ~/.config/Thunar/renamerrc
         """
-        print "loading settings"
+        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["test"] = "blah"
-        
+        settings["Prefix"] = self.get_property("prefix")
         return settings
 
 class ThunarxRenamerPlugin(thunarx.RenamerProvider):



More information about the Xfce4-commits mailing list