home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2091 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.2 KB  |  75 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from style import Style, TextProperties, ListLevelProperties
  6. from text import ListStyle, ListLevelStyleNumber, ListLevelStyleBullet
  7. _MAX_LIST_LEVEL = 10
  8. SHOW_ALL_LEVELS = True
  9. SHOW_ONE_LEVEL = False
  10.  
  11. def styleFromString(name, specifiers, delim, spacing, showAllLevels):
  12.     specArray = specifiers.split(delim)
  13.     return styleFromList(name, specArray, spacing, showAllLevels)
  14.  
  15.  
  16. def styleFromList(styleName, specArray, spacing, showAllLevels):
  17.     bullet = ''
  18.     numPrefix = ''
  19.     numSuffix = ''
  20.     numberFormat = ''
  21.     cssLengthNum = 0
  22.     cssLengthUnits = ''
  23.     numbered = False
  24.     displayLevels = 0
  25.     listStyle = ListStyle(name = styleName)
  26.     numFormatPattern = re.compile('([1IiAa])')
  27.     cssLengthPattern = re.compile('([^a-z]+)\\s*([a-z]+)?')
  28.     m = cssLengthPattern.search(spacing)
  29.     if m != None:
  30.         cssLengthNum = float(m.group(1))
  31.         if m.lastindex == 2:
  32.             cssLengthUnits = m.group(2)
  33.         
  34.     
  35.     i = 0
  36.     while i < len(specArray):
  37.         specification = specArray[i]
  38.         m = numFormatPattern.search(specification)
  39.         if m != None:
  40.             numberFormat = m.group(1)
  41.             numPrefix = specification[0:m.start(1)]
  42.             numSuffix = specification[m.end(1):]
  43.             bullet = ''
  44.             numbered = True
  45.             if showAllLevels:
  46.                 displayLevels = i + 1
  47.             else:
  48.                 displayLevels = 1
  49.         else:
  50.             bullet = specification
  51.             numPrefix = ''
  52.             numSuffix = ''
  53.             numberFormat = ''
  54.             displayLevels = 1
  55.             numbered = False
  56.         if numbered:
  57.             lls = ListLevelStyleNumber(level = i + 1)
  58.             if numPrefix != '':
  59.                 lls.setAttribute('numprefix', numPrefix)
  60.             
  61.             if numSuffix != '':
  62.                 lls.setAttribute('numsuffix', numSuffix)
  63.             
  64.             lls.setAttribute('displaylevels', displayLevels)
  65.         else:
  66.             lls = ListLevelStyleBullet(level = i + 1, bulletchar = bullet[0])
  67.         llp = ListLevelProperties()
  68.         llp.setAttribute('spacebefore', str(cssLengthNum * (i + 1)) + cssLengthUnits)
  69.         llp.setAttribute('minlabelwidth', str(cssLengthNum) + cssLengthUnits)
  70.         lls.addElement(llp)
  71.         listStyle.addElement(lls)
  72.         i += 1
  73.     return listStyle
  74.  
  75.