widgetbase.py: add CloneMixin, make use of in axes.py
authorrgbecker
Tue, 06 Jul 2010 16:19:30 +0000
changeset 3408 f2ce23ab0644
parent 3407 d2e72807782b
child 3410 d300c040b7b7
widgetbase.py: add CloneMixin, make use of in axes.py
src/reportlab/graphics/charts/axes.py
src/reportlab/graphics/widgetbase.py
--- a/src/reportlab/graphics/charts/axes.py	Tue Jul 06 14:02:50 2010 +0000
+++ b/src/reportlab/graphics/charts/axes.py	Tue Jul 06 16:19:30 2010 +0000
@@ -1286,18 +1286,12 @@
                             if not i:  #first one
                                 x0, y0, x1, y1 = label.getBounds()
                                 if x0 < a_x:
-                                    label, olabel = label.__class__(),label
-                                    label.__dict__.clear()
-                                    label.__dict__.update(olabel.__dict__)
-                                    label.dx += a_x - x0
+                                    label = label.clone(dx=label.dx + a_x - x0)
                             if i==nticks1:  #final one
                                 a_x1 = a_x +self._length
                                 x0, y0, x1, y1 = label.getBounds()
                                 if x1 > a_x1:
-                                    label, olabel = label.__class__(),label
-                                    label.__dict__.clear()
-                                    label.__dict__.update(olabel.__dict__)
-                                    label.dx -= x1-a_x1
+                                    label=label.clone(dx=label.dx-x1+a_x1)
                     g.add(label)
 
         return g
--- a/src/reportlab/graphics/widgetbase.py	Tue Jul 06 14:02:50 2010 +0000
+++ b/src/reportlab/graphics/widgetbase.py	Tue Jul 06 16:19:30 2010 +0000
@@ -177,6 +177,14 @@
 
 _ItemWrapper={}
 
+class CloneMixin:
+    def clone(self,**kwds):
+        n = self.__class__()
+        n.__dict__.clear()
+        n.__dict__.update(self.__dict__)
+        if kwds: n.__dict__.update(kwds)
+        return n
+
 class TypedPropertyCollection(PropHolder):
     """A container with properties for objects of the same kind.
 
@@ -206,7 +214,7 @@
         self.__dict__['_children'] = {}
 
     def wKlassFactory(self,Klass):
-        class WKlass(Klass):
+        class WKlass(Klass,CloneMixin):
             def __getattr__(self,name):
                 try:
                     return self.__class__.__bases__[0].__getattr__(self,name)