Can I use pygments in wxpython?

I wonder whether I can use pygments in wxpython or not.
I hope there is a simple demo.

Wonjun, Choi

From what I can see it should be possible, although it seems like it
focuses on web-output/ displaying.
You can write your own output formatter:
http://pygments.org/docs/formatterdevelopment/

This is probably where I would start from, still not being fully aware
of what you want, i.e. only display styled output or a full-editor
approach ....

Cheers

···

Am 16.09.11 10:27, schrieb Wonjun, Choi:

I wonder whether I can use pygments in wxpython or not.
I hope there is a simple demo.

Wonjun, Choi

--
--------------------------------------------------
Tobias Weber
CEO

The ROG Corporation GmbH
Donaustaufer Str. 200
93059 Regensburg
Tel: +49 941 4610 57 55
Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber
Registergericht: Amtsgericht Regensburg - HRB 8954
UStID DE225905250 - Steuer-Nr.184/59359
--------------------------------------------------

I want to display the highlighted text in stc or text control.
is it possible?

Wonjun, Choi

···

On 9월16일, 오후5시36분, Tobias Weber <tobias.we...@roglink.net> wrote:

Am 16.09.11 10:27, schrieb Wonjun, Choi:> I wonder whether I can use pygments in wxpython or not.
> I hope there is a simple demo.

> Wonjun, Choi

From what I can see it should be possible, although it seems like it
focuses on web-output/ displaying.
You can write your own output formatter:Write your own formatter — Pygments

This is probably where I would start from, still not being fully aware
of what you want, i.e. only display styled output or a full-editor
approach ....

Cheers

--
--------------------------------------------------
Tobias Weber
CEO

The ROG Corporation GmbH
Donaustaufer Str. 200
93059 Regensburg
Tel: +49 941 4610 57 55
Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber
Registergericht: Amtsgericht Regensburg - HRB 8954
UStID DE225905250 - Steuer-Nr.184/59359
--------------------------------------------------

I want to display the highlighted text in stc or text control.
is it possible?

You have to format the output it creates according to the ctrl you want
to load it into.
The simplest thing would be a wx.HtmlWindow I think
See the wx demo for that

···

Am 16.09.11 10:49, schrieb Wonjun, Choi:

Wonjun, Choi

On 9월16일, 오후5시36분, Tobias Weber <tobias.we...@roglink.net> wrote:

Am 16.09.11 10:27, schrieb Wonjun, Choi:> I wonder whether I can use pygments in wxpython or not.

I hope there is a simple demo.
Wonjun, Choi

From what I can see it should be possible, although it seems like it
focuses on web-output/ displaying.
You can write your own output formatter:Write your own formatter — Pygments

This is probably where I would start from, still not being fully aware
of what you want, i.e. only display styled output or a full-editor
approach ....

Cheers

--
--------------------------------------------------
Tobias Weber
CEO

The ROG Corporation GmbH
Donaustaufer Str. 200
93059 Regensburg
Tel: +49 941 4610 57 55
Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber
Registergericht: Amtsgericht Regensburg - HRB 8954
UStID DE225905250 - Steuer-Nr.184/59359
--------------------------------------------------

--
--------------------------------------------------
Tobias Weber
CEO

The ROG Corporation GmbH
Donaustaufer Str. 200
93059 Regensburg
Tel: +49 941 4610 57 55
Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber
Registergericht: Amtsgericht Regensburg - HRB 8954
UStID DE225905250 - Steuer-Nr.184/59359
--------------------------------------------------

is there an option to disable an entry or just the chekbox in a
CheckListCtrl?

I found that you can disable a whole checklist, though it overrides the
background color setting ..

list = CheckListCtrl(self)
sizer = wx.BoxSizer()
sizer.Add(list,0, wx.EXPAND)
sizer.Add(btn,0,wx.EXPAND
self.SetSizer(sizer)

list.InsertColumn(0, "Model")
#....
index = list.InsertStringItem(sys.maxint,u'test')
# here I wanna disable the checkbox ....
#disable the whole ist
list.Disable()

Cheers

···

--
--------------------------------------------------
Tobias Weber
CEO

The ROG Corporation GmbH
Donaustaufer Str. 200
93059 Regensburg
Tel: +49 941 4610 57 55
Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber
Registergericht: Amtsgericht Regensburg - HRB 8954
UStID DE225905250 - Steuer-Nr.184/59359
--------------------------------------------------

Not built-in, but you can probably add the functionality by doing something like adding EnableItem and DisableItem methods which keep track of disabled items and change the item's bg color or some other style to indicate they are disabled, and intercepting the EVT_LEFT_DOWN event and only calling Skip if it is not on an item that is disabled.

···

On 9/16/11 3:21 AM, Tobias Weber wrote:

is there an option to disable an entry or just the chekbox in a
CheckListCtrl?

--
Robin Dunn
Software Craftsman

Thanks- will do :slight_smile:

···

Am 17.09.11 20:46, schrieb Robin Dunn:

On 9/16/11 3:21 AM, Tobias Weber wrote:

is there an option to disable an entry or just the chekbox in a
CheckListCtrl?

Not built-in, but you can probably add the functionality by doing
something like adding EnableItem and DisableItem methods which keep
track of disabled items and change the item's bg color or some other
style to indicate they are disabled, and intercepting the
EVT_LEFT_DOWN event and only calling Skip if it is not on an item that
is disabled.

--
--------------------------------------------------
Tobias Weber
CEO

The ROG Corporation GmbH
Donaustaufer Str. 200
93059 Regensburg
Tel: +49 941 4610 57 55
Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber
Registergericht: Amtsgericht Regensburg - HRB 8954
UStID DE225905250 - Steuer-Nr.184/59359
--------------------------------------------------

sorry, I don’t understand exactly.
wx.HtmlWindow Demo opens only data/test.htm file by using below command

name = os.path.join(self.cwd, opj(‘data/test.htm’))
self.html.LoadPage(name)

I don’t think the demo explains the way of highlighting specific character.

and I cannot understand
==> You have to format the output it creates according to the ctrl you want
to load it into.

Wonjun, Choi

···

2011/9/16 Tobias Weber tobias.weber@roglink.net

Am 16.09.11 10:49, schrieb Wonjun, Choi:

I want to display the highlighted text in stc or text control.

is it possible?

You have to format the output it creates according to the ctrl you want

to load it into.

The simplest thing would be a wx.HtmlWindow I think

See the wx demo for that

Wonjun, Choi

On 9월16일, 오후5시36분, Tobias Weber tobias.we...@roglink.net wrote:

Am 16.09.11 10:27, schrieb Wonjun, Choi:> I wonder whether I can use pygments in wxpython or not.

I hope there is a simple demo.

Wonjun, Choi

From what I can see it should be possible, although it seems like it

focuses on web-output/ displaying.

You can write your own output formatter:http://pygments.org/docs/formatterdevelopment/

This is probably where I would start from, still not being fully aware

of what you want, i.e. only display styled output or a full-editor

approach …

Cheers


Tobias Weber

CEO

The ROG Corporation GmbH

Donaustaufer Str. 200

93059 Regensburg

Tel: +49 941 4610 57 55

Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber

Registergericht: Amtsgericht Regensburg - HRB 8954

UStID DE225905250 - Steuer-Nr.184/59359



Tobias Weber

CEO

The ROG Corporation GmbH

Donaustaufer Str. 200

93059 Regensburg

Tel: +49 941 4610 57 55

Fax: +49 941 4610 57 56

www.roglink.com

GeschŠftsfŸhrer: Tobias Weber

Registergericht: Amtsgericht Regensburg - HRB 8954

UStID DE225905250 - Steuer-Nr.184/59359


To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

sorry, I don't understand exactly.
wx.HtmlWindow Demo opens only data/test.htm file by using below command

name = os.path.join(self.cwd, opj('data/test.htm'))
self.html.LoadPage(name)

I don't think the demo explains the way of highlighting specific character.

Just like any other HTML document, with font tags with color attributes.

and I cannot understand
==> You have to format the output it creates according to the ctrl you want
to load it into.

Pygments is designed to produce output in multiple formats. The statement above simply means that you need to choose an output format that you are able to display in your program using your desired widgets. If none of them works for you then you need to either add your own output format to pygments, or choose or create some other tool.

···

On 9/18/11 6:12 PM, 최원준 wrote:

--
Robin Dunn
Software Craftsman

I want to highlight cython, c, fortran, python language.
and I could highlight python language in Terminal using TerminalFormatter.
but I want to display this in STC. so I refered Editra open source code.
there was _xtext.py example. it imports pygments for lexing language.
I think it puts highlighted tokens into the STC.
and I still wonder how to display the highlighted text into the STC

there was function like this

def StyleText(stc, start, end):
“”"Style the text
@param stc: Styled text control instance
@param start: Start position
@param end: end position

"""

for index, token, txt in lexer.get_tokens_unprocessed(stc.GetTextRange(0, end)):

print index, token, txt

    style = TOKEN_MAP.get(token, STC_XTEXT_DEFAULT)

print “Text=%s, len=%s” % (txt, len(txt))

    stc.StartStyling(index, 0x1f)
    tlen = len(txt)
    if tlen:
        stc.SetStyling(len(txt), style)

my purpose is displaying highlighted text(cython, c, fortran, python language) into the STC(Styledtextctrl)
but I still don’t know how to do this. please help me.

···

2011/9/20 Robin Dunn robin@alldunn.com

On 9/18/11 6:12 PM, 최원준 wrote:

sorry, I don’t understand exactly.

wx.HtmlWindow Demo opens only data/test.htm file by using below command

name = os.path.join(self.cwd, opj(‘data/test.htm’))

self.html.LoadPage(name)

I don’t think the demo explains the way of highlighting specific character.

Just like any other HTML document, with font tags with color attributes.

and I cannot understand

==> You have to format the output it creates according to the ctrl you want

to load it into.

Pygments is designed to produce output in multiple formats. The statement above simply means that you need to choose an output format that you are able to display in your program using your desired widgets. If none of them works for you then you need to either add your own output format to pygments, or choose or create some other tool.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Is this right?

···

#----------------------------------------------------------------------
import keyword

import wx
import wx.stc as stc

class PythonSTC(stc.StyledTextCtrl):

fold_symbols = 2

def __init__(self, parent, ID,
             pos=wx.DefaultPosition, size=wx.DefaultSize,
             style=0):
    stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)

    self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
    self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)

def Styletext(self):
    import sys
    from pygments.lexers import PythonLexer
    from pygments.token import Token
    ftext = open("wxpython_pygments2.py", "r")
    text = ftext.read()
    ftext.close()
    line=1
    lexer = PythonLexer()
    for index, token, txt in lexer.get_tokens_unprocessed(text):
        if token is Token.EndOfLine:
            line += 1
        print line, token, txt
    return token

#----------------------------------------------------------------------

_USE_PANEL = 1

def runTest(frame, nb, log):
if not _USE_PANEL:
ed = p = PythonSTC(nb, -1)
else:
p = wx.Panel(nb, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE)
ed = PythonSTC(p, -1)
s = wx.BoxSizer(wx.HORIZONTAL)
s.Add(ed, 1, wx.EXPAND)
p.SetSizer(s)
p.SetAutoLayout(True)

    import sys
    from pygments.lexers import PythonLexer
    from pygments.token import Token
    ftext = open("wxpython_pygments2.py", "r")
    text = ftext.read()
    ftext.close()
    line=1
    lexer = PythonLexer()
    for index, token, txt in lexer.get_tokens_unprocessed(text):
        if token is Token.EndOfLine:
            line += 1
       
            ed.SetText(token)
            ed.EmptyUndoBuffer()
            ed.Colourise(0, -1)
# line numbers in the margin
ed.SetMarginType(1, stc.STC_MARGIN_NUMBER)
ed.SetMarginWidth(1, 25)

return p

if name == ‘main’:
import sys,os
import run
run.main([‘’, os.path.basename(sys.argv[0])] + sys.argv[1:])

#----------------------------------------------------------------------

2011년 9월 20일 오후 4:35, 최원준 wonjunchoi001@gmail.com님의 말:

I want to highlight cython, c, fortran, python language.
and I could highlight python language in Terminal using TerminalFormatter.
but I want to display this in STC. so I refered Editra open source code.
there was _xtext.py example. it imports pygments for lexing language.

I think it puts highlighted tokens into the STC.
and I still wonder how to display the highlighted text into the STC

there was function like this

def StyleText(stc, start, end):
“”"Style the text

@param stc: Styled text control instance
@param start: Start position
@param end: end position

"""

for index, token, txt in lexer.get_tokens_unprocessed(stc.GetTextRange(0, end)):

print index, token, txt

    style = TOKEN_MAP.get(token, STC_XTEXT_DEFAULT)

print “Text=%s, len=%s” % (txt, len(txt))

    stc.StartStyling(index, 0x1f)
    tlen = len(txt)


    if tlen:
        stc.SetStyling(len(txt), style)

my purpose is displaying highlighted text(cython, c, fortran, python language) into the STC(Styledtextctrl)
but I still don’t know how to do this. please help me.

2011/9/20 Robin Dunn robin@alldunn.com

On 9/18/11 6:12 PM, 최원준 wrote:

sorry, I don’t understand exactly.

wx.HtmlWindow Demo opens only data/test.htm file by using below command

name = os.path.join(self.cwd, opj(‘data/test.htm’))

self.html.LoadPage(name)

I don’t think the demo explains the way of highlighting specific character.

Just like any other HTML document, with font tags with color attributes.

and I cannot understand

==> You have to format the output it creates according to the ctrl you want

to load it into.

Pygments is designed to produce output in multiple formats. The statement above simply means that you need to choose an output format that you are able to display in your program using your desired widgets. If none of them works for you then you need to either add your own output format to pygments, or choose or create some other tool.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en