Hi Neil,
And thank you for the reply.
py2.2, wxPython 2.3.3 pre3, win98se, swiss french kbd
I'm a bit stupid, because
1) the demo contains doc about stc
2) I'm using the wonderful SciTE editor and forgot to visit the Scintilla
site.
Back to my problem. It seems that stc doesn't like StartStyling() and
SetStyling() when a lexer is hooked to the ctrl.
See the following code and its comments.
···
#-------------------------------------------------------------------
from wxPython.wx import *
from wxPython.stc import *
import keyword
#-------------------------------------------------------------------
class MyStc(wxStyledTextCtrl):
def __init__(self, parent, id, pos , size):
wxStyledTextCtrl.__init__(self, parent, id, pos, size)
self.SetMarginType(1, wxSTC_MARGIN_NUMBER)
self.SetMarginWidth(1, 40)
self.SetViewWhiteSpace(true)
self.SetTabWidth(4)
self.SetUseTabs(false)
self.SetLexer(wxSTC_LEX_PYTHON)
self.SetKeyWords(0, ' '.join(keyword.kwlist))
txtone = """some python text
plus some text
class cc:
def sub():
#comment
'a string'
one another text
"""
self.StyleSetSpec(wxSTC_STYLE_DEFAULT, "face:Courier
New,size:10,fore:#000000,back:#FFFFFF")
self.StyleClearAll()
self.StyleSetSpec(wxSTC_STYLE_LINENUMBER, "face:Courier
New,size:10,fore:#FF0000,back:#CFCFCF")
#~ self.StyleSetSpec(wxSTC_P_DEFAULT, "face:Courier
New,size:10,fore:#00FF00")
self.StyleSetSpec(wxSTC_P_COMMENTLINE, "face:Courier
New,size:10,fore:#DD0000")
self.StyleSetSpec(wxSTC_P_NUMBER, "face:Courier New,size:10")
self.StyleSetSpec(wxSTC_P_STRING, "face:Courier
New,size:10,fore:#00AA00")
self.StyleSetSpec(wxSTC_P_CHARACTER, "face:Courier
New,size:10,fore:#7F007F")
self.StyleSetSpec(wxSTC_P_WORD, "face:Courier
New,size:10,fore:#FF7700")
self.StyleSetSpec(wxSTC_P_TRIPLE, "face:Courier
New,size:10,fore:#00FF00")
self.StyleSetSpec(wxSTC_P_TRIPLEDOUBLE, "face:Courier
New,size:10,fore:#00FF00,back:#FFFFE8")
self.StyleSetSpec(wxSTC_P_CLASSNAME, "face:Courier
New,size:10,fore:#0000FF")
self.StyleSetSpec(wxSTC_P_DEFNAME, "face:Courier
New,size:10,fore:#0000FF")
self.StyleSetSpec(wxSTC_P_OPERATOR, "face:Courier New,size:10")
self.StyleSetSpec(wxSTC_P_IDENTIFIER, "face:Courier New,size:10")
self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, "face:Courier
New,size:10,fore:#DD0000")
self.StyleSetSpec(wxSTC_P_STRINGEOL, "face:Courier
New,size:10,fore:#000000,back:#E0C0E0,eolfilled")
self.AddText(txtone)
p = self.GetCurrentPos()
txttwo = 'zzzzz, class c, and, some spaces\n'
self.AddText(txttwo)
#up to this point ok
#but if I introduce the following styling lines, txtone became black
#(wxSTC_STYLE_DEFAULT) and txttwo is correctly drawn in
#red (wxSTC_P_COMMENTLINE)
self.StartStyling(p, 0xff)
self.SetStyling(len(txttwo), wxSTC_P_COMMENTLINE)
#funny: if I run this script and type (add) some text at the end,
txtone
#stays in black, but txttwo will be colorised in python style.
#The freshly typped text receive the python attributes.
#-------------------------------------------------------------------
class MyFrame(wxFrame):
def __init__(self, parent, id):
wxFrame.__init__(self, parent, id, "essai-stc1", wxPoint(300,10),
wxSize(400, 400))
stc = MyStc(self, -1, wxDefaultPosition, wxDefaultSize)
EVT_CLOSE(self, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
#-------------------------------------------------------------------
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL, -1)
frame.Show(true)
self.SetTopWindow(frame)
return true
#-------------------------------------------------------------------
def main():
print 'main is running...'
app = MyApp(0)
app.MainLoop()
#-------------------------------------------------------------------
if __name__ == "__main__" :
main()
#eof-------------------------------------------------------------------
Second point:
By chance, I discovered the following:
If I explicitly set a style for wxSTC_P_DEFAULT (green in the above code),
and I type some text, all the chars having an accent (é, à, ü, ï, ...)
(swiss french kbd) are now displayed with the wxSTC_P_DEFAULT style.
'Normal' (or should I say US chars) are in black (wxSTC_STYLE_DEFAULT)
Regards
Jean-Michel Fauth, Switzerland