[eog-plugins] [slideshowshuffle] Port to new plugin API



commit 7db1f14d5c18470e10ff798a3278708fd93aef3c
Author: Felix Riemann <friemann gnome org>
Date:   Fri Mar 18 15:44:47 2011 +0100

    [slideshowshuffle] Port to new plugin API

 configure.ac                                       |    2 +-
 plugins/slideshowshuffle/Makefile.am               |    6 +-
 ...sktop.in => slideshowshuffle.plugin.desktop.in} |    2 +-
 plugins/slideshowshuffle/slideshowshuffle.py       |   42 ++++++++++++-------
 4 files changed, 31 insertions(+), 21 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9073fa5..1b346fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -213,7 +213,7 @@ then
 fi
 
 # Disable plugins that are not yet ported to eog-3.0
-UNPORTED_PLUGINS="postasa pythonconsole slideshowshuffle"
+UNPORTED_PLUGINS="postasa pythonconsole"
 for pl in $UNPORTED_PLUGINS
 do
 	undef_plugin "$pl" "not yet ported to 3.0"
diff --git a/plugins/slideshowshuffle/Makefile.am b/plugins/slideshowshuffle/Makefile.am
index 8dc8988..a3fda64 100644
--- a/plugins/slideshowshuffle/Makefile.am
+++ b/plugins/slideshowshuffle/Makefile.am
@@ -1,13 +1,13 @@
 # Slideshow Shuffle plugin
 plugindir = $(libdir)/eog/plugins
-plugin_in_files = slideshowshuffle.eog-plugin.desktop.in
+plugin_in_files = slideshowshuffle.plugin.desktop.in
 
 plugin_PYTHON = \
 	slideshowshuffle.py
 
-%.eog-plugin: %.eog-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(AM_V_GEN)$(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(AM_V_GEN)$(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
 
-plugin_DATA = $(plugin_in_files:.eog-plugin.desktop.in=.eog-plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
 
 EXTRA_DIST = $(plugin_in_files)
 
diff --git a/plugins/slideshowshuffle/slideshowshuffle.eog-plugin.desktop.in b/plugins/slideshowshuffle/slideshowshuffle.plugin.desktop.in
similarity index 94%
rename from plugins/slideshowshuffle/slideshowshuffle.eog-plugin.desktop.in
rename to plugins/slideshowshuffle/slideshowshuffle.plugin.desktop.in
index 80e8e7e..986de8b 100644
--- a/plugins/slideshowshuffle/slideshowshuffle.eog-plugin.desktop.in
+++ b/plugins/slideshowshuffle/slideshowshuffle.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Eog Plugin]
+[Plugin]
 Loader=python
 Module=slideshowshuffle
 IAge=2
diff --git a/plugins/slideshowshuffle/slideshowshuffle.py b/plugins/slideshowshuffle/slideshowshuffle.py
index 104da85..3cdaafa 100644
--- a/plugins/slideshowshuffle/slideshowshuffle.py
+++ b/plugins/slideshowshuffle/slideshowshuffle.py
@@ -15,25 +15,33 @@
 # along with this program; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-import eog, random
+from gi.repository import GObject, Gtk, Eog
+import random
+
+class SlideshowShufflePlugin(GObject.Object, Eog.WindowActivatable):
+
+    # Override EogWindowActivatable's window property
+    window = GObject.property(type=Eog.Window)
 
-class SlideshowShufflePlugin(eog.Plugin):
     def __init__(self):
-        eog.Plugin.__init__(self)
+        GObject.Object.__init__(self)
 
-    def activate(self, window):
+    def do_activate(self):
         random.seed()
         self.slideshow = False
         self.state_handler_id = \
-            window.connect('window-state-event', self.state_changed_cb)
+            self.window.connect('window-state-event', self.state_changed_cb, self)
 
-    def deactivate(self, window):
-        window.disconnect(self.state_handler_id)
+    def do_deactivate(self):
+        self.window.disconnect(self.state_handler_id)
 
-    def state_changed_cb(self, window, data = None):
-        mode = window.get_mode()
+    # The callback functions are done statically to avoid causing additional
+    # references on the window property causing eog to not quit correctly.
+    @staticmethod
+    def state_changed_cb(window, event, self):
+        mode = self.window.get_mode()
 
-        if mode == eog.WindowMode(3) and not self.slideshow:
+        if mode == Eog.WindowMode(3) and not self.slideshow:
             # Slideshow starts
             self.slideshow = True
 
@@ -52,17 +60,18 @@ class SlideshowShufflePlugin(eog.Plugin):
                 self.map[uri] = supply.pop(random.randint(0, len(supply) - 1))
 
             # Put random sort function in place
-            window.get_store().\
-                set_default_sort_func(self.random_sort_function)
-        elif mode == eog.WindowMode(1) and self.slideshow:
+            self.window.get_store().\
+                set_default_sort_func(self.random_sort_function, self)
+        elif mode == Eog.WindowMode(1) and self.slideshow:
             # Slideshow ends
             self.slideshow = False
 
             # Put alphabetic sort function in place
-            window.get_store().\
+            self.window.get_store().\
                 set_default_sort_func(self.alphabetic_sort_function)
 
-    def random_sort_function(self, store, iter1, iter2, data = None):
+    @staticmethod
+    def random_sort_function(store, iter1, iter2, self):
         pos1 = self.map[store[iter1][2].get_uri_for_display()]
         pos2 = self.map[store[iter2][2].get_uri_for_display()]
 
@@ -73,7 +82,8 @@ class SlideshowShufflePlugin(eog.Plugin):
         else:
             return 0
 
-    def alphabetic_sort_function(self, store, iter1, iter2, data = None):
+    @staticmethod
+    def alphabetic_sort_function(store, iter1, iter2, data = None):
         uri1 = store[iter1][2].get_uri_for_display().lower()
         uri2 = store[iter2][2].get_uri_for_display().lower()
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]