Bug in wx.richtext.RichTextCtrl

I’ve encountered an issue with the RichTextCtrl. The problem is that the Enter key switches focus instead of inserting a newline. Here is a bit of code that produces the bug on Windows. To see it, focus on the RichTextCtrl and hit enter.

import wx
import wx.richtext

class MyFrame(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, title, wx.DefaultPosition, wx.Size(320, 350))

    panel = wx.Panel(self, -1)
    wx.richtext.RichTextCtrl(panel, -1, pos=(0, 0), size=(100, 100))
    wx.TreeCtrl(panel, -1, (200, 200)).AddRoot("asdfl")
    self.Centre()

class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, ‘test’)
frame.Show(True)
self.SetTopWindow(frame)
return True

app = MyApp(0)
app.MainLoop()

At least, I think it’s a bug. It might be expected functionality, because I’m not very experienced with rich text widgets.

test.py (618 Bytes)

Saketh wrote:

I've encountered an issue with the RichTextCtrl. The problem is that the Enter key switches focus instead of inserting a newline. Here is a bit of code that produces the bug on Windows. To see it, focus on the RichTextCtrl and hit enter.

Turn off the wx.TAB_TRAVERSAL style of the panel by passing style=0 to its constructor.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I have two panels within a Splitter in my application. Should I change
the style parameter in both of their construction calls to zero? I
tried that, and it doesn't seem to change the situation.

···

On 6/18/07, Robin Dunn <robin@alldunn.com> wrote:

Saketh wrote:
> I've encountered an issue with the RichTextCtrl. The problem is that the
> Enter key switches focus instead of inserting a newline. Here is a bit
> of code that produces the bug on Windows. To see it, focus on the
> RichTextCtrl and hit enter.

Turn off the wx.TAB_TRAVERSAL style of the panel by passing style=0 to
its constructor.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Saketh wrote:

···

On 6/18/07, Robin Dunn <robin@alldunn.com> wrote:

Saketh wrote:
> I've encountered an issue with the RichTextCtrl. The problem is that the
> Enter key switches focus instead of inserting a newline. Here is a bit
> of code that produces the bug on Windows. To see it, focus on the
> RichTextCtrl and hit enter.

Turn off the wx.TAB_TRAVERSAL style of the panel by passing style=0 to
its constructor.

I have two panels within a Splitter in my application. Should I change
the style parameter in both of their construction calls to zero? I
tried that, and it doesn't seem to change the situation.

The splitter window is also considered a control container, so it will handle navigation keys too, but I don't think it can't be turned off. :frowning: Looks like another way to fix it is to give the richtext control a style of wx.WANTS_CHARS. This will tell the system to give it events for all the keystrokes and then its internal key event handlers will see the Enter key before it has a chance to be turned into a navigation event.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

That did the trick. wx.WANTS_CHARS fixes my problem. Thanks, Robin!