3 import wx
.richtext
as rt
6 #----------------------------------------------------------------------
8 class RichTextFrame(wx
.Frame
):
9 def __init__(self
, *args
, **kw
):
10 wx
.Frame
.__init
__(self
, *args
, **kw
)
14 self
.CreateStatusBar()
15 self
.SetStatusText("Welcome to wx.richtext.RichTextCtrl!")
17 self
.rtc
= rt
.RichTextCtrl(self
, style
=wx
.VSCROLL|wx
.HSCROLL|wx
.NO_BORDER
);
18 wx
.CallAfter(self
.rtc
.SetFocus
)
21 self
.rtc
.BeginSuppressUndo()
23 self
.rtc
.BeginParagraphSpacing(0, 20)
25 self
.rtc
.BeginAlignment(rt
.TEXT_ALIGNMENT_CENTRE
)
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()
33 self
.rtc
.BeginItalic()
34 self
.rtc
.WriteText("by Julian Smart")
40 self
.rtc
.WriteImage(images
.get_rt_zebraImage())
42 self
.rtc
.EndAlignment()
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 ")
51 self
.rtc
.BeginTextColour((255, 0, 0))
52 self
.rtc
.WriteText("colour, like this red bit.")
53 self
.rtc
.EndTextColour()
55 self
.rtc
.BeginTextColour((0, 0, 255))
56 self
.rtc
.WriteText(" And this blue bit.")
57 self
.rtc
.EndTextColour()
59 self
.rtc
.WriteText(" Naturally you can make things ")
61 self
.rtc
.WriteText("bold ")
63 self
.rtc
.BeginItalic()
64 self
.rtc
.WriteText("or italic ")
66 self
.rtc
.BeginUnderline()
67 self
.rtc
.WriteText("or underlined.")
68 self
.rtc
.EndUnderline()
70 self
.rtc
.BeginFontSize(14)
71 self
.rtc
.WriteText(" Different font sizes on the same line is allowed, too.")
72 self
.rtc
.EndFontSize()
74 self
.rtc
.WriteText(" Next we'll show an indented paragraph.")
76 self
.rtc
.BeginLeftIndent(60)
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()
84 self
.rtc
.WriteText("Next, we'll show a first-line indent, achieved using BeginLeftIndent(100, -40).")
86 self
.rtc
.BeginLeftIndent(100, -40)
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.")
90 self
.rtc
.EndLeftIndent()
94 self
.rtc
.WriteText("Numbered bullets are possible, again using sub-indents:")
96 self
.rtc
.BeginNumberedBullet(1, 100, 60)
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()
102 self
.rtc
.BeginNumberedBullet(2, 100, 60)
105 self
.rtc
.WriteText("This is my second item.")
106 self
.rtc
.EndNumberedBullet()
110 self
.rtc
.WriteText("The following paragraph is right-indented:")
112 self
.rtc
.BeginRightIndent(200)
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()
120 self
.rtc
.WriteText("The following paragraph is right-aligned with 1.5 line spacing:")
122 self
.rtc
.BeginAlignment(rt
.TEXT_ALIGNMENT_RIGHT
)
123 self
.rtc
.BeginLineSpacing(rt
.TEXT_ATTR_LINE_SPACING_HALF
)
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()
131 self
.rtc
.WriteText("Other notable features of wxRichTextCtrl include:")
133 self
.rtc
.BeginSymbolBullet('*', 100, 60)
135 self
.rtc
.WriteText("Compatibility with wxTextCtrl API")
136 self
.rtc
.EndSymbolBullet()
138 self
.rtc
.BeginSymbolBullet('*', 100, 60)
140 self
.rtc
.WriteText("Easy stack-based BeginXXX()...EndXXX() style setting in addition to SetStyle()")
141 self
.rtc
.EndSymbolBullet()
143 self
.rtc
.BeginSymbolBullet('*', 100, 60)
145 self
.rtc
.WriteText("XML loading and saving")
146 self
.rtc
.EndSymbolBullet()
148 self
.rtc
.BeginSymbolBullet('*', 100, 60)
150 self
.rtc
.WriteText("Undo/Redo, with batching option and Undo suppressing")
151 self
.rtc
.EndSymbolBullet()
153 self
.rtc
.BeginSymbolBullet('*', 100, 60)
155 self
.rtc
.WriteText("Clipboard copy and paste")
156 self
.rtc
.EndSymbolBullet()
158 self
.rtc
.BeginSymbolBullet('*', 100, 60)
160 self
.rtc
.WriteText("wxRichTextStyleSheet with named character and paragraph styles, and control for applying named styles")
161 self
.rtc
.EndSymbolBullet()
163 self
.rtc
.BeginSymbolBullet('*', 100, 60)
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()
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!")
172 self
.rtc
.EndParagraphSpacing()
174 self
.rtc
.EndSuppressUndo()
178 def OnFileOpen(self
, evt
):
179 # This gives us a string suitable for the file dialog based on
180 # the file handlers that are loaded
181 wildcard
, types
= rt
.RichTextBuffer
.GetExtWildcard(save
=False)
182 dlg
= wx
.FileDialog(self
, "Choose a filename",
185 if dlg
.ShowModal() == wx
.ID_OK
:
188 fileType
= types
[dlg
.GetFilterIndex()]
189 self
.rtc
.LoadFile(path
, fileType
)
193 def OnFileSave(self
, evt
):
194 if not self
.rtc
.GetFilename():
195 self
.OnFileSaveAs(evt
)
200 def OnFileSaveAs(self
, evt
):
201 wildcard
, types
= rt
.RichTextBuffer
.GetExtWildcard(save
=True)
203 dlg
= wx
.FileDialog(self
, "Choose a filename",
206 if dlg
.ShowModal() == wx
.ID_OK
:
209 fileType
= types
[dlg
.GetFilterIndex()]
210 ext
= rt
.RichTextBuffer
.FindHandlerByType(fileType
).GetExtension()
211 if not path
.endswith(ext
):
213 self
.rtc
.SaveFile(path
, fileType
)
217 def OnFileViewHTML(self
, evt
):
218 # Get an instance of the html file handler, use it to save the
219 # document to a StringIO stream, and then display the
220 # resulting html text in a dialog with a HtmlWindow.
221 handler
= rt
.RichTextHTMLHandler()
222 handler
.SetFlags(rt
.RICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY
)
223 handler
.SetFontSizeMapping([7,9,11,12,14,22,100])
226 stream
= cStringIO
.StringIO()
227 if not handler
.SaveStream(self
.rtc
.GetBuffer(), stream
):
231 dlg
= wx
.Dialog(self
, title
="HTML", style
=wx
.DEFAULT_DIALOG_STYLE|wx
.RESIZE_BORDER
)
232 html
= wx
.html
.HtmlWindow(dlg
, size
=(500,400), style
=wx
.BORDER_SUNKEN
)
233 html
.SetPage(stream
.getvalue())
234 btn
= wx
.Button(dlg
, wx
.ID_CANCEL
)
235 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
236 sizer
.Add(html
, 1, wx
.ALL|wx
.EXPAND
, 5)
237 sizer
.Add(btn
, 0, wx
.ALL|wx
.CENTER
, 10)
243 handler
.DeleteTemporaryImages()
247 def OnFileExit(self
, evt
):
251 def OnBold(self
, evt
):
252 self
.rtc
.ApplyBoldToSelection()
254 def OnItalic(self
, evt
):
255 self
.rtc
.ApplyItalicToSelection()
257 def OnUnderline(self
, evt
):
258 self
.rtc
.ApplyUnderlineToSelection()
260 def OnAlignLeft(self
, evt
):
261 self
.rtc
.ApplyAlignmentToSelection(rt
.TEXT_ALIGNMENT_LEFT
)
263 def OnAlignRight(self
, evt
):
264 self
.rtc
.ApplyAlignmentToSelection(rt
.TEXT_ALIGNMENT_RIGHT
)
266 def OnAlignCenter(self
, evt
):
267 self
.rtc
.ApplyAlignmentToSelection(rt
.TEXT_ALIGNMENT_CENTRE
)
269 def OnIndentMore(self
, evt
):
270 attr
= rt
.RichTextAttr()
271 attr
.SetFlags(rt
.TEXT_ATTR_LEFT_INDENT
)
272 ip
= self
.rtc
.GetInsertionPoint()
273 if self
.rtc
.GetStyle(ip
, attr
):
274 r
= rt
.RichTextRange(ip
, ip
)
275 if self
.rtc
.HasSelection():
276 r
= self
.rtc
.GetSelectionRange()
278 attr
.SetLeftIndent(attr
.GetLeftIndent() + 100)
279 attr
.SetFlags(rt
.TEXT_ATTR_LEFT_INDENT
)
280 self
.rtc
.SetStyle(r
, attr
)
283 def OnIndentLess(self
, evt
):
284 attr
= rt
.RichTextAttr()
285 attr
.SetFlags(rt
.TEXT_ATTR_LEFT_INDENT
)
286 ip
= self
.rtc
.GetInsertionPoint()
287 if self
.rtc
.GetStyle(ip
, attr
):
288 r
= rt
.RichTextRange(ip
, ip
)
289 if self
.rtc
.HasSelection():
290 r
= self
.rtc
.GetSelectionRange()
292 if attr
.GetLeftIndent() >= 100:
293 attr
.SetLeftIndent(attr
.GetLeftIndent() - 100)
294 attr
.SetFlags(rt
.TEXT_ATTR_LEFT_INDENT
)
295 self
.rtc
.SetStyle(r
, attr
)
298 def OnParagraphSpacingMore(self
, evt
):
299 attr
= rt
.RichTextAttr()
300 attr
.SetFlags(rt
.TEXT_ATTR_PARA_SPACING_AFTER
)
301 ip
= self
.rtc
.GetInsertionPoint()
302 if self
.rtc
.GetStyle(ip
, attr
):
303 r
= rt
.RichTextRange(ip
, ip
)
304 if self
.rtc
.HasSelection():
305 r
= self
.rtc
.GetSelectionRange()
307 attr
.SetParagraphSpacingAfter(attr
.GetParagraphSpacingAfter() + 20);
308 attr
.SetFlags(rt
.TEXT_ATTR_PARA_SPACING_AFTER
)
309 self
.rtc
.SetStyle(r
, attr
)
312 def OnParagraphSpacingLess(self
, evt
):
313 attr
= rt
.RichTextAttr()
314 attr
.SetFlags(rt
.TEXT_ATTR_PARA_SPACING_AFTER
)
315 ip
= self
.rtc
.GetInsertionPoint()
316 if self
.rtc
.GetStyle(ip
, attr
):
317 r
= rt
.RichTextRange(ip
, ip
)
318 if self
.rtc
.HasSelection():
319 r
= self
.rtc
.GetSelectionRange()
321 if attr
.GetParagraphSpacingAfter() >= 20:
322 attr
.SetParagraphSpacingAfter(attr
.GetParagraphSpacingAfter() - 20);
323 attr
.SetFlags(rt
.TEXT_ATTR_PARA_SPACING_AFTER
)
324 self
.rtc
.SetStyle(r
, attr
)
327 def OnLineSpacingSingle(self
, evt
):
328 attr
= rt
.RichTextAttr()
329 attr
.SetFlags(rt
.TEXT_ATTR_LINE_SPACING
)
330 ip
= self
.rtc
.GetInsertionPoint()
331 if self
.rtc
.GetStyle(ip
, attr
):
332 r
= rt
.RichTextRange(ip
, ip
)
333 if self
.rtc
.HasSelection():
334 r
= self
.rtc
.GetSelectionRange()
336 attr
.SetFlags(rt
.TEXT_ATTR_LINE_SPACING
)
337 attr
.SetLineSpacing(10)
338 self
.rtc
.SetStyle(r
, attr
)
341 def OnLineSpacingHalf(self
, evt
):
342 attr
= rt
.RichTextAttr()
343 attr
.SetFlags(rt
.TEXT_ATTR_LINE_SPACING
)
344 ip
= self
.rtc
.GetInsertionPoint()
345 if self
.rtc
.GetStyle(ip
, attr
):
346 r
= rt
.RichTextRange(ip
, ip
)
347 if self
.rtc
.HasSelection():
348 r
= self
.rtc
.GetSelectionRange()
350 attr
.SetFlags(rt
.TEXT_ATTR_LINE_SPACING
)
351 attr
.SetLineSpacing(15)
352 self
.rtc
.SetStyle(r
, attr
)
355 def OnLineSpacingDouble(self
, evt
):
356 attr
= rt
.RichTextAttr()
357 attr
.SetFlags(rt
.TEXT_ATTR_LINE_SPACING
)
358 ip
= self
.rtc
.GetInsertionPoint()
359 if self
.rtc
.GetStyle(ip
, attr
):
360 r
= rt
.RichTextRange(ip
, ip
)
361 if self
.rtc
.HasSelection():
362 r
= self
.rtc
.GetSelectionRange()
364 attr
.SetFlags(rt
.TEXT_ATTR_LINE_SPACING
)
365 attr
.SetLineSpacing(20)
366 self
.rtc
.SetStyle(r
, attr
)
369 def OnFont(self
, evt
):
370 if not self
.rtc
.HasSelection():
373 r
= self
.rtc
.GetSelectionRange()
374 fontData
= wx
.FontData()
375 fontData
.EnableEffects(False)
376 attr
= rt
.RichTextAttr()
377 attr
.SetFlags(rt
.TEXT_ATTR_FONT
)
378 if self
.rtc
.GetStyle(self
.rtc
.GetInsertionPoint(), attr
):
379 fontData
.SetInitialFont(attr
.CreateFont())
381 dlg
= wx
.FontDialog(self
, fontData
)
382 if dlg
.ShowModal() == wx
.ID_OK
:
383 fontData
= dlg
.GetFontData()
384 font
= fontData
.GetChosenFont()
386 attr
.SetFlags(rt
.TEXT_ATTR_FONT
)
388 self
.rtc
.SetStyle(r
, attr
)
392 def OnColour(self
, evt
):
393 colourData
= wx
.ColourData()
394 attr
= rt
.RichTextAttr()
395 attr
.SetFlags(rt
.TEXT_ATTR_TEXT_COLOUR
)
396 if self
.rtc
.GetStyle(self
.rtc
.GetInsertionPoint(), attr
):
397 colourData
.SetColour(attr
.GetTextColour())
399 dlg
= wx
.ColourDialog(self
, colourData
)
400 if dlg
.ShowModal() == wx
.ID_OK
:
401 colourData
= dlg
.GetColourData()
402 colour
= colourData
.GetColour()
404 if not self
.rtc
.HasSelection():
405 self
.rtc
.BeginTextColour(colour
)
407 r
= self
.rtc
.GetSelectionRange()
408 attr
.SetFlags(rt
.TEXT_ATTR_TEXT_COLOUR
)
409 attr
.SetTextColour(colour
)
410 self
.rtc
.SetStyle(r
, attr
)
415 def OnUpdateBold(self
, evt
):
416 evt
.Check(self
.rtc
.IsSelectionBold())
418 def OnUpdateItalic(self
, evt
):
419 evt
.Check(self
.rtc
.IsSelectionItalics())
421 def OnUpdateUnderline(self
, evt
):
422 evt
.Check(self
.rtc
.IsSelectionUnderlined())
424 def OnUpdateAlignLeft(self
, evt
):
425 evt
.Check(self
.rtc
.IsSelectionAligned(rt
.TEXT_ALIGNMENT_LEFT
))
427 def OnUpdateAlignCenter(self
, evt
):
428 evt
.Check(self
.rtc
.IsSelectionAligned(rt
.TEXT_ALIGNMENT_CENTRE
))
430 def OnUpdateAlignRight(self
, evt
):
431 evt
.Check(self
.rtc
.IsSelectionAligned(rt
.TEXT_ALIGNMENT_RIGHT
))
434 def ForwardEvent(self
, evt
):
435 # The RichTextCtrl can handle menu and update events for undo,
436 # redo, cut, copy, paste, delete, and select all, so just
437 # forward the event to it.
438 self
.rtc
.ProcessEvent(evt
)
441 def MakeMenuBar(self
):
442 def doBind(item
, handler
, updateUI
=None):
443 self
.Bind(wx
.EVT_MENU
, handler
, item
)
444 if updateUI
is not None:
445 self
.Bind(wx
.EVT_UPDATE_UI
, updateUI
, item
)
448 doBind( fileMenu
.Append(-1, "&Open\tCtrl+O", "Open a file"),
450 doBind( fileMenu
.Append(-1, "&Save\tCtrl+S", "Save a file"),
452 doBind( fileMenu
.Append(-1, "&Save As...\tF12", "Save to a new file"),
454 fileMenu
.AppendSeparator()
455 doBind( fileMenu
.Append(-1, "&View as HTML", "View HTML"),
457 fileMenu
.AppendSeparator()
458 doBind( fileMenu
.Append(-1, "E&xit\tCtrl+Q", "Quit this program"),
462 doBind( editMenu
.Append(wx
.ID_UNDO
, "&Undo\tCtrl+Z"),
463 self
.ForwardEvent
, self
.ForwardEvent
)
464 doBind( editMenu
.Append(wx
.ID_REDO
, "&Redo\tCtrl+Y"),
465 self
.ForwardEvent
, self
.ForwardEvent
)
466 editMenu
.AppendSeparator()
467 doBind( editMenu
.Append(wx
.ID_CUT
, "Cu&t\tCtrl+X"),
468 self
.ForwardEvent
, self
.ForwardEvent
)
469 doBind( editMenu
.Append(wx
.ID_COPY
, "&Copy\tCtrl+C"),
470 self
.ForwardEvent
, self
.ForwardEvent
)
471 doBind( editMenu
.Append(wx
.ID_PASTE
, "&Paste\tCtrl+V"),
472 self
.ForwardEvent
, self
.ForwardEvent
)
473 doBind( editMenu
.Append(wx
.ID_CLEAR
, "&Delete\tDel"),
474 self
.ForwardEvent
, self
.ForwardEvent
)
475 editMenu
.AppendSeparator()
476 doBind( editMenu
.Append(wx
.ID_SELECTALL
, "Select A&ll\tCtrl+A"),
477 self
.ForwardEvent
, self
.ForwardEvent
)
479 #doBind( editMenu.AppendSeparator(), )
480 #doBind( editMenu.Append(-1, "&Find...\tCtrl+F"), )
481 #doBind( editMenu.Append(-1, "&Replace...\tCtrl+R"), )
483 formatMenu
= wx
.Menu()
484 doBind( formatMenu
.AppendCheckItem(-1, "&Bold\tCtrl+B"),
485 self
.OnBold
, self
.OnUpdateBold
)
486 doBind( formatMenu
.AppendCheckItem(-1, "&Italic\tCtrl+I"),
487 self
.OnItalic
, self
.OnUpdateItalic
)
488 doBind( formatMenu
.AppendCheckItem(-1, "&Underline\tCtrl+U"),
489 self
.OnUnderline
, self
.OnUpdateUnderline
)
490 formatMenu
.AppendSeparator()
491 doBind( formatMenu
.AppendCheckItem(-1, "L&eft Align"),
492 self
.OnAlignLeft
, self
.OnUpdateAlignLeft
)
493 doBind( formatMenu
.AppendCheckItem(-1, "&Centre"),
494 self
.OnAlignCenter
, self
.OnUpdateAlignCenter
)
495 doBind( formatMenu
.AppendCheckItem(-1, "&Right Align"),
496 self
.OnAlignRight
, self
.OnUpdateAlignRight
)
497 formatMenu
.AppendSeparator()
498 doBind( formatMenu
.Append(-1, "Indent &More"), self
.OnIndentMore
)
499 doBind( formatMenu
.Append(-1, "Indent &Less"), self
.OnIndentLess
)
500 formatMenu
.AppendSeparator()
501 doBind( formatMenu
.Append(-1, "Increase Paragraph &Spacing"), self
.OnParagraphSpacingMore
)
502 doBind( formatMenu
.Append(-1, "Decrease &Paragraph Spacing"), self
.OnParagraphSpacingLess
)
503 formatMenu
.AppendSeparator()
504 doBind( formatMenu
.Append(-1, "Normal Line Spacing"), self
.OnLineSpacingSingle
)
505 doBind( formatMenu
.Append(-1, "1.5 Line Spacing"), self
.OnLineSpacingHalf
)
506 doBind( formatMenu
.Append(-1, "Double Line Spacing"), self
.OnLineSpacingDouble
)
507 formatMenu
.AppendSeparator()
508 doBind( formatMenu
.Append(-1, "&Font..."), self
.OnFont
)
511 mb
.Append(fileMenu
, "&File")
512 mb
.Append(editMenu
, "&Edit")
513 mb
.Append(formatMenu
, "F&ormat")
517 def MakeToolBar(self
):
518 def doBind(item
, handler
, updateUI
=None):
519 self
.Bind(wx
.EVT_TOOL
, handler
, item
)
520 if updateUI
is not None:
521 self
.Bind(wx
.EVT_UPDATE_UI
, updateUI
, item
)
523 tbar
= self
.CreateToolBar()
524 doBind( tbar
.AddTool(-1, images
.get_rt_openBitmap(),
525 shortHelpString
="Open"), self
.OnFileOpen
)
526 doBind( tbar
.AddTool(-1, images
.get_rt_saveBitmap(),
527 shortHelpString
="Save"), self
.OnFileSave
)
529 doBind( tbar
.AddTool(wx
.ID_CUT
, images
.get_rt_cutBitmap(),
530 shortHelpString
="Cut"), self
.ForwardEvent
, self
.ForwardEvent
)
531 doBind( tbar
.AddTool(wx
.ID_COPY
, images
.get_rt_copyBitmap(),
532 shortHelpString
="Copy"), self
.ForwardEvent
, self
.ForwardEvent
)
533 doBind( tbar
.AddTool(wx
.ID_PASTE
, images
.get_rt_pasteBitmap(),
534 shortHelpString
="Paste"), self
.ForwardEvent
, self
.ForwardEvent
)
536 doBind( tbar
.AddTool(wx
.ID_UNDO
, images
.get_rt_undoBitmap(),
537 shortHelpString
="Undo"), self
.ForwardEvent
, self
.ForwardEvent
)
538 doBind( tbar
.AddTool(wx
.ID_REDO
, images
.get_rt_redoBitmap(),
539 shortHelpString
="Redo"), self
.ForwardEvent
, self
.ForwardEvent
)
541 doBind( tbar
.AddTool(-1, images
.get_rt_boldBitmap(), isToggle
=True,
542 shortHelpString
="Bold"), self
.OnBold
, self
.OnUpdateBold
)
543 doBind( tbar
.AddTool(-1, images
.get_rt_italicBitmap(), isToggle
=True,
544 shortHelpString
="Italic"), self
.OnItalic
, self
.OnUpdateItalic
)
545 doBind( tbar
.AddTool(-1, images
.get_rt_underlineBitmap(), isToggle
=True,
546 shortHelpString
="Underline"), self
.OnUnderline
, self
.OnUpdateUnderline
)
548 doBind( tbar
.AddTool(-1, images
.get_rt_alignleftBitmap(), isToggle
=True,
549 shortHelpString
="Align Left"), self
.OnAlignLeft
, self
.OnUpdateAlignLeft
)
550 doBind( tbar
.AddTool(-1, images
.get_rt_centreBitmap(), isToggle
=True,
551 shortHelpString
="Center"), self
.OnAlignCenter
, self
.OnUpdateAlignCenter
)
552 doBind( tbar
.AddTool(-1, images
.get_rt_alignrightBitmap(), isToggle
=True,
553 shortHelpString
="Align Right"), self
.OnAlignRight
, self
.OnUpdateAlignRight
)
555 doBind( tbar
.AddTool(-1, images
.get_rt_indentlessBitmap(),
556 shortHelpString
="Indent Less"), self
.OnIndentLess
)
557 doBind( tbar
.AddTool(-1, images
.get_rt_indentmoreBitmap(),
558 shortHelpString
="Indent More"), self
.OnIndentMore
)
560 doBind( tbar
.AddTool(-1, images
.get_rt_fontBitmap(),
561 shortHelpString
="Font"), self
.OnFont
)
562 doBind( tbar
.AddTool(-1, images
.get_rt_colourBitmap(),
563 shortHelpString
="Font Colour"), self
.OnColour
)
569 #----------------------------------------------------------------------
572 class TestPanel(wx
.Panel
):
573 def __init__(self
, parent
, log
):
575 wx
.Panel
.__init
__(self
, parent
, -1)
577 b
= wx
.Button(self
, -1, "Show the RichTextCtrl sample", (50,50))
578 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
580 self
.AddRTCHandlers()
583 def AddRTCHandlers(self
):
584 # make sure we haven't already added them.
585 if rt
.RichTextBuffer
.FindHandlerByType(rt
.RICHTEXT_TYPE_HTML
) is not None:
588 # This would normally go in your app's OnInit method. I'm
589 # not sure why these file handlers are not loaded by
590 # default by the C++ richtext code, I guess it's so you
591 # can change the name or extension if you wanted...
592 rt
.RichTextBuffer
.AddHandler(rt
.RichTextHTMLHandler())
593 rt
.RichTextBuffer
.AddHandler(rt
.RichTextXMLHandler())
596 rt
.RichTextBuffer
.AddHandler(rt
.RichTextXMLHandler(name
="Other XML",
600 # This is needed for the view as HTML option since we tell it
601 # to store the images in the memory file system.
602 wx
.FileSystem
.AddHandler(wx
.MemoryFSHandler())
605 def OnButton(self
, evt
):
606 win
= RichTextFrame(self
, -1, "wx.richtext.RichTextCtrl",
608 style
= wx
.DEFAULT_FRAME_STYLE
)
611 # give easy access to the demo's PyShell if it's running
617 #----------------------------------------------------------------------
619 def runTest(frame
, nb
, log
):
620 win
= TestPanel(nb
, log
)
623 #----------------------------------------------------------------------
627 overview
= """<html><body>
628 <h2><center>wx.richtext.RichTextCtrl</center></h2>
635 if __name__
== '__main__':
638 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])