Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Python syntax coloring for series60

The new Text() control allows rich text which can be
used for syntax coloring
(screenshot)
http://photos22.flickr.com/30187174_8598b800ec_o.jpg
   1  
   2  from appuifw import *
   3  from pyfontify import fontify
   4  import os, e32
   5  
   6  src = ur"""
   7  __version__ = "0.4"
   8  import string, re, keyword  
   9  commentPat = "#.*"  
  10  # Build up a regular expression
  11  pat = "q[^\q\n]*(\\\\[\000-\377][^\q\n]*)*q"
  12  """
  13  
  14  color = { 'keyword': 0x0000ff,
  15            'string': 0xff00ff,
  16            'comment': 0x008000,
  17            'function': 0x008080,
  18            'class': 0x008080 }
  19  
  20  t = Text()
  21  pos = 0
  22  for tag, start, end, sl in fontify(src):
  23      t.color = 0
  24      t.add(src[pos:start])
  25      t.color = color[tag]
  26      t.add(src[start:end])
  27      pos = end
  28  t.color = 0
  29  t.add(src[pos:])
  30  
  31  app.body = t
  32  e32.ao_sleep(10)

You first need to install the pyfontify module from here
http://linux.duke.edu/~mstenner/free-docs/diveintopython-3.9-1/py/pyfontify.py
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS