[gimp/gimp-2-10] plug-ins: avoid running pygimp plug-ins derived from gimpplugin.plugin at each startup



commit 71fe5c00fd9949dce4bc94da22439012e9f42210
Author: Ell <ell_se yahoo com>
Date:   Fri Jan 25 04:26:08 2019 -0500

    plug-ins: avoid running pygimp plug-ins derived from gimpplugin.plugin at each startup
    
    When initializing a pygimp plug-in derived from gimpplugin.plugin,
    only pass the plug-in's init() and quit() functions to gimp.main()
    if the plug-in actually implements them, instead of passing the
    default NOP versions.  This avoids plug-ins that don't implement
    init() from being registered as having an init function, causing
    them to be run at each startup.
    
    (cherry picked from commit 9851bc89621ba39f561561359bdf54ff391c4617)

 plug-ins/pygimp/gimpplugin.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/plug-ins/pygimp/gimpplugin.py b/plug-ins/pygimp/gimpplugin.py
index 6a5ce1be9b..eeaa3f33ba 100644
--- a/plug-ins/pygimp/gimpplugin.py
+++ b/plug-ins/pygimp/gimpplugin.py
@@ -42,7 +42,21 @@ import gimp
 
 class plugin:
     def start(self):
-        gimp.main(self.init, self.quit, self.query, self._run)
+        # only pass the init()/quit() member functions to gimp.main() if the
+        # plug-in overrides them, to avoid the default NOP versions from being
+        # called unnecessarily.  in particular, this avoids plug-ins that don't
+        # implement init() from being registered as having an init function,
+        # causing them to be run at each startup.
+        def get_func(name):
+            if getattr(self.__class__, name) != getattr(plugin, name):
+                return getattr(self, name)
+            else:
+                return None
+
+        gimp.main(get_func("init"),
+                  get_func("quit"),
+                  self.query,
+                  self._run)
 
     def init(self):
         pass


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