]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/RichTextCtrl.py
added missing button state
[wxWidgets.git] / wxPython / demo / RichTextCtrl.py
CommitLineData
30fc5e8f
RD
1
2import wx
3import wx.richtext as rt
4import images
5
6#----------------------------------------------------------------------
7
8class RichTextFrame(wx.Frame):
9 def __init__(self, *args, **kw):
10 wx.Frame.__init__(self, *args, **kw)
11
12 self.MakeMenuBar()
13 self.MakeToolBar()
14 self.CreateStatusBar()
15 self.SetStatusText("Welcome to wx.richtext.RichTextCtrl!")
16
17 self.rtc = rt.RichTextCtrl(self, style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER);
18 wx.CallAfter(self.rtc.SetFocus)
19
20
21 self.rtc.BeginSuppressUndo()
22
23 self.rtc.BeginParagraphSpacing(0, 20)
24
25 self.rtc.BeginAlignment(rt.TEXT_ALIGNMENT_CENTRE)
26 self.rtc.BeginBold()
27
28 self.rtc.BeginFontSize(14)
29 self.rtc.WriteText("Welcome to wxRichTextCtrl, a wxWidgets control for editing and presenting styled text and images")
30 self.rtc.EndFontSize()
31 self.rtc.Newline()
32
33 self.rtc.BeginItalic()
34 self.rtc.WriteText("by Julian Smart")
35 self.rtc.EndItalic()
36
37 self.rtc.EndBold()
38
39 self.rtc.Newline()
40 self.rtc.WriteImage(images.get_rt_zebraImage())
41
42 self.rtc.EndAlignment()
43
44 self.rtc.Newline()
45 self.rtc.Newline()
46
47 self.rtc.WriteText("What can you do with this thing? ")
48 self.rtc.WriteImage(images.get_rt_smileyImage())
49 self.rtc.WriteText(" Well, you can change text ")
50
51 self.rtc.BeginTextColour((255, 0, 0))
52 self.rtc.WriteText("colour, like this red bit.")
53 self.rtc.EndTextColour()
54
55 self.rtc.BeginTextColour((0, 0, 255))
56 self.rtc.WriteText(" And this blue bit.")
57 self.rtc.EndTextColour()
58
59 self.rtc.WriteText(" Naturally you can make things ")
60 self.rtc.BeginBold()
61 self.rtc.WriteText("bold ")
62 self.rtc.EndBold()
63 self.rtc.BeginItalic()
64 self.rtc.WriteText("or italic ")
65 self.rtc.EndItalic()
66 self.rtc.BeginUnderline()
67 self.rtc.WriteText("or underlined.")
68 self.rtc.EndUnderline()
69
70 self.rtc.BeginFontSize(14)
71 self.rtc.WriteText(" Different font sizes on the same line is allowed, too.")
72 self.rtc.EndFontSize()
73
74 self.rtc.WriteText(" Next we'll show an indented paragraph.")
75
76 self.rtc.BeginLeftIndent(60)
77 self.rtc.Newline()
78
79 self.rtc.WriteText("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
80 self.rtc.EndLeftIndent()
81
82 self.rtc.Newline()
83
84 self.rtc.WriteText("Next, we'll show a first-line indent, achieved using BeginLeftIndent(100, -40).")
85
86 self.rtc.BeginLeftIndent(100, -40)
87 self.rtc.Newline()
88
89 self.rtc.WriteText("It was in January, the most down-trodden month of an Edinburgh winteself.rtc. An attractive woman came into the cafe, which is nothing remarkable.")
90 self.rtc.EndLeftIndent()
91
92 self.rtc.Newline()
93
94 self.rtc.WriteText("Numbered bullets are possible, again using subindents:")
95
96 self.rtc.BeginNumberedBullet(1, 100, 60)
97 self.rtc.Newline()
98
99 self.rtc.WriteText("This is my first item. Note that wxRichTextCtrl doesn't automatically do numbering, but this will be added later.")
100 self.rtc.EndNumberedBullet()
101
102 self.rtc.BeginNumberedBullet(2, 100, 60)
103 self.rtc.Newline()
104
105 self.rtc.WriteText("This is my second item.")
106 self.rtc.EndNumberedBullet()
107
108 self.rtc.Newline()
109
110 self.rtc.WriteText("The following paragraph is right-indented:")
111
112 self.rtc.BeginRightIndent(200)
113 self.rtc.Newline()
114
115 self.rtc.WriteText("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
116 self.rtc.EndRightIndent()
117
118 self.rtc.Newline()
119
120 self.rtc.WriteText("The following paragraph is right-aligned with 1.5 line spacing:")
121
122 self.rtc.BeginAlignment(rt.TEXT_ALIGNMENT_RIGHT)
123 self.rtc.BeginLineSpacing(rt.TEXT_ATTR_LINE_SPACING_HALF)
124 self.rtc.Newline()
125
126 self.rtc.WriteText("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
127 self.rtc.EndLineSpacing()
128 self.rtc.EndAlignment()
129
130 self.rtc.Newline()
131 self.rtc.WriteText("Other notable features of wxRichTextCtrl include:")
132
133 self.rtc.BeginSymbolBullet('*', 100, 60)
134 self.rtc.Newline()
135 self.rtc.WriteText("Compatibility with wxTextCtrl API")
136 self.rtc.EndSymbolBullet()
137
138 self.rtc.BeginSymbolBullet('*', 100, 60)
139 self.rtc.Newline()
140 self.rtc.WriteText("Easy stack-based BeginXXX()...EndXXX() style setting in addition to SetStyle()")
141 self.rtc.EndSymbolBullet()
142
143 self.rtc.BeginSymbolBullet('*', 100, 60)
144 self.rtc.Newline()
145 self.rtc.WriteText("XML loading and saving")
146 self.rtc.EndSymbolBullet()
147
148 self.rtc.BeginSymbolBullet('*', 100, 60)
149 self.rtc.Newline()
150 self.rtc.WriteText("Undo/Redo, with batching option and Undo suppressing")
151 self.rtc.EndSymbolBullet()
152
153 self.rtc.BeginSymbolBullet('*', 100, 60)
154 self.rtc.Newline()
155 self.rtc.WriteText("Clipboard copy and paste")
156 self.rtc.EndSymbolBullet()
157
158 self.rtc.BeginSymbolBullet('*', 100, 60)
159 self.rtc.Newline()
160 self.rtc.WriteText("wxRichTextStyleSheet with named character and paragraph styles, and control for applying named styles")
161 self.rtc.EndSymbolBullet()
162
163 self.rtc.BeginSymbolBullet('*', 100, 60)
164 self.rtc.Newline()
165 self.rtc.WriteText("A design that can easily be extended to other content types, ultimately with text boxes, tables, controls, and so on")
166 self.rtc.EndSymbolBullet()
167
168 self.rtc.Newline()
169
170 self.rtc.WriteText("Note: this sample content was generated programmatically from within the MyFrame constructor in the demo. The images were loaded from inline XPMs. Enjoy wxRichTextCtrl!")
171
172 self.rtc.EndParagraphSpacing()
173
174 self.rtc.EndSuppressUndo()
175
176
177 def OnFileOpen(self, evt):
178 # TODO: Use RichTextBuffer.GetExtWildcard to get the wildcard string
179 dlg = wx.FileDialog(self, "Choose a filename",
180 wildcard="All files (*.*)|*.*",
181 style=wx.OPEN)
182 if dlg.ShowModal() == wx.ID_OK:
183 path = dlg.GetPath()
184 if path:
185 # TODO: use the filter index to determine what file type to use
186 self.rtc.LoadFile(path, rt.RICHTEXT_TYPE_TEXT)
187 dlg.Destroy()
188
189
190 def OnFileSave(self, evt):
191 if not self.rtc.GetFilename():
192 self.OnFileSaveAs(evt)
193 return
194 self.rtc.SaveFile()
195
196 def OnFileSaveAs(self, evt):
197 # TODO: Use RichTextBuffer.GetExtWildcard to get the wildcard string
198 dlg = wx.FileDialog(self, "Choose a filename",
199 wildcard="All files (*.*)|*.*",
88535d8e 200 style=wx.SAVE)
30fc5e8f
RD
201 if dlg.ShowModal() == wx.ID_OK:
202 path = dlg.GetPath()
203 if path:
204 self.rtc.SaveFile(path)
e2e0b76a
RD
205 dlg.Destroy()
206
30fc5e8f
RD
207
208 def OnFileViewHTML(self, evt): pass
209
210
211 def OnFileExit(self, evt):
212 self.Close(True)
213
214
215 def OnBold(self, evt):
216 self.rtc.ApplyBoldToSelection()
217
218 def OnItalic(self, evt):
219 self.rtc.ApplyItalicToSelection()
220
221 def OnUnderline(self, evt):
222 self.rtc.ApplyUnderlineToSelection()
223
224 def OnAlignLeft(self, evt):
225 self.rtc.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_LEFT)
226
227 def OnAlignRight(self, evt):
228 self.rtc.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_RIGHT)
229
230 def OnAlignCenter(self, evt):
231 self.rtc.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_CENTRE)
232
233 def OnIndentMore(self, evt):
234 attr = rt.RichTextAttr()
235 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
236 ip = self.rtc.GetInsertionPoint()
237 if self.rtc.GetStyle(ip, attr):
238 r = rt.RichTextRange(ip, ip)
239 if self.rtc.HasSelection():
240 r = self.rtc.GetSelectionRange()
241
242 attr.SetLeftIndent(attr.GetLeftIndent() + 100)
243 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
244 self.rtc.SetStyle(r, attr)
245
246
247 def OnIndentLess(self, evt):
248 attr = rt.RichTextAttr()
249 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
250 ip = self.rtc.GetInsertionPoint()
251 if self.rtc.GetStyle(ip, attr):
252 r = rt.RichTextRange(ip, ip)
253 if self.rtc.HasSelection():
254 r = self.rtc.GetSelectionRange()
255
256 if attr.GetLeftIndent() >= 100:
257 attr.SetLeftIndent(attr.GetLeftIndent() - 100)
258 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
259 self.rtc.SetStyle(r, attr)
260
261
262 def OnParagraphSpacingMore(self, evt):
263 attr = rt.RichTextAttr()
264 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
265 ip = self.rtc.GetInsertionPoint()
266 if self.rtc.GetStyle(ip, attr):
267 r = rt.RichTextRange(ip, ip)
268 if self.rtc.HasSelection():
269 r = self.rtc.GetSelectionRange()
270
271 attr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter() + 20);
272 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
273 self.rtc.SetStyle(r, attr)
274
275
276 def OnParagraphSpacingLess(self, evt):
277 attr = rt.RichTextAttr()
278 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
279 ip = self.rtc.GetInsertionPoint()
280 if self.rtc.GetStyle(ip, attr):
281 r = rt.RichTextRange(ip, ip)
282 if self.rtc.HasSelection():
283 r = self.rtc.GetSelectionRange()
284
285 if attr.GetParagraphSpacingAfter() >= 20:
286 attr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter() - 20);
287 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
288 self.rtc.SetStyle(r, attr)
289
290
291 def OnLineSpacingSingle(self, evt):
292 attr = rt.RichTextAttr()
293 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
294 ip = self.rtc.GetInsertionPoint()
295 if self.rtc.GetStyle(ip, attr):
296 r = rt.RichTextRange(ip, ip)
297 if self.rtc.HasSelection():
298 r = self.rtc.GetSelectionRange()
299
300 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
301 attr.SetLineSpacing(10)
302 self.rtc.SetStyle(r, attr)
303
304
305 def OnLineSpacingHalf(self, evt):
306 attr = rt.RichTextAttr()
307 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
308 ip = self.rtc.GetInsertionPoint()
309 if self.rtc.GetStyle(ip, attr):
310 r = rt.RichTextRange(ip, ip)
311 if self.rtc.HasSelection():
312 r = self.rtc.GetSelectionRange()
313
314 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
315 attr.SetLineSpacing(15)
316 self.rtc.SetStyle(r, attr)
317
318
319 def OnLineSpacingDouble(self, evt):
320 attr = rt.RichTextAttr()
321 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
322 ip = self.rtc.GetInsertionPoint()
323 if self.rtc.GetStyle(ip, attr):
324 r = rt.RichTextRange(ip, ip)
325 if self.rtc.HasSelection():
326 r = self.rtc.GetSelectionRange()
327
328 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
329 attr.SetLineSpacing(20)
330 self.rtc.SetStyle(r, attr)
331
332
333 def OnFont(self, evt):
334 if not self.rtc.HasSelection():
335 return
336
337 r = self.rtc.GetSelectionRange()
338 fontData = wx.FontData()
b97ff8ed 339 fontData.EnableEffects(False)
30fc5e8f
RD
340 attr = rt.RichTextAttr()
341 attr.SetFlags(rt.TEXT_ATTR_FONT)
342 if self.rtc.GetStyle(self.rtc.GetInsertionPoint(), attr):
343 fontData.SetInitialFont(attr.CreateFont())
344
345 dlg = wx.FontDialog(self, fontData)
346 if dlg.ShowModal() == wx.ID_OK:
347 fontData = dlg.GetFontData()
348 font = fontData.GetChosenFont()
349 if font:
350 attr.SetFlags(rt.TEXT_ATTR_FONT)
351 attr.SetFont(font)
352 self.rtc.SetStyle(r, attr)
353 dlg.Destroy()
354
355
b97ff8ed
RD
356 def OnColour(self, evt):
357 colourData = wx.ColourData()
358 attr = rt.RichTextAttr()
359 attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
360 if self.rtc.GetStyle(self.rtc.GetInsertionPoint(), attr):
361 colourData.SetColour(attr.GetTextColour())
362
363 dlg = wx.ColourDialog(self, colourData)
364 if dlg.ShowModal() == wx.ID_OK:
365 colourData = dlg.GetColourData()
366 colour = colourData.GetColour()
367 if colour:
368 if not self.rtc.HasSelection():
369 self.rtc.BeginTextColour(colour)
370 else:
371 r = self.rtc.GetSelectionRange()
372 attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
373 attr.SetTextColour(colour)
374 self.rtc.SetStyle(r, attr)
375 dlg.Destroy()
376
377
378
30fc5e8f
RD
379 def OnUpdateBold(self, evt):
380 evt.Check(self.rtc.IsSelectionBold())
381
382 def OnUpdateItalic(self, evt):
383 evt.Check(self.rtc.IsSelectionItalics())
384
385 def OnUpdateUnderline(self, evt):
386 evt.Check(self.rtc.IsSelectionUnderlined())
387
388 def OnUpdateAlignLeft(self, evt):
389 evt.Check(self.rtc.IsSelectionAligned(rt.TEXT_ALIGNMENT_LEFT))
390
391 def OnUpdateAlignCenter(self, evt):
392 evt.Check(self.rtc.IsSelectionAligned(rt.TEXT_ALIGNMENT_CENTRE))
393
394 def OnUpdateAlignRight(self, evt):
395 evt.Check(self.rtc.IsSelectionAligned(rt.TEXT_ALIGNMENT_RIGHT))
396
397
398 def ForwardEvent(self, evt):
399 # The RichTextCtrl can handle menu and update events for undo,
400 # redo, cut, copy, paste, delete, and select all, so just
401 # forward the event to it.
402 self.rtc.ProcessEvent(evt)
403
404
405 def MakeMenuBar(self):
406 def doBind(item, handler, updateUI=None):
407 self.Bind(wx.EVT_MENU, handler, item)
408 if updateUI is not None:
409 self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
410
411 fileMenu = wx.Menu()
412 doBind( fileMenu.Append(-1, "&Open\tCtrl+O", "Open a file"),
413 self.OnFileOpen )
414 doBind( fileMenu.Append(-1, "&Save\tCtrl+S", "Save a file"),
415 self.OnFileSave )
416 doBind( fileMenu.Append(-1, "&Save As...\tF12", "Save to a new file"),
417 self.OnFileSaveAs )
418 fileMenu.AppendSeparator()
419 doBind( fileMenu.Append(-1, "&View as HTML", "View HTML"),
420 self.OnFileViewHTML)
421 fileMenu.AppendSeparator()
422 doBind( fileMenu.Append(-1, "E&xit\tCtrl+Q", "Quit this program"),
423 self.OnFileExit )
424
425 editMenu = wx.Menu()
426 doBind( editMenu.Append(wx.ID_UNDO, "&Undo\tCtrl+Z"),
427 self.ForwardEvent, self.ForwardEvent)
428 doBind( editMenu.Append(wx.ID_REDO, "&Redo\tCtrl+Y"),
429 self.ForwardEvent, self.ForwardEvent )
430 editMenu.AppendSeparator()
431 doBind( editMenu.Append(wx.ID_CUT, "Cu&t\tCtrl+X"),
432 self.ForwardEvent, self.ForwardEvent )
433 doBind( editMenu.Append(wx.ID_COPY, "&Copy\tCtrl+C"),
434 self.ForwardEvent, self.ForwardEvent)
435 doBind( editMenu.Append(wx.ID_PASTE, "&Paste\tCtrl+V"),
436 self.ForwardEvent, self.ForwardEvent)
437 doBind( editMenu.Append(wx.ID_CLEAR, "&Delete\tDel"),
438 self.ForwardEvent, self.ForwardEvent)
439 editMenu.AppendSeparator()
440 doBind( editMenu.Append(wx.ID_SELECTALL, "Select A&ll\tCtrl+A"),
441 self.ForwardEvent, self.ForwardEvent )
442
443 #doBind( editMenu.AppendSeparator(), )
444 #doBind( editMenu.Append(-1, "&Find...\tCtrl+F"), )
445 #doBind( editMenu.Append(-1, "&Replace...\tCtrl+R"), )
446
447 formatMenu = wx.Menu()
448 doBind( formatMenu.AppendCheckItem(-1, "&Bold\tCtrl+B"),
449 self.OnBold, self.OnUpdateBold)
450 doBind( formatMenu.AppendCheckItem(-1, "&Italic\tCtrl+I"),
451 self.OnItalic, self.OnUpdateItalic)
452 doBind( formatMenu.AppendCheckItem(-1, "&Underline\tCtrl+U"),
453 self.OnUnderline, self.OnUpdateUnderline)
454 formatMenu.AppendSeparator()
455 doBind( formatMenu.AppendCheckItem(-1, "L&eft Align"),
456 self.OnAlignLeft, self.OnUpdateAlignLeft)
457 doBind( formatMenu.AppendCheckItem(-1, "&Centre"),
458 self.OnAlignCenter, self.OnUpdateAlignCenter)
459 doBind( formatMenu.AppendCheckItem(-1, "&Right Align"),
460 self.OnAlignRight, self.OnUpdateAlignRight)
461 formatMenu.AppendSeparator()
462 doBind( formatMenu.Append(-1, "Indent &More"), self.OnIndentMore)
463 doBind( formatMenu.Append(-1, "Indent &Less"), self.OnIndentLess)
464 formatMenu.AppendSeparator()
465 doBind( formatMenu.Append(-1, "Increase Paragraph &Spacing"), self.OnParagraphSpacingMore)
466 doBind( formatMenu.Append(-1, "Decrease &Paragraph Spacing"), self.OnParagraphSpacingLess)
467 formatMenu.AppendSeparator()
468 doBind( formatMenu.Append(-1, "Normal Line Spacing"), self.OnLineSpacingSingle)
469 doBind( formatMenu.Append(-1, "1.5 Line Spacing"), self.OnLineSpacingHalf)
470 doBind( formatMenu.Append(-1, "Double Line Spacing"), self.OnLineSpacingDouble)
471 formatMenu.AppendSeparator()
472 doBind( formatMenu.Append(-1, "&Font..."), self.OnFont)
473
474 mb = wx.MenuBar()
475 mb.Append(fileMenu, "&File")
476 mb.Append(editMenu, "&Edit")
477 mb.Append(formatMenu, "F&ormat")
478 self.SetMenuBar(mb)
479
480
481 def MakeToolBar(self):
482 def doBind(item, handler, updateUI=None):
483 self.Bind(wx.EVT_TOOL, handler, item)
484 if updateUI is not None:
485 self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
486
487 tbar = self.CreateToolBar()
488 doBind( tbar.AddTool(-1, images.get_rt_openBitmap(),
489 shortHelpString="Open"), self.OnFileOpen)
490 doBind( tbar.AddTool(-1, images.get_rt_saveBitmap(),
491 shortHelpString="Save"), self.OnFileSave)
492 tbar.AddSeparator()
493 doBind( tbar.AddTool(wx.ID_CUT, images.get_rt_cutBitmap(),
494 shortHelpString="Cut"), self.ForwardEvent, self.ForwardEvent)
495 doBind( tbar.AddTool(wx.ID_COPY, images.get_rt_copyBitmap(),
496 shortHelpString="Copy"), self.ForwardEvent, self.ForwardEvent)
497 doBind( tbar.AddTool(wx.ID_PASTE, images.get_rt_pasteBitmap(),
498 shortHelpString="Paste"), self.ForwardEvent, self.ForwardEvent)
499 tbar.AddSeparator()
500 doBind( tbar.AddTool(wx.ID_UNDO, images.get_rt_undoBitmap(),
501 shortHelpString="Undo"), self.ForwardEvent, self.ForwardEvent)
502 doBind( tbar.AddTool(wx.ID_REDO, images.get_rt_redoBitmap(),
503 shortHelpString="Redo"), self.ForwardEvent, self.ForwardEvent)
504 tbar.AddSeparator()
505 doBind( tbar.AddTool(-1, images.get_rt_boldBitmap(), isToggle=True,
506 shortHelpString="Bold"), self.OnBold, self.OnUpdateBold)
507 doBind( tbar.AddTool(-1, images.get_rt_italicBitmap(), isToggle=True,
508 shortHelpString="Italic"), self.OnItalic, self.OnUpdateItalic)
509 doBind( tbar.AddTool(-1, images.get_rt_underlineBitmap(), isToggle=True,
510 shortHelpString="Underline"), self.OnUnderline, self.OnUpdateUnderline)
511 tbar.AddSeparator()
512 doBind( tbar.AddTool(-1, images.get_rt_alignleftBitmap(), isToggle=True,
513 shortHelpString="Align Left"), self.OnAlignLeft, self.OnUpdateAlignLeft)
514 doBind( tbar.AddTool(-1, images.get_rt_centreBitmap(), isToggle=True,
515 shortHelpString="Center"), self.OnAlignCenter, self.OnUpdateAlignCenter)
516 doBind( tbar.AddTool(-1, images.get_rt_alignrightBitmap(), isToggle=True,
517 shortHelpString="Align Right"), self.OnAlignRight, self.OnUpdateAlignRight)
518 tbar.AddSeparator()
519 doBind( tbar.AddTool(-1, images.get_rt_indentlessBitmap(),
520 shortHelpString="Indent Less"), self.OnIndentLess)
521 doBind( tbar.AddTool(-1, images.get_rt_indentmoreBitmap(),
522 shortHelpString="Indent More"), self.OnIndentMore)
523 tbar.AddSeparator()
524 doBind( tbar.AddTool(-1, images.get_rt_fontBitmap(),
525 shortHelpString="Font"), self.OnFont)
b97ff8ed
RD
526 doBind( tbar.AddTool(-1, images.get_rt_colourBitmap(),
527 shortHelpString="Font Colour"), self.OnColour)
30fc5e8f
RD
528
529 tbar.Realize()
530
531
532
533#----------------------------------------------------------------------
534
535class TestPanel(wx.Panel):
536 def __init__(self, parent, log):
537 self.log = log
538 wx.Panel.__init__(self, parent, -1)
539
540 b = wx.Button(self, -1, "Show the RichTextCtrl sample", (50,50))
541 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
542
543
544 def OnButton(self, evt):
545 win = RichTextFrame(self, -1, "wx.richtext.RichTextCtrl",
546 size=(700, 500),
547 style = wx.DEFAULT_FRAME_STYLE)
548 win.Show(True)
549
550 # give easy access to PyShell if it's running
551 self.rtfrm = win
552 self.rtc = win.rtc
553
554#----------------------------------------------------------------------
555
556def runTest(frame, nb, log):
557 win = TestPanel(nb, log)
558 return win
559
560#----------------------------------------------------------------------
561
562
563
564overview = """<html><body>
565<h2><center>wx.richtext.RichTextCtrl</center></h2>
566
567</body></html>
568"""
569
570
571
572if __name__ == '__main__':
573 import sys,os
574 import run
575 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
576