]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/RichTextCtrl.py
workaround sizing bug on Mac
[wxWidgets.git] / wxPython / demo / RichTextCtrl.py
1
2 import wx
3 import wx.richtext as rt
4 import images
5
6 #----------------------------------------------------------------------
7
8 class 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 (*.*)|*.*",
200 style=wx.OPEN)
201 if dlg.ShowModal() == wx.ID_OK:
202 path = dlg.GetPath()
203 if path:
204 self.rtc.SaveFile(path)
205
206
207 def OnFileViewHTML(self, evt): pass
208
209
210 def OnFileExit(self, evt):
211 self.Close(True)
212
213
214 def OnBold(self, evt):
215 self.rtc.ApplyBoldToSelection()
216
217 def OnItalic(self, evt):
218 self.rtc.ApplyItalicToSelection()
219
220 def OnUnderline(self, evt):
221 self.rtc.ApplyUnderlineToSelection()
222
223 def OnAlignLeft(self, evt):
224 self.rtc.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_LEFT)
225
226 def OnAlignRight(self, evt):
227 self.rtc.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_RIGHT)
228
229 def OnAlignCenter(self, evt):
230 self.rtc.ApplyAlignmentToSelection(rt.TEXT_ALIGNMENT_CENTRE)
231
232 def OnIndentMore(self, evt):
233 attr = rt.RichTextAttr()
234 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
235 ip = self.rtc.GetInsertionPoint()
236 if self.rtc.GetStyle(ip, attr):
237 r = rt.RichTextRange(ip, ip)
238 if self.rtc.HasSelection():
239 r = self.rtc.GetSelectionRange()
240
241 attr.SetLeftIndent(attr.GetLeftIndent() + 100)
242 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
243 self.rtc.SetStyle(r, attr)
244
245
246 def OnIndentLess(self, evt):
247 attr = rt.RichTextAttr()
248 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
249 ip = self.rtc.GetInsertionPoint()
250 if self.rtc.GetStyle(ip, attr):
251 r = rt.RichTextRange(ip, ip)
252 if self.rtc.HasSelection():
253 r = self.rtc.GetSelectionRange()
254
255 if attr.GetLeftIndent() >= 100:
256 attr.SetLeftIndent(attr.GetLeftIndent() - 100)
257 attr.SetFlags(rt.TEXT_ATTR_LEFT_INDENT)
258 self.rtc.SetStyle(r, attr)
259
260
261 def OnParagraphSpacingMore(self, evt):
262 attr = rt.RichTextAttr()
263 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
264 ip = self.rtc.GetInsertionPoint()
265 if self.rtc.GetStyle(ip, attr):
266 r = rt.RichTextRange(ip, ip)
267 if self.rtc.HasSelection():
268 r = self.rtc.GetSelectionRange()
269
270 attr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter() + 20);
271 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
272 self.rtc.SetStyle(r, attr)
273
274
275 def OnParagraphSpacingLess(self, evt):
276 attr = rt.RichTextAttr()
277 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
278 ip = self.rtc.GetInsertionPoint()
279 if self.rtc.GetStyle(ip, attr):
280 r = rt.RichTextRange(ip, ip)
281 if self.rtc.HasSelection():
282 r = self.rtc.GetSelectionRange()
283
284 if attr.GetParagraphSpacingAfter() >= 20:
285 attr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter() - 20);
286 attr.SetFlags(rt.TEXT_ATTR_PARA_SPACING_AFTER)
287 self.rtc.SetStyle(r, attr)
288
289
290 def OnLineSpacingSingle(self, evt):
291 attr = rt.RichTextAttr()
292 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
293 ip = self.rtc.GetInsertionPoint()
294 if self.rtc.GetStyle(ip, attr):
295 r = rt.RichTextRange(ip, ip)
296 if self.rtc.HasSelection():
297 r = self.rtc.GetSelectionRange()
298
299 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
300 attr.SetLineSpacing(10)
301 self.rtc.SetStyle(r, attr)
302
303
304 def OnLineSpacingHalf(self, evt):
305 attr = rt.RichTextAttr()
306 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
307 ip = self.rtc.GetInsertionPoint()
308 if self.rtc.GetStyle(ip, attr):
309 r = rt.RichTextRange(ip, ip)
310 if self.rtc.HasSelection():
311 r = self.rtc.GetSelectionRange()
312
313 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
314 attr.SetLineSpacing(15)
315 self.rtc.SetStyle(r, attr)
316
317
318 def OnLineSpacingDouble(self, evt):
319 attr = rt.RichTextAttr()
320 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
321 ip = self.rtc.GetInsertionPoint()
322 if self.rtc.GetStyle(ip, attr):
323 r = rt.RichTextRange(ip, ip)
324 if self.rtc.HasSelection():
325 r = self.rtc.GetSelectionRange()
326
327 attr.SetFlags(rt.TEXT_ATTR_LINE_SPACING)
328 attr.SetLineSpacing(20)
329 self.rtc.SetStyle(r, attr)
330
331
332 def OnFont(self, evt):
333 if not self.rtc.HasSelection():
334 return
335
336 r = self.rtc.GetSelectionRange()
337 fontData = wx.FontData()
338 fontData.EnableEffects(False)
339 attr = rt.RichTextAttr()
340 attr.SetFlags(rt.TEXT_ATTR_FONT)
341 if self.rtc.GetStyle(self.rtc.GetInsertionPoint(), attr):
342 fontData.SetInitialFont(attr.CreateFont())
343
344 dlg = wx.FontDialog(self, fontData)
345 if dlg.ShowModal() == wx.ID_OK:
346 fontData = dlg.GetFontData()
347 font = fontData.GetChosenFont()
348 if font:
349 attr.SetFlags(rt.TEXT_ATTR_FONT)
350 attr.SetFont(font)
351 self.rtc.SetStyle(r, attr)
352 dlg.Destroy()
353
354
355 def OnColour(self, evt):
356 colourData = wx.ColourData()
357 attr = rt.RichTextAttr()
358 attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
359 if self.rtc.GetStyle(self.rtc.GetInsertionPoint(), attr):
360 colourData.SetColour(attr.GetTextColour())
361
362 dlg = wx.ColourDialog(self, colourData)
363 if dlg.ShowModal() == wx.ID_OK:
364 colourData = dlg.GetColourData()
365 colour = colourData.GetColour()
366 if colour:
367 if not self.rtc.HasSelection():
368 self.rtc.BeginTextColour(colour)
369 else:
370 r = self.rtc.GetSelectionRange()
371 attr.SetFlags(rt.TEXT_ATTR_TEXT_COLOUR)
372 attr.SetTextColour(colour)
373 self.rtc.SetStyle(r, attr)
374 dlg.Destroy()
375
376
377
378 def OnUpdateBold(self, evt):
379 evt.Check(self.rtc.IsSelectionBold())
380
381 def OnUpdateItalic(self, evt):
382 evt.Check(self.rtc.IsSelectionItalics())
383
384 def OnUpdateUnderline(self, evt):
385 evt.Check(self.rtc.IsSelectionUnderlined())
386
387 def OnUpdateAlignLeft(self, evt):
388 evt.Check(self.rtc.IsSelectionAligned(rt.TEXT_ALIGNMENT_LEFT))
389
390 def OnUpdateAlignCenter(self, evt):
391 evt.Check(self.rtc.IsSelectionAligned(rt.TEXT_ALIGNMENT_CENTRE))
392
393 def OnUpdateAlignRight(self, evt):
394 evt.Check(self.rtc.IsSelectionAligned(rt.TEXT_ALIGNMENT_RIGHT))
395
396
397 def ForwardEvent(self, evt):
398 # The RichTextCtrl can handle menu and update events for undo,
399 # redo, cut, copy, paste, delete, and select all, so just
400 # forward the event to it.
401 self.rtc.ProcessEvent(evt)
402
403
404 def MakeMenuBar(self):
405 def doBind(item, handler, updateUI=None):
406 self.Bind(wx.EVT_MENU, handler, item)
407 if updateUI is not None:
408 self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
409
410 fileMenu = wx.Menu()
411 doBind( fileMenu.Append(-1, "&Open\tCtrl+O", "Open a file"),
412 self.OnFileOpen )
413 doBind( fileMenu.Append(-1, "&Save\tCtrl+S", "Save a file"),
414 self.OnFileSave )
415 doBind( fileMenu.Append(-1, "&Save As...\tF12", "Save to a new file"),
416 self.OnFileSaveAs )
417 fileMenu.AppendSeparator()
418 doBind( fileMenu.Append(-1, "&View as HTML", "View HTML"),
419 self.OnFileViewHTML)
420 fileMenu.AppendSeparator()
421 doBind( fileMenu.Append(-1, "E&xit\tCtrl+Q", "Quit this program"),
422 self.OnFileExit )
423
424 editMenu = wx.Menu()
425 doBind( editMenu.Append(wx.ID_UNDO, "&Undo\tCtrl+Z"),
426 self.ForwardEvent, self.ForwardEvent)
427 doBind( editMenu.Append(wx.ID_REDO, "&Redo\tCtrl+Y"),
428 self.ForwardEvent, self.ForwardEvent )
429 editMenu.AppendSeparator()
430 doBind( editMenu.Append(wx.ID_CUT, "Cu&t\tCtrl+X"),
431 self.ForwardEvent, self.ForwardEvent )
432 doBind( editMenu.Append(wx.ID_COPY, "&Copy\tCtrl+C"),
433 self.ForwardEvent, self.ForwardEvent)
434 doBind( editMenu.Append(wx.ID_PASTE, "&Paste\tCtrl+V"),
435 self.ForwardEvent, self.ForwardEvent)
436 doBind( editMenu.Append(wx.ID_CLEAR, "&Delete\tDel"),
437 self.ForwardEvent, self.ForwardEvent)
438 editMenu.AppendSeparator()
439 doBind( editMenu.Append(wx.ID_SELECTALL, "Select A&ll\tCtrl+A"),
440 self.ForwardEvent, self.ForwardEvent )
441
442 #doBind( editMenu.AppendSeparator(), )
443 #doBind( editMenu.Append(-1, "&Find...\tCtrl+F"), )
444 #doBind( editMenu.Append(-1, "&Replace...\tCtrl+R"), )
445
446 formatMenu = wx.Menu()
447 doBind( formatMenu.AppendCheckItem(-1, "&Bold\tCtrl+B"),
448 self.OnBold, self.OnUpdateBold)
449 doBind( formatMenu.AppendCheckItem(-1, "&Italic\tCtrl+I"),
450 self.OnItalic, self.OnUpdateItalic)
451 doBind( formatMenu.AppendCheckItem(-1, "&Underline\tCtrl+U"),
452 self.OnUnderline, self.OnUpdateUnderline)
453 formatMenu.AppendSeparator()
454 doBind( formatMenu.AppendCheckItem(-1, "L&eft Align"),
455 self.OnAlignLeft, self.OnUpdateAlignLeft)
456 doBind( formatMenu.AppendCheckItem(-1, "&Centre"),
457 self.OnAlignCenter, self.OnUpdateAlignCenter)
458 doBind( formatMenu.AppendCheckItem(-1, "&Right Align"),
459 self.OnAlignRight, self.OnUpdateAlignRight)
460 formatMenu.AppendSeparator()
461 doBind( formatMenu.Append(-1, "Indent &More"), self.OnIndentMore)
462 doBind( formatMenu.Append(-1, "Indent &Less"), self.OnIndentLess)
463 formatMenu.AppendSeparator()
464 doBind( formatMenu.Append(-1, "Increase Paragraph &Spacing"), self.OnParagraphSpacingMore)
465 doBind( formatMenu.Append(-1, "Decrease &Paragraph Spacing"), self.OnParagraphSpacingLess)
466 formatMenu.AppendSeparator()
467 doBind( formatMenu.Append(-1, "Normal Line Spacing"), self.OnLineSpacingSingle)
468 doBind( formatMenu.Append(-1, "1.5 Line Spacing"), self.OnLineSpacingHalf)
469 doBind( formatMenu.Append(-1, "Double Line Spacing"), self.OnLineSpacingDouble)
470 formatMenu.AppendSeparator()
471 doBind( formatMenu.Append(-1, "&Font..."), self.OnFont)
472
473 mb = wx.MenuBar()
474 mb.Append(fileMenu, "&File")
475 mb.Append(editMenu, "&Edit")
476 mb.Append(formatMenu, "F&ormat")
477 self.SetMenuBar(mb)
478
479
480 def MakeToolBar(self):
481 def doBind(item, handler, updateUI=None):
482 self.Bind(wx.EVT_TOOL, handler, item)
483 if updateUI is not None:
484 self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
485
486 tbar = self.CreateToolBar()
487 doBind( tbar.AddTool(-1, images.get_rt_openBitmap(),
488 shortHelpString="Open"), self.OnFileOpen)
489 doBind( tbar.AddTool(-1, images.get_rt_saveBitmap(),
490 shortHelpString="Save"), self.OnFileSave)
491 tbar.AddSeparator()
492 doBind( tbar.AddTool(wx.ID_CUT, images.get_rt_cutBitmap(),
493 shortHelpString="Cut"), self.ForwardEvent, self.ForwardEvent)
494 doBind( tbar.AddTool(wx.ID_COPY, images.get_rt_copyBitmap(),
495 shortHelpString="Copy"), self.ForwardEvent, self.ForwardEvent)
496 doBind( tbar.AddTool(wx.ID_PASTE, images.get_rt_pasteBitmap(),
497 shortHelpString="Paste"), self.ForwardEvent, self.ForwardEvent)
498 tbar.AddSeparator()
499 doBind( tbar.AddTool(wx.ID_UNDO, images.get_rt_undoBitmap(),
500 shortHelpString="Undo"), self.ForwardEvent, self.ForwardEvent)
501 doBind( tbar.AddTool(wx.ID_REDO, images.get_rt_redoBitmap(),
502 shortHelpString="Redo"), self.ForwardEvent, self.ForwardEvent)
503 tbar.AddSeparator()
504 doBind( tbar.AddTool(-1, images.get_rt_boldBitmap(), isToggle=True,
505 shortHelpString="Bold"), self.OnBold, self.OnUpdateBold)
506 doBind( tbar.AddTool(-1, images.get_rt_italicBitmap(), isToggle=True,
507 shortHelpString="Italic"), self.OnItalic, self.OnUpdateItalic)
508 doBind( tbar.AddTool(-1, images.get_rt_underlineBitmap(), isToggle=True,
509 shortHelpString="Underline"), self.OnUnderline, self.OnUpdateUnderline)
510 tbar.AddSeparator()
511 doBind( tbar.AddTool(-1, images.get_rt_alignleftBitmap(), isToggle=True,
512 shortHelpString="Align Left"), self.OnAlignLeft, self.OnUpdateAlignLeft)
513 doBind( tbar.AddTool(-1, images.get_rt_centreBitmap(), isToggle=True,
514 shortHelpString="Center"), self.OnAlignCenter, self.OnUpdateAlignCenter)
515 doBind( tbar.AddTool(-1, images.get_rt_alignrightBitmap(), isToggle=True,
516 shortHelpString="Align Right"), self.OnAlignRight, self.OnUpdateAlignRight)
517 tbar.AddSeparator()
518 doBind( tbar.AddTool(-1, images.get_rt_indentlessBitmap(),
519 shortHelpString="Indent Less"), self.OnIndentLess)
520 doBind( tbar.AddTool(-1, images.get_rt_indentmoreBitmap(),
521 shortHelpString="Indent More"), self.OnIndentMore)
522 tbar.AddSeparator()
523 doBind( tbar.AddTool(-1, images.get_rt_fontBitmap(),
524 shortHelpString="Font"), self.OnFont)
525 doBind( tbar.AddTool(-1, images.get_rt_colourBitmap(),
526 shortHelpString="Font Colour"), self.OnColour)
527
528 tbar.Realize()
529
530
531
532 #----------------------------------------------------------------------
533
534 class TestPanel(wx.Panel):
535 def __init__(self, parent, log):
536 self.log = log
537 wx.Panel.__init__(self, parent, -1)
538
539 b = wx.Button(self, -1, "Show the RichTextCtrl sample", (50,50))
540 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
541
542
543 def OnButton(self, evt):
544 win = RichTextFrame(self, -1, "wx.richtext.RichTextCtrl",
545 size=(700, 500),
546 style = wx.DEFAULT_FRAME_STYLE)
547 win.Show(True)
548
549 # give easy access to PyShell if it's running
550 self.rtfrm = win
551 self.rtc = win.rtc
552
553 #----------------------------------------------------------------------
554
555 def runTest(frame, nb, log):
556 win = TestPanel(nb, log)
557 return win
558
559 #----------------------------------------------------------------------
560
561
562
563 overview = """<html><body>
564 <h2><center>wx.richtext.RichTextCtrl</center></h2>
565
566 </body></html>
567 """
568
569
570
571 if __name__ == '__main__':
572 import sys,os
573 import run
574 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
575