src/reportlab/lib/styles.py
branchpy33
changeset 3721 0c93dd8ff567
parent 3617 ae5744e97c42
child 3723 99aa837b6703
equal deleted inserted replaced
3720:7a059dde5bf5 3721:0c93dd8ff567
    60         self.refresh()
    60         self.refresh()
    61         self._setKwds(**kw)
    61         self._setKwds(**kw)
    62 
    62 
    63     def _setKwds(self,**kw):
    63     def _setKwds(self,**kw):
    64         #step three - copy keywords if any
    64         #step three - copy keywords if any
    65         for (key, value) in kw.items():
    65         for (key, value) in list(kw.items()):
    66              self.__dict__[key] = value
    66              self.__dict__[key] = value
    67 
    67 
    68     def __repr__(self):
    68     def __repr__(self):
    69         return "<%s '%s'>" % (self.__class__.__name__, self.name)
    69         return "<%s '%s'>" % (self.__class__.__name__, self.name)
    70 
    70 
    71     def refresh(self):
    71     def refresh(self):
    72         """re-fetches attributes from the parent on demand;
    72         """re-fetches attributes from the parent on demand;
    73         use if you have been hacking the styles.  This is
    73         use if you have been hacking the styles.  This is
    74         used by __init__"""
    74         used by __init__"""
    75         if self.parent:
    75         if self.parent:
    76             for (key, value) in self.parent.__dict__.items():
    76             for (key, value) in list(self.parent.__dict__.items()):
    77                 if (key not in ['name','parent']):
    77                 if (key not in ['name','parent']):
    78                     self.__dict__[key] = value
    78                     self.__dict__[key] = value
    79 
    79 
    80     def listAttrs(self, indent=''):
    80     def listAttrs(self, indent=''):
    81         print indent + 'name =', self.name
    81         print(indent + 'name =', self.name)
    82         print indent + 'parent =', self.parent
    82         print(indent + 'parent =', self.parent)
    83         keylist = self.__dict__.keys()
    83         keylist = list(self.__dict__.keys())
    84         keylist.sort()
    84         keylist.sort()
    85         keylist.remove('name')
    85         keylist.remove('name')
    86         keylist.remove('parent')
    86         keylist.remove('parent')
    87         for key in keylist:
    87         for key in keylist:
    88             value = self.__dict__.get(key, None)
    88             value = self.__dict__.get(key, None)
    89             print indent + '%s = %s' % (key, value)
    89             print(indent + '%s = %s' % (key, value))
    90 
    90 
    91     def clone(self, name, parent=None, **kwds):
    91     def clone(self, name, parent=None, **kwds):
    92         r = self.__class__(name,parent)
    92         r = self.__class__(name,parent)
    93         r.__dict__ = self.__dict__.copy()
    93         r.__dict__ = self.__dict__.copy()
    94         r.parent = parent is None and self or parent
    94         r.parent = parent is None and self or parent
   218         self.byName[key] = style
   218         self.byName[key] = style
   219         if alias:
   219         if alias:
   220             self.byAlias[alias] = style
   220             self.byAlias[alias] = style
   221 
   221 
   222     def list(self):
   222     def list(self):
   223         styles = self.byName.items()
   223         styles = list(self.byName.items())
   224         styles.sort()
   224         styles.sort()
   225         alii = {}
   225         alii = {}
   226         for (alias, style) in self.byAlias.items():
   226         for (alias, style) in list(self.byAlias.items()):
   227             alii[style] = alias
   227             alii[style] = alias
   228         for (name, style) in styles:
   228         for (name, style) in styles:
   229             alias = alii.get(style, None)
   229             alias = alii.get(style, None)
   230             print name, alias
   230             print(name, alias)
   231             style.listAttrs('    ')
   231             style.listAttrs('    ')
   232             print
   232             print()
   233 
   233 
   234 def testStyles():
   234 def testStyles():
   235     pNormal = ParagraphStyle('Normal',None)
   235     pNormal = ParagraphStyle('Normal',None)
   236     pNormal.fontName = _baseFontName
   236     pNormal.fontName = _baseFontName
   237     pNormal.fontSize = 12
   237     pNormal.fontSize = 12
   238     pNormal.leading = 14.4
   238     pNormal.leading = 14.4
   239 
   239 
   240     pNormal.listAttrs()
   240     pNormal.listAttrs()
   241     print
   241     print()
   242     pPre = ParagraphStyle('Literal', pNormal)
   242     pPre = ParagraphStyle('Literal', pNormal)
   243     pPre.fontName = 'Courier'
   243     pPre.fontName = 'Courier'
   244     pPre.listAttrs()
   244     pPre.listAttrs()
   245     return pNormal, pPre
   245     return pNormal, pPre
   246 
   246