]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxStyledTextCtrl_1.py
don't process VK_OEM_XXX key presses
[wxWidgets.git] / wxPython / demo / wxStyledTextCtrl_1.py
CommitLineData
f6bcfd97
BP
1
2from wxPython.wx import *
3from wxPython.stc import *
4
5#----------------------------------------------------------------------
6
7demoText = """\
8
9This editor is provided by a class named wxStyledTextCtrl. As
10the name suggests, you can define styles that can be applied to
11sections of text. This will typically be used for things like
12syntax highlighting code editors, but I'm sure that there are other
13applications as well. A style is a combination of font, point size,
14forground and background colours. The editor can handle
15proportional fonts just as easily as monospaced fonts, and various
16styles can use different sized fonts.
17
18There are a few canned language lexers and colourizers included,
19(see the next demo) or you can handle the colourization yourself.
20If you do you can simply register an event handler and the editor
21will let you know when the visible portion of the text needs
22styling.
23
24wxStyledTextEditor also supports setting markers in the margin...
25
26
27
28
29...and indicators within the text. You can use these for whatever
30you want in your application. Cut, Copy, Paste, Drag and Drop of
31text works, as well as virtually unlimited Undo and Redo
32capabilities, (right click to try it out.)
33
34"""
35
36if wxPlatform == '__WXMSW__':
37 face1 = 'Arial'
38 face2 = 'Times New Roman'
39 face3 = 'Courier New'
40 pb = 6
41else:
42 face1 = 'Helvetica'
43 face2 = 'Times'
44 face3 = 'Courier'
45 pb = 10
46
47
48#----------------------------------------------------------------------
49# This shows how to catch the Modified event from the wxStyledTextCtrl
50
51class MySTC(wxStyledTextCtrl):
52 def __init__(self, parent, ID, log):
53 wxStyledTextCtrl.__init__(self, parent, ID)
54 self.log = log
55
56 EVT_STC_MODIFIED(self, ID, self.OnModified)
57
58
59 def OnModified(self, evt):
60 self.log.write("""OnModified
61 Mod type: %s
62 At position: %d
63 Lines added: %d
64 Text Length: %d
65 Text: %s\n""" % ( self.transModType(evt.GetModificationType()),
66 evt.GetPosition(),
67 evt.GetLinesAdded(),
68 evt.GetLength(),
69 evt.GetText() ))
70
71 def transModType(self, modType):
72 st = ""
73 table = [(wxSTC_MOD_INSERTTEXT, "InsertText"),
74 (wxSTC_MOD_DELETETEXT, "DeleteText"),
75 (wxSTC_MOD_CHANGESTYLE, "ChangeStyle"),
76 (wxSTC_MOD_CHANGEFOLD, "ChangeFold"),
77 (wxSTC_PERFORMED_USER, "UserFlag"),
78 (wxSTC_PERFORMED_UNDO, "Undo"),
79 (wxSTC_PERFORMED_REDO, "Redo"),
80 (wxSTC_LASTSTEPINUNDOREDO, "Last-Undo/Redo"),
81 (wxSTC_MOD_CHANGEMARKER, "ChangeMarker"),
82 (wxSTC_MOD_BEFOREINSERT, "B4-Insert"),
83 (wxSTC_MOD_BEFOREDELETE, "B4-Delete")
84 ]
85
86 for flag,text in table:
87 if flag & modType:
88 st = st + text + " "
89
90 if not st:
91 st = 'UNKNOWN'
92
93 return st
94
95
96
97#----------------------------------------------------------------------
98
cf273c67
RD
99_USE_PANEL = 1
100
f6bcfd97 101def runTest(frame, nb, log):
cf273c67
RD
102 if not _USE_PANEL:
103 ed = p = MySTC(nb, -1, log)
104
105 else:
106 p = wxPanel(nb, -1)
107 ed = MySTC(p, -1, log)
108 s = wxBoxSizer(wxHORIZONTAL)
109 s.Add(ed, 1, wxEXPAND)
110 p.SetSizer(s)
111 p.SetAutoLayout(true)
f6bcfd97
BP
112
113 ed.SetText(demoText)
114 ed.EmptyUndoBuffer()
115
116 # make some styles
117 ed.StyleSetSpec(wxSTC_STYLE_DEFAULT, "size:%d,face:%s" % (pb+2, face3))
118 ed.StyleSetSpec(1, "size:%d,bold,face:%s,fore:#0000FF" % (pb+3, face1))
119 ed.StyleSetSpec(2, "face:%s,italic,fore:#FF0000,size:%d" % (face2, pb+2))
120 ed.StyleSetSpec(3, "face:%s,bold,size:%d" % (face2, pb+3))
121 ed.StyleSetSpec(4, "face:%s,size:%d" % (face1, pb))
122
123
124 # now set some text to those styles... Normally this would be
125 # done in an event handler that happens when text needs displayed.
126 ed.StartStyling(98, 0xff)
c368d904 127 ed.SetStyling(6, 1) # set style for 6 characters using style 1
f6bcfd97
BP
128
129 ed.StartStyling(190, 0xff)
c368d904 130 ed.SetStyling(20, 2)
f6bcfd97
BP
131
132 ed.StartStyling(310, 0xff)
c368d904
RD
133 ed.SetStyling(4, 3)
134 ed.SetStyling(2, 0)
135 ed.SetStyling(10, 4)
f6bcfd97
BP
136
137
138 # line numbers in the margin
139 ed.SetMarginType(0, wxSTC_MARGIN_NUMBER)
140 ed.SetMarginWidth(0, 22)
141 ed.StyleSetSpec(wxSTC_STYLE_LINENUMBER, "size:%d,face:%s" % (pb, face1))
142
143 # setup some markers
144 ed.SetMarginType(1, wxSTC_MARGIN_SYMBOL)
145 ed.MarkerDefine(0, wxSTC_MARK_ROUNDRECT, "#CCFF00", "RED")
146 ed.MarkerDefine(1, wxSTC_MARK_CIRCLE, "FOREST GREEN", "SIENNA")
147 ed.MarkerDefine(2, wxSTC_MARK_SHORTARROW, "blue", "blue")
148 ed.MarkerDefine(3, wxSTC_MARK_ARROW, "#00FF00", "#00FF00")
149
150 # put some markers on some lines
151 ed.MarkerAdd(17, 0)
152 ed.MarkerAdd(18, 1)
153 ed.MarkerAdd(19, 2)
154 ed.MarkerAdd(20, 3)
155 ed.MarkerAdd(20, 0)
156
157
158 # and finally, an indicator or two
159 ed.IndicatorSetStyle(0, wxSTC_INDIC_SQUIGGLE)
c368d904 160 ed.IndicatorSetForeground(0, wxRED)
f6bcfd97 161 ed.IndicatorSetStyle(1, wxSTC_INDIC_DIAGONAL)
c368d904 162 ed.IndicatorSetForeground(1, wxBLUE)
f6bcfd97 163 ed.IndicatorSetStyle(2, wxSTC_INDIC_STRIKE)
c368d904 164 ed.IndicatorSetForeground(2, wxRED)
f6bcfd97
BP
165
166 ed.StartStyling(836, wxSTC_INDICS_MASK)
c368d904
RD
167 ed.SetStyling(10, wxSTC_INDIC0_MASK)
168 ed.SetStyling(10, wxSTC_INDIC1_MASK)
169 ed.SetStyling(10, wxSTC_INDIC2_MASK | wxSTC_INDIC1_MASK)
f6bcfd97
BP
170
171
cf273c67 172 return p
f6bcfd97
BP
173
174
175
176#----------------------------------------------------------------------
177
178
179overview = """\
180<html><body>
181Once again, no docs yet. <b>Sorry.</b> But <a href="data/stc.h">this</a>
182and <a href="http://www.scintilla.org/ScintillaDoc.html">this</a> should
183be helpful.
184</body><html>
185"""
186
187
188
189if __name__ == '__main__':
190 import sys
191 app = wxPySimpleApp()
192 frame = wxFrame(None, -1, "Tester...", size=(640, 480))
193 win = runTest(frame, frame, sys.stdout)
194 frame.Show(true)
195 app.MainLoop()
196
197