[Yt-svn] yt-commit r1046 - in trunk/yt: . raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Fri Dec 26 08:13:38 PST 2008


Author: mturk
Date: Fri Dec 26 08:13:37 2008
New Revision: 1046
URL: http://yt.spacepope.org/changeset/1046

Log:
I'm sick of keeping track of the callbacks, so we're going to use a
'self-registering plugin' pattern, as per Effbot
(http://effbot.org/zone/metaclass-plugins.htm)

Callbacks will now auto-register, and we simply import all of the
auto-registered callbacks.  The "exec" statement is kind of ugly, but I think
it's better than modifying the local dictionary.

The callback interface will likely change, too, as we will probably move to
adding them all as methods to RavenPlot, rather than manually doing
add_callback with an instance.



Modified:
   trunk/yt/mods.py
   trunk/yt/raven/Callbacks.py

Modified: trunk/yt/mods.py
==============================================================================
--- trunk/yt/mods.py	(original)
+++ trunk/yt/mods.py	Fri Dec 26 08:13:37 2008
@@ -50,11 +50,10 @@
 fieldInfo = EnzoFieldInfo
 
 # Now individual component imports from raven
-from yt.raven import PlotCollection, PlotCollectionInteractive, \
-    QuiverCallback, ParticleCallback, ContourCallback, \
-    GridBoundaryCallback, UnitBoundaryCallback, \
-    LinePlotCallback, CuttingQuiverCallback, ClumpContourCallback, \
-    HopCircleCallback
+from yt.raven import PlotCollection, PlotCollectionInteractive
+from yt.raven.Callbacks import callback_registry
+for name, cls in callback_registry:
+    exec("from yt.raven import %s" % name)
 
 # Optional component imports from raven
 try:

Modified: trunk/yt/raven/Callbacks.py
==============================================================================
--- trunk/yt/raven/Callbacks.py	(original)
+++ trunk/yt/raven/Callbacks.py	Fri Dec 26 08:13:37 2008
@@ -32,7 +32,14 @@
 
 import _MPL
 
+callback_registry = []
+
 class PlotCallback(object):
+    class __metaclass__(type):
+        def __init__(cls, name, b, d):
+            type.__init__(name, b, d)
+            callback_registry.append((name, cls))
+
     def __init__(self, *args, **kwargs):
         pass
 



More information about the yt-svn mailing list