src/reportlab/graphics/shapes.py
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3762 4817e577522d
equal deleted inserted replaced
3722:29c11b905751 3723:99aa837b6703
   181                 canvas._drawTimeResize(w,h)
   181                 canvas._drawTimeResize(w,h)
   182 
   182 
   183 class _SetKeyWordArgs:
   183 class _SetKeyWordArgs:
   184     def __init__(self, keywords={}):
   184     def __init__(self, keywords={}):
   185         """In general properties may be supplied to the constructor."""
   185         """In general properties may be supplied to the constructor."""
   186         for key, value in list(keywords.items()):
   186         for key, value in keywords.items():
   187             setattr(self, key, value)
   187             setattr(self, key, value)
   188 
   188 
   189 
   189 
   190 #################################################################
   190 #################################################################
   191 #
   191 #
   306 
   306 
   307         #basic nodes have no children so this is easy.
   307         #basic nodes have no children so this is easy.
   308         #for more complex objects like widgets you
   308         #for more complex objects like widgets you
   309         #may need to override this.
   309         #may need to override this.
   310         props = {}
   310         props = {}
   311         for key, value in list(self.__dict__.items()):
   311         for key, value in self.__dict__.items():
   312             if key[0:1] != '_':
   312             if key[0:1] != '_':
   313                 props[key] = value
   313                 props[key] = value
   314         return props
   314         return props
   315 
   315 
   316     def setProperties(self, props):
   316     def setProperties(self, props):
   339         are present; and (if a checking function is found)
   339         are present; and (if a checking function is found)
   340         checks each attribute.  Either succeeds or raises
   340         checks each attribute.  Either succeeds or raises
   341         an informative exception."""
   341         an informative exception."""
   342 
   342 
   343         if self._attrMap is not None:
   343         if self._attrMap is not None:
   344             for key in list(self.__dict__.keys()):
   344             for key in self.__dict__.keys():
   345                 if key[0] != '_':
   345                 if key[0] != '_':
   346                     assert key in self._attrMap, "Unexpected attribute %s found in %s" % (key, self)
   346                     assert key in self._attrMap, "Unexpected attribute %s found in %s" % (key, self)
   347             for (attr, metavalue) in list(self._attrMap.items()):
   347             for attr, metavalue in self._attrMap.items():
   348                 assert hasattr(self, attr), "Missing attribute %s from %s" % (attr, self)
   348                 assert hasattr(self, attr), "Missing attribute %s from %s" % (attr, self)
   349                 value = getattr(self, attr)
   349                 value = getattr(self, attr)
   350                 assert metavalue.validate(value), "Invalid value %s for attribute %s in class %s" % (value, attr, self.__class__.__name__)
   350                 assert metavalue.validate(value), "Invalid value %s for attribute %s in class %s" % (value, attr, self.__class__.__name__)
   351 
   351 
   352     if shapeChecking:
   352     if shapeChecking:
   472 
   472 
   473     def _copyNamedContents(self,obj,aKeys=None,noCopy=('contents',)):
   473     def _copyNamedContents(self,obj,aKeys=None,noCopy=('contents',)):
   474         from copy import copy
   474         from copy import copy
   475         self_contents = self.contents
   475         self_contents = self.contents
   476         if not aKeys: aKeys = list(self._attrMap.keys())
   476         if not aKeys: aKeys = list(self._attrMap.keys())
   477         for (k, v) in list(self.__dict__.items()):
   477         for k, v in self.__dict__.items():
   478             if v in self_contents:
   478             if v in self_contents:
   479                 pos = self_contents.index(v)
   479                 pos = self_contents.index(v)
   480                 setattr(obj, k, obj.contents[pos])
   480                 setattr(obj, k, obj.contents[pos])
   481             elif k in aKeys and k not in noCopy:
   481             elif k in aKeys and k not in noCopy:
   482                 setattr(obj, k, copy(v))
   482                 setattr(obj, k, copy(v))
   576             s = self.__class__.__name__+'('
   576             s = self.__class__.__name__+'('
   577             for n in args[1:]:
   577             for n in args[1:]:
   578                 v = P[n]
   578                 v = P[n]
   579                 del P[n]
   579                 del P[n]
   580                 s = s + '%s,' % _repr(v,I)
   580                 s = s + '%s,' % _repr(v,I)
   581             for n,v in list(P.items()):
   581             for n,v in P.items():
   582                 v = P[n]
   582                 v = P[n]
   583                 s = s + '%s=%s,' % (n, _repr(v,I))
   583                 s = s + '%s=%s,' % (n, _repr(v,I))
   584             return s[:-1]+')'
   584             return s[:-1]+')'
   585         else:
   585         else:
   586             return repr(self)
   586             return repr(self)
   615 
   615 
   616 def _extraKW(self,pfx,**kw):
   616 def _extraKW(self,pfx,**kw):
   617     kw.update(self.__dict__)
   617     kw.update(self.__dict__)
   618     R = {}
   618     R = {}
   619     n = len(pfx)
   619     n = len(pfx)
   620     for k in list(kw.keys()):
   620     for k in kw.keys():
   621         if k.startswith(pfx):
   621         if k.startswith(pfx):
   622             R[k[n:]] = kw[k]
   622             R[k[n:]] = kw[k]
   623     return R
   623     return R
   624 
   624 
   625 class Drawing(Group, Flowable):
   625 class Drawing(Group, Flowable):
   659     def _renderPy(self):
   659     def _renderPy(self):
   660         I = {'reportlab.graphics.shapes': ['_DrawingEditorMixin','Drawing','Group']}
   660         I = {'reportlab.graphics.shapes': ['_DrawingEditorMixin','Drawing','Group']}
   661         G = _renderGroupPy(self._explode(),'self',I)
   661         G = _renderGroupPy(self._explode(),'self',I)
   662         n = 'ExplodedDrawing_' + self.__class__.__name__
   662         n = 'ExplodedDrawing_' + self.__class__.__name__
   663         s = '#Autogenerated by ReportLab guiedit do not edit\n'
   663         s = '#Autogenerated by ReportLab guiedit do not edit\n'
   664         for m, o in list(I.items()):
   664         for m, o in I.items():
   665             s = s + 'from %s import %s\n' % (m,string.replace(str(o)[1:-1],"'",""))
   665             s = s + 'from %s import %s\n' % (m,string.replace(str(o)[1:-1],"'",""))
   666         s = s + '\nclass %s(_DrawingEditorMixin,Drawing):\n' % n
   666         s = s + '\nclass %s(_DrawingEditorMixin,Drawing):\n' % n
   667         s = s + '\tdef __init__(self,width=%s,height=%s,*args,**kw):\n' % (self.width,self.height)
   667         s = s + '\tdef __init__(self,width=%s,height=%s,*args,**kw):\n' % (self.width,self.height)
   668         s = s + '\t\tDrawing.__init__(self,width,height,*args,**kw)\n'
   668         s = s + '\t\tDrawing.__init__(self,width,height,*args,**kw)\n'
   669         s = s + G
   669         s = s + G