当前位置: 首页>>代码示例>>Python>>正文


Python Formatter.__init__方法代码示例

本文整理汇总了Python中pygments.formatter.Formatter.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.__init__方法的具体用法?Python Formatter.__init__怎么用?Python Formatter.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.formatter.Formatter的用法示例。


在下文中一共展示了Formatter.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
    def __init__(self, **options):
        Formatter.__init__(self, **options)

        # create a dict of (start, end) tuples that wrap the
        # value of a token so that we can use it in the format
        # method later
        self.styles = {}

        # we iterate over the `_styles` attribute of a style item
        # that contains the parsed style values.
        for token, style in self.style:
            start = end = ''
            if style['color']:
                sty = str(style['color'])
                if sty == "000000": start, end = '<cstyle:py_decodes>','<cstyle:>'
                if sty == "000001": start, end = '<cstyle:py_comment>','<cstyle:>'
                elif sty == "000002": start, end = '<cstyle:py_keyword>','<cstyle:>'
                elif sty == "000003": start, end = '<cstyle:py_name>','<cstyle:>'
                elif sty == "000004": start, end = '<cstyle:py_name_func>','<cstyle:>'
                elif sty == "000005": start, end = '<cstyle:py_name_class>','<cstyle:>'
                
                elif sty == "100001": start, end = '<cstyle:py_number>','<cstyle:>'   
                elif sty == "100002": start, end = '<cstyle:py_builtin>','<cstyle:>'   
                elif sty == "100003": start, end = '<cstyle:py_builtin>','<cstyle:>'  
                elif sty == "100004": start, end = '<cstyle:py_operator>','<cstyle:>'  
                
                elif sty == "999999": start, end = '<cstyle:py_string>','<cstyle:>'
                #else : start, end = '<cstyle:py_default>','<cstyle:>'
                
            self.styles[token] = (start, end)
开发者ID:cesandoval,项目名称:decoding_designscript,代码行数:32,代码来源:dc_pygments_extensions.py

示例2: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
 def __init__(self, **options):
     Formatter.__init__(self, **options)
     self.styles = {}
     for token, style in self.style:
         self.styles[token] = {}
         if style["color"]:
             self.styles[token]["color"] = Colors.rgb(*hex2rgb(style["color"]))
开发者ID:skykooler,项目名称:Lightningbeam,代码行数:9,代码来源:codeeditor.py

示例3: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        #XXX distinct colors must fit, actually
        if curses.can_change_color() and len(self.style) <= curses.COLORS:

            # cache of registered RGB colors
            colors = []
            def init_color(rgb):
                r, g, b = int(rgb[:2], 16), int(rgb[2:4], 16), int(rgb[4:], 16)
                curses.init_color(len(colors) + 1,
                    r * 1000 / 255, g * 1000 / 255, b * 1000 / 255)
                colors.append(rgb)
            pairs = []
            self.pairs = {}
            self.bolds = set()
            for token, style in self.style:
                #XXX bg
                fg = style['color'] or 'ffffff'
                bg = style['bgcolor']
                if fg not in colors:
                    init_color(fg)

                if style['bold']:
                    self.bolds.add(token)

                pair = (fg, bg)
                sys.stderr.write("%r gets %r\n" % (token, pair))
                if pair not in pairs:
                    curses.init_pair(len(pairs) + 1,
                        colors.index(fg)+1, -1)
                    pairs.append(pair)

                self.pairs[token] = pairs.index(pair)
开发者ID:lehmannro,项目名称:faketerm,代码行数:35,代码来源:faketerm.py

示例4: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
  def __init__(self, **options):
        Formatter.__init__(self, **options)
        
        if "fonts" in options:
          self.fonts = ",".join(options["fonts"])
        else:
		  self.fonts = ",".join(['consolas', 'lucida console', 'courier', 'monospace'])

        # create a dict of (start, end) tuples that wrap the
        # value of a token so that we can use it in the format
        # method later
        self.styles = {}

        # we iterate over the `_styles` attribute of a style item
        # that contains the parsed style values.
        for token, style in self.style:
            start = end = ''
            # a style item is a tuple in the following form:
            # colors are readily specified in hex: 'RRGGBB'
            if style['color']:
                start += '<span style="color:#%s">' % style['color']
                end = '</span>' + end
            if style['bold']:
                start += '<b>'
                end = '</b>' + end
            if style['italic']:
                start += '<i>'
                end = '</i>' + end
            if style['underline']:
                start += '<u>'
                end = '</u>' + end
            self.styles[token] = (start, end)
开发者ID:Khaos,项目名称:pygments.wlwriter,代码行数:34,代码来源:devhawk_formatter.py

示例5: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
 def __init__(self, **options):
     """Extra arguments:
     
     usebold: if false, bold will be ignored and always off
             default: True
     usebg: if false, background color will always be 'default'
             default: True
     defaultfg: the default color to use for the foreground, used
         if the style does not specify.
         This is in curses format, e.g. curses.COLOR_BLACK.
         Use -1 for the terminal default, -2 for the pygments style default.
         default: -1 (terminal default)
     defaultbg: the default color to use for the background, used in blank
         space, and behind normal text when usebg = False or when
         the style does not specify a foreground color.
         This is in curses format, e.g. curses.COLOR_BLACK.
         Use -1 for the terminal default, -2 for the pygments style default.
         default: -1 (terminal default)
     colors: number of colors to use (-1 for auto, 16, 88, or 256)
             default: -1 (automatic)"""
     Formatter.__init__(self, **options)
     self.usebold = options.get('usebold',True)
     self.usebg = options.get('usebg', True)
     self.defaultbg = options.get('defaultbg', -1)
     self.defaultfg = options.get('defaultfg', -1)
     self.colors = options.get('colors', -1)
     self.style_attrs = {}
     self._tokentocolorpair = {}
     self._setup = False
开发者ID:wackywendell,项目名称:ipycurses,代码行数:31,代码来源:cursespygments.py

示例6: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
 def __init__(self, **options):
     """Initialize the style types."""
     Formatter.__init__(self, **options)
     self.styles = {}
     for token, style in self.style:
         start = ''
         end = ''
         newline_end = '\n'
         newline_start = ''
         if style['color']:
             start += newline_start + '<STATviewcolor=#%s>' % style['color'] + '\n'
             newline_start = ''
         if style['bold']:
             start += newline_start + '<STATviewb>\n'
             newline_start = ''
         if style['italic']:
             start += newline_start + '<STATviewi>\n'
             newline_start = ''
         if style['underline']:
             start += newline_start + '<STATviewu>\n'
             newline_start = ''
         if style['underline']:
             end = newline_end + end + '</STATviewu>\n'
             newline_end = ''
         if style['italic']:
             end = newline_end + end + '</STATviewi>\n'
             newline_end = ''
         if style['bold']:
             end = newline_end + end + '</STATviewb>\n'
             newline_end = ''
         if style['color']:
             end = newline_end + end + '</STATviewcolor>\n'
             newline_end = ''
         self.styles[token] = (start, end)
开发者ID:SteveXiSong,项目名称:STAT,代码行数:36,代码来源:STAThelper.py

示例7: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.token_map = {}
        self.styles = []

        for token, style in self.style:
            #debug("formatter: {} {}".format(token, style))

            try:
                s = {}
                if style['color']:
                    c, b = extract_color(style['color'])
                    #debug("fg color: c='{}' b='{}'".format(c, b))
                    s['fg_color'] = c
                    s['fg_bright'] = b
                if style['bold']:
                    s['bold'] = bool(style['bold'])
                if style['underline']:
                    s['underline'] = bool(style['underline'])
                if style['bgcolor']:
                    c, b = extract_color(style['bgcolor'])
                    debug("bg color: c='{}' b='{}'".format(c, b))
                    s['bg_color'] = c
                    s['bg_bright'] = b

                i = self.add_style(s) if len(s) != 0 else -1
                self.token_map[token] = i

                #debug("token_map: {}".format(self.token_map))

            except Exception as ex:
                ## use default formatting
                debug("error: style formatted wrong for {}: {}. Skipping...".format(token, ex))
                self.token_map[token] = -1
开发者ID:ajbonkoski,项目名称:pye,代码行数:36,代码来源:syntax_highlighter.py

示例8: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
  def __init__(self, **options):
    Formatter.__init__(self, **options)

    self.styles = {}

    for token, style in self.style:
      start_tag = close_tag = ''

      if style['color']:
        start_tag += '<span fgcolor="#%s">' % style['color']
        close_tag = '</span>' + close_tag

      if style['bold']:
        start_tag += '<b>'
        close_tag = '</b>' + close_tag

      if style['italic']:
        start_tag += '<i>'
        close_tag = '</i>' + close_tag

      if style['underline']:
        start_tag += '<u>'
        close_tag = '</u>' + close_tag

      self.styles[token] = (start_tag, close_tag)
开发者ID:behdad,项目名称:slippy,代码行数:27,代码来源:pangopygments.py

示例9: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
 def __init__(self, **options):
     Formatter.__init__(self, **options)
     self.lineseparator = options.get("lineseparator", "\n")
     self.tabwidth = get_int_opt(options, "tabwidth", 4)
     self.escapetable = _escape_html_table
     self.escapetable[ord("\t")] = "&nbsp;" * self.tabwidth
     self.noclasses = get_bool_opt(options, "noclasses", False)
     self.classprefix = options.get("classprefix", "")
     self.cssclass = options.get("cssclass", "highlight")
     self.stylebg = get_bool_opt(options, "stylebg", True)
     self.stylebgalternating = get_bool_opt(options, "stylebgalternating", True)
     self.fontfamily = options.get("fontfamily", "Courier")
     self.fontsize = options.get("fontsize", "1.2em")
     self._create_stylesheet()
     self.linecolwidth = options.get("linecolwidth", 3)
     self.tablewidth = options.get("tablewidth", "100%")
     self.showtitles = get_bool_opt(options, "showtitles", False)
     self.titles = []
     self.additionalstyles = options.get(
         "additionalstyles",
         (
             AspectStyle(name=CSSCLASS_LINENO, styles=dict(bgcolor="eeeeee", borderright="eeaaaa")),
             AspectStyle(name="bgcoloreven", styles=dict(bgcolor="fafafa")),
             AspectStyle(name="bgcoloreven2", styles=dict(bgcolor="fdfdfd")),
             AspectStyle(name="bgcolorodd", styles=dict(bgcolor="f5f5f5")),
             AspectStyle(name="bgcolorodd2", styles=dict(bgcolor="f8f8f8")),
             AspectStyle(name=CSSCLASS_TD_TITLE, styles=dict(bgcolor="eeaaaa", paddingleft="15px")),
         ),
     )
     self._create_additional_styles()
开发者ID:gixxi,项目名称:comparareetpendere,代码行数:32,代码来源:__init__.py

示例10: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
    def __init__(self):
        Formatter.__init__(self)
        self.data = []

        # Create a dictionary of text styles, indexed
        # by pygments token names, containing QTextCharFormat
        # instances according to pygments' description
        # of each style

        self.styles = {}
        for token, style in self.style:
            qtf = QtGui.QTextCharFormat()

            if style['color']:
                qtf.setForeground(hex2QColor(style['color']))
            if style['bgcolor']:
                qtf.setBackground(hex2QColor(style['bgcolor']))
            if style['bold']:
                qtf.setFontWeight(QtGui.QFont.Bold)
            if style['italic']:
                qtf.setFontItalic(True)
            if style['underline']:
                qtf.setFontUnderline(True)
            self.styles[str(token)] = qtf
        # missing token
        self.styles['Token.Literal.String.Name'] = self.styles['Token.Literal.String']
开发者ID:LionelR,项目名称:pgleon,代码行数:28,代码来源:editor.py

示例11: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
 def __init__(self, **options):
     Formatter.__init__(self, **options)
     self.darkbg = get_choice_opt(options, 'bg',
                                  ['light', 'dark'], 'light') == 'dark'
     self.colorscheme = options.get('colorscheme', None) or COMMAND_COLORS
     self.linenos = options.get('linenos', False)
     self._lineno = 0
开发者ID:joaobarbosa,项目名称:orator,代码行数:9,代码来源:command_formatter.py

示例12: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = options.get('cssclass', 'highlight')
        self.cssstyles = options.get('cssstyles', '')
        self.prestyles = options.get('prestyles', '')
        self.cssfile = options.get('cssfile', '')
        linenos = options.get('linenos', False)
        if linenos == 'inline':
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.lineseparator = options.get('lineseparator', '\n')
        self.lineanchors = options.get('lineanchors', '')
        self.hl_lines = set()
        for lineno in get_list_opt(options, 'hl_lines', []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._class_cache = {}
        self._create_stylesheet()
开发者ID:B-Rich,项目名称:crashkit,代码行数:34,代码来源:html.py

示例13: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
    def __init__(self, **options):
        Formatter.__init__(self, **options)

        # create a dict of (start, end) tuples that wrap the
        # value of a token so that we can use it in the format
        # method later
        self.styles = {}

        # we iterate over the `_styles` attribute of a style item
        # that contains the parsed style values.
        for token, style in self.style:
            start = end = ''
            # a style item is a tuple in the following form:
            # colors are readily specified in hex: 'RRGGBB'
            if style['color']:
                start += '<font color="#%s">' % style['color']
                end = '</font>' + end
            if style['bold']:
                start += '<b>'
                end = '</b>' + end
            if style['italic']:
                start += '<i>'
                end = '</i>' + end
            if style['underline']:
                start += '<u>'
                end = '</u>' + end
            self.styles[token] = (start, end)
开发者ID:lsfusion,项目名称:samples,代码行数:29,代码来源:main.py

示例14: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self._code = get_bool_opt(options, 'codetag', False)
        self._mono = get_bool_opt(options, 'monofont', False)

        self.styles = {}
        self._make_styles()
开发者ID:10sr,项目名称:hue,代码行数:9,代码来源:bbcode.py

示例15: __init__

# 需要导入模块: from pygments.formatter import Formatter [as 别名]
# 或者: from pygments.formatter.Formatter import __init__ [as 别名]
 def __init__(self, flowdocument=True, store_code_blocks=False, **options):
     Formatter.__init__(self, **options)
     self.flowdocument = flowdocument
     self.store_code_blocks = store_code_blocks
     
     self.linenos = 0
     if flowdocument:
         self.lineseparator = '\n'
     else:
         self.lineseparator = '<LineBreak />'
     self.styles = {}
     
     for token, style in self.style:
         format_string = ''
         # a style item is a tuple in the following form:
         # colors are readily specified in hex: 'RRGGBB'
         if style['color']:
             format_string = ' Foreground="#%s"' % style['color']
         if style['bold']:
             format_string += ' FontWeight="Bold"'
         if style['italic']:
             format_string += ' FontStyle="Italic"'
         if style['underline']:
             # not used ?
             pass
         self.styles[token] = format_string
开发者ID:jschementi,项目名称:pycon2010,代码行数:28,代码来源:xamlformatter.py


注:本文中的pygments.formatter.Formatter.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。