×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148

    Syntax coloring in editor

    The new Text() control support many color, font, highlight and style.
    Therefore, we are now capable of making a more decent editor.
    Here's an example how python source code can be syntax-colored.

    You need first to install the PyFontify module from here
    http://linux.duke.edu/~mstenner/free...y/pyfontify.py
    Code:
    from appuifw import *
    from pyfontify import fontify
    import os, e32
    
    src = ur"""
    __version__ = "0.4"
    import string, re, keyword  
    commentPat = "#.*"  
    # Build up a regular expression
    pat = "q[^\q\n]*(\\\\[\000-\377][^\q\n]*)*q"
    """
    
    color = { 'keyword': 0x0000ff,
              'string': 0xff00ff,
              'comment': 0x008000,
              'function': 0x008080,
              'class': 0x008080 }
    
    t = Text()
    pos = 0
    for tag, start, end, sl in fontify(src):
        t.color = 0
        t.add(src[pos:start])
        t.color = color[tag]
        t.add(src[start:end])
        pos = end
    t.color = 0
    t.add(src[pos:])
    
    app.body = t
    
    e32.ao_sleep(10)
    See screenshot here.
    http://photos22.flickr.com/30187174_8598b800ec_o.jpg
    Last edited by korakotc; 2005-08-01 at 06:05.

  2. #2
    Regular Contributor
    Join Date
    Jul 2004
    Posts
    76
    Very nice!

  3. #3
    Regular Contributor
    Join Date
    Dec 2004
    Location
    Czech Republic
    Posts
    50
    nice. maybe you can remember I was developing a text editor for python programming purposes, so i couldnt have forgotten function like syntax highlighting ... but i hadnt found out any way how to colour the part of to text without deleting other part, so i could just create a very slow algorhitm ... after an afternoon of debugging it was working, but it is very slow, processing 1kB of text takes about 1 minute, so it isn't very useful ...

    if this algorhitm is better, I'll try to implement it, when I find some free time...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×