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