home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2383 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.6 KB  |  145 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from pygments.token import Token, STANDARD_TYPES
  5.  
  6. class StyleMeta(type):
  7.     
  8.     def __new__(mcs, name, bases, dct):
  9.         obj = type.__new__(mcs, name, bases, dct)
  10.         for token in STANDARD_TYPES:
  11.             if token not in obj.styles:
  12.                 obj.styles[token] = ''
  13.                 continue
  14.         
  15.         
  16.         def colorformat(text):
  17.             if text[0:1] == '#':
  18.                 col = text[1:]
  19.                 if len(col) == 6:
  20.                     return col
  21.                 if len(col) == 3:
  22.                     return col[0] + '0' + col[1] + '0' + col[2] + '0'
  23.             elif text == '':
  24.                 return ''
  25.             len(col) == 6
  26.  
  27.         _styles = obj._styles = { }
  28.         for ttype in obj.styles:
  29.             for token in ttype.split():
  30.                 if token in _styles:
  31.                     continue
  32.                 
  33.                 ndef = _styles.get(token.parent, None)
  34.                 styledefs = obj.styles.get(token, '').split()
  35.                 if not ndef or token is None:
  36.                     ndef = [
  37.                         '',
  38.                         0,
  39.                         0,
  40.                         0,
  41.                         '',
  42.                         '',
  43.                         0,
  44.                         0,
  45.                         0]
  46.                 elif 'noinherit' in styledefs and token is not Token:
  47.                     ndef = _styles[Token][:]
  48.                 else:
  49.                     ndef = ndef[:]
  50.                 _styles[token] = ndef
  51.                 for styledef in obj.styles.get(token, '').split():
  52.                     if styledef == 'noinherit':
  53.                         continue
  54.                     if styledef == 'bold':
  55.                         ndef[1] = 1
  56.                         continue
  57.                     if styledef == 'nobold':
  58.                         ndef[1] = 0
  59.                         continue
  60.                     if styledef == 'italic':
  61.                         ndef[2] = 1
  62.                         continue
  63.                     if styledef == 'noitalic':
  64.                         ndef[2] = 0
  65.                         continue
  66.                     if styledef == 'underline':
  67.                         ndef[3] = 1
  68.                         continue
  69.                     if styledef == 'nounderline':
  70.                         ndef[3] = 0
  71.                         continue
  72.                     if styledef[:3] == 'bg:':
  73.                         ndef[4] = colorformat(styledef[3:])
  74.                         continue
  75.                     if styledef[:7] == 'border:':
  76.                         ndef[5] = colorformat(styledef[7:])
  77.                         continue
  78.                     if styledef == 'roman':
  79.                         ndef[6] = 1
  80.                         continue
  81.                     if styledef == 'sans':
  82.                         ndef[7] = 1
  83.                         continue
  84.                     if styledef == 'mono':
  85.                         ndef[8] = 1
  86.                         continue
  87.                     ndef[0] = colorformat(styledef)
  88.                 
  89.             
  90.         
  91.         return obj
  92.  
  93.     
  94.     def style_for_token(cls, token):
  95.         t = cls._styles[token]
  96.         if not t[0]:
  97.             pass
  98.         if not t[4]:
  99.             pass
  100.         if not t[5]:
  101.             pass
  102.         if not bool(t[6]):
  103.             pass
  104.         if not bool(t[7]):
  105.             pass
  106.         if not bool(t[8]):
  107.             pass
  108.         return {
  109.             'color': None,
  110.             'bold': bool(t[1]),
  111.             'italic': bool(t[2]),
  112.             'underline': bool(t[3]),
  113.             'bgcolor': None,
  114.             'border': None,
  115.             'roman': None,
  116.             'sans': None,
  117.             'mono': None }
  118.  
  119.     
  120.     def list_styles(cls):
  121.         return list(cls)
  122.  
  123.     
  124.     def styles_token(cls, ttype):
  125.         return ttype in cls._styles
  126.  
  127.     
  128.     def __iter__(cls):
  129.         for token in cls._styles:
  130.             yield (token, cls.style_for_token(token))
  131.         
  132.  
  133.     
  134.     def __len__(cls):
  135.         return len(cls._styles)
  136.  
  137.  
  138.  
  139. class Style(object):
  140.     __metaclass__ = StyleMeta
  141.     background_color = '#ffffff'
  142.     highlight_color = '#ffffcc'
  143.     styles = { }
  144.  
  145.