wxSTC background color

Hi

A complete working application:

#-*- coding: iso-8859-1 -*-

···

#-------------------------------------------------------------------
# STCBackgroundColour.py
# win98, Py 2.3.3. wxPy 2.4.2.4
# 10 January 2004
# Jean-Michel Fauth, Switzerland
#-------------------------------------------------------------------

from wxPython.wx import *
from wxPython.stc import *

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

class MyStc(wxStyledTextCtrl):
    
    def __init__(self, parent, id, pos , size):
        self.parent = parent
        si = self.parent.GetClientSize()
        wxStyledTextCtrl.__init__(self, parent, id, pos, si)

        self.SetMarginLeft(2)
        self.SetViewWhiteSpace(True)
        self.SetTabWidth(4)
        self.SetUseTabs(False)
        self.SetEOLMode(wxSTC_EOL_LF)
        self.SetViewEOL(True)
        self.UsePopUp(False)

        #the most critical part, code the style stuff in that way!
        self.STYLEDEFAULT = 0
        self.STYLEDEFAULTSPEC = "face:courier new,size:10,fore:#000000,back:#FFFFDD"
        # stc background colour ^^^^^^^
        self.STYLEONE = 1
        self.STYLEONESPEC = "face:courier new,size:10,fore:#0000ff,back:#FF0000"
        self.StyleSetSpec(wxSTC_STYLE_DEFAULT, self.STYLEDEFAULTSPEC)
        self.StyleClearAll()
        self.StyleSetSpec(self.STYLEONE, self.STYLEONESPEC)
        
        #add some text
        s = ''
        for i in xrange(51):
            s += 'line ' + str(i) + '\n'
        self.AddText(s)
        
        EVT_RIGHT_DOWN(self, self.OnRightDown)
        EVT_LEFT_DOWN(self, self.OnLeftDown)

    def OnLeftDown(self, event):
        fin = self.GetLength()
        self.StartStyling(0, 0xFF)
        self.SetStyling(fin, self.STYLEONE)
        self.InsertText(0, '') #this forces a refresh!
        event.Skip()

    def OnRightDown(self, event):
        fin = self.GetLength()
        self.StartStyling(0, 0xFF)
        self.SetStyling(fin, self.STYLEDEFAULT)
        self.InsertText(0, '') #this forces a refresh!
        event.Skip()

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

class MyFrame(wxFrame):

    def __init__(self, parent, id):
        s = __file__
        wxFrame.__init__(self, parent, id, s, wxPoint(0,0), wxSize(500, 400))
        thestc = MyStc(self, -1, wxDefaultPosition, wxDefaultSize)

        EVT_CLOSE(self, self.OnCloseWindow)
    
    def OnCloseWindow(self, event):
        self.Destroy()

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

class MyApp(wxApp):

    def OnInit(self):
        frame = MyFrame(None, -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-------------------------------------------------------------------

Jean-Michel Fauth, Switzerland