Hi everyone:
I've been trying to use the Clear() method of wx.richtext.RichTextCtrl
[2.8.10.1 (msw-unicode)], but it doesn't seem to remove all formatting
from the text. The following code example summarizes my confusion
(click through the buttons in the order they're numbered to see what I
mean):
import wx
import wx.richtext
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
self.hsizer = wx.BoxSizer(wx.HORIZONTAL)
self.control = wx.richtext.RichTextCtrl(self, wx.NewId(),
style=wx.TE_MULTILINE)
self.vsizer = wx.BoxSizer(wx.VERTICAL)
self.selectAll = wx.Button(self, wx.NewId(), '1. Select All')
self.bold = wx.Button(self, wx.NewId(), '2. Bold Selection')
self.clear = wx.Button(self, wx.NewId(), '3. Clear')
self.writeSomeTextThatShouldNotBeBold = wx.Button(self,
wx.NewId(), '4. Write some text that\nshould not be bold\nbut is for
some reason')
self.hsizer.Add(self.control, 1, wx.EXPAND)
self.vsizer.Add(self.selectAll, 0)
self.vsizer.Add(self.bold, 0)
self.vsizer.Add(self.clear, 0)
self.vsizer.Add(self.writeSomeTextThatShouldNotBeBold, 0)
self.hsizer.Add(self.vsizer, 0)
self.SetSizer(self.hsizer)
self.SetAutoLayout(True)
self.hsizer.Fit(self)
self.Bind(wx.EVT_BUTTON, self.OnBold, self.bold)
self.Bind(wx.EVT_BUTTON,
self.WriteSomeTextThatShouldNotBeBold,
self.writeSomeTextThatShouldNotBeBold)
self.Bind(wx.EVT_BUTTON, self.OnClear, self.clear)
self.Bind(wx.EVT_BUTTON, self.OnSelectAll, self.selectAll)
self.Show(True)
self.WriteSomeBoldText()
def OnSelectAll(self, e):
self.control.SelectAll()
def OnBold(self, e):
self.control.ApplyBoldToSelection()
def OnClear(self, e):
self.control.Clear()
def WriteSomeBoldText(self):
self.control.BeginSuppressUndo()
self.control.BeginBold()
self.control.WriteText("0. This wx.richtext.RichTextCtrl has
been preloaded with bold text.")
self.control.EndBold()
self.control.EndSuppressUndo()
def WriteSomeTextThatShouldNotBeBold(self, e):
self.control.BeginSuppressUndo()
self.control.WriteText("This text should not be bold.")
self.control.EndSuppressUndo()
app = wx.PySimpleApp()
frame = MainWindow(None, wx.ID_ANY, 'Weird Behavior Example')
app.MainLoop()
Is this a bug, or is the Clear() method not the one I'm looking for?
Sincerely,
Saketh