##// END OF EJS Templates
Added lost SocExplorerPlot wrapper and win32 libelf binary.
Added lost SocExplorerPlot wrapper and win32 libelf binary.

File last commit:

r0:1aa783210b8e default
r7:1abdb58baffd default
Show More
66 lines | 1.9 KiB | text/x-python | PythonLexer
# -*- coding: utf-8 -*-
""" python-part of PygmentsHighlighter
code/ideas taken from IPython, but IPython doesn't work with PythonQt...
"Melven Zoellner" <melven@topen.org>
# allow to import pygments-stuff from current path
import sys
from __main__ import PYMODULES
# Third-party imports
import pygments
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
# PythonQt imports
from PythonQt import QtGui
class PygmentsHighlighter(object):
""" highlight python code with a QSyntaxHighlighter,
callable class (e.g. function with a state) to """
def __init__(self):
""" constructor """
self._lexer = PythonLexer()
self._formatter = HtmlFormatter()
self._document = QtGui.QTextDocument()
self._format_cache = dict()
def __call__(self, code):
""" makes this class callable, actually do the highlightning """
index = 0
for token, text in self._lexer.get_tokens(code):
length = len(text)
char_format = self._get_format(token)
pygmentsHighlighter._setFormat(index, length, char_format)
index += length
def _get_format(self, token):
""" get the QTextCharFormat for a token """
if token in self._format_cache:
return self._format_cache[token]
# get format from document
code, html = self._formatter._format_lines([(token, u'dummy')]).next()
char_format = QtGui.QTextCursor(self._document).charFormat()
# cache result
self._format_cache[token] = char_format
return char_format
# create class instance, can be called with highlightCode(code)
highlightCode = PygmentsHighlighter()