16 Aug 2011 13:11
palette container
Alain Leufroy <alain.leufroy <at> logilab.fr>
2011-08-16 11:11:07 GMT
2011-08-16 11:11:07 GMT
Hi,
I'd like to use pygments to colorize source file data displayed in a Text
widget.
To do so, I set a palette with names from pygments tokens. Here is a simple
example::
--- 8< ---- Begin (test.py) ---- 8< ----
#! /usr/bin/env python
import urwid
from pygments import lex, lexers, token
class Foo(object):
'''Just to get a class'''
def __str__(self):
'''return this python source code as a string'''
fid = open(__file__)
python_code = fid.read()
fid.close()
return python_code
def highlight_code(text):
"""return formated text using pygments"""
return list(lex(text, lexers.PythonLexer()))
PALETTE = [(token.Token.Text, 'default', 'default'),
(token.Token.Name, 'dark blue', 'default'),
(Continue reading)
RSS Feed