boldface bug in wx.richtext.RichTextCtrl?

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

Saketh wrote:

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):

[...]

Is this a bug, or is the Clear() method not the one I'm looking for?

Seems to be working ok for me, the text inserted with button #4 is not bold.

···

--
Robin Dunn
Software Craftsman

That's odd, since I'm having this issue on both Windows and Ubuntu.

Robin, what is your setup? I would like to imitate it, in order to
circumvent this issue.

···

On Aug 13, 2:46 am, Robin Dunn <ro...@alldunn.com> wrote:

Saketh wrote:
> 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):

[...]

> Is this a bug, or is the Clear() method not the one I'm looking for?

Seems to be working ok for me, the text inserted with button #4 is not bold.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Saketh wrote:

That's odd, since I'm having this issue on both Windows and Ubuntu.

Robin, what is your setup? I would like to imitate it, in order to
circumvent this issue.

I tested with 2.8.10.1 on all three platforms.

···

--
Robin Dunn
Software Craftsman

I'm really surprised because this is a self-contained program, and I'm
definitely getting this issue on 2.8.10.1 on Windows and Ubuntu (and
Python 2.6).

When you do "2. Bold selection", does it leave the preformatted text
as bold, or does it unbold it? For me, it leaves the preformatted text
as bold.

···

On Aug 13, 8:44 pm, Robin Dunn <ro...@alldunn.com> wrote:

Saketh wrote:
> That's odd, since I'm having this issue on both Windows and Ubuntu.

> Robin, what is your setup? I would like to imitate it, in order to
> circumvent this issue.

I tested with 2.8.10.1 on all three platforms.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

I'm also getting the same issue on Mac OS X 10.4, with wxPython
version mac-unicode 2.8.10.1.

···

On Aug 14, 11:28 pm, Saketh <saketh.bhamidip...@gmail.com> wrote:

I'm really surprised because this is a self-contained program, and I'm
definitely getting this issue on 2.8.10.1 on Windows and Ubuntu (and
Python 2.6).

When you do "2. Bold selection", does it leave the preformatted text
as bold, or does it unbold it? For me, it leaves the preformatted text
as bold.

On Aug 13, 8:44 pm, Robin Dunn <ro...@alldunn.com> wrote:

> Saketh wrote:
> > That's odd, since I'm having this issue on both Windows and Ubuntu.

> > Robin, what is your setup? I would like to imitate it, in order to
> > circumvent this issue.

> I tested with 2.8.10.1 on all three platforms.

> --
> Robin Dunn
> Software Craftsmanhttp://wxPython.org

Robin,

Interesting result -- it works correctly, as you said, on Python 2.5
(with wxPython 2.8.10.1) on Linux, Mac, and Windows. However, the
issue is there for Python 2.6 (also with wxPython 2.8.10.1) on Linux,
Mac, and Windows. For now, I will use Python 2.5 without any qualms,
but is this expected behavior with Python 2.6?

Sincerely,
Saketh

···

On Aug 15, 2:41 pm, Saketh <saketh.bhamidip...@gmail.com> wrote:

I'm also getting the same issue on Mac OS X 10.4, with wxPython
version mac-unicode 2.8.10.1.

On Aug 14, 11:28 pm, Saketh <saketh.bhamidip...@gmail.com> wrote:

> I'm really surprised because this is a self-contained program, and I'm
> definitely getting this issue on 2.8.10.1 on Windows and Ubuntu (and
> Python 2.6).

> When you do "2. Bold selection", does it leave the preformatted text
> as bold, or does it unbold it? For me, it leaves the preformatted text
> as bold.

> On Aug 13, 8:44 pm, Robin Dunn <ro...@alldunn.com> wrote:

> > Saketh wrote:
> > > That's odd, since I'm having this issue on both Windows and Ubuntu.

> > > Robin, what is your setup? I would like to imitate it, in order to
> > > circumvent this issue.

> > I tested with 2.8.10.1 on all three platforms.

> > --
> > Robin Dunn
> > Software Craftsmanhttp://wxPython.org

Saketh wrote:

I'm really surprised because this is a self-contained program, and I'm
definitely getting this issue on 2.8.10.1 on Windows and Ubuntu (and
Python 2.6).

When you do "2. Bold selection", does it leave the preformatted text
as bold, or does it unbold it? For me, it leaves the preformatted text
as bold.

Same here.

···

--
Robin Dunn
Software Craftsman

Saketh wrote:

Robin,

Interesting result -- it works correctly, as you said, on Python 2.5
(with wxPython 2.8.10.1) on Linux, Mac, and Windows. However, the
issue is there for Python 2.6 (also with wxPython 2.8.10.1) on Linux,
Mac, and Windows. For now, I will use Python 2.5 without any qualms,
but is this expected behavior with Python 2.6?

No.

BTW, it works correctly for me on Py2.6 also.

···

--
Robin Dunn
Software Craftsman