···
Thanks, it did the trick. However, I think this behaviour is not the behaviour a user is expecting to have and there is a pending design mistake here. Having to handle the tab key because it is used for text editing and for keyboard navigation is normal. This should not be the case for the cr key at least in a text widget. The behaviour is correct in a TextCtrl, incorrect in a RichText. Below, a small test application for those who wish to toy and check the difference between a TextCtrl widget and a RichText widget.
Jean-Michel Fauth, Switzerland
import wx
import wx.richtext
#-------------------------------------------------------------------
class MyRichTextCtrl(wx.richtext.RichTextCtrl):
def __init__(self, parent, id, value, pos, size, style):
wx.richtext.RichTextCtrl.__init__(self, parent, id, value, pos, size, style)
#-------------------------------------------------------------------
class MyTextCtrl(wx.TextCtrl):
def __init__(self, parent, id, value, pos, size, style):
wx.TextCtrl.__init__(self, parent, id, value, pos, size, style)
#-------------------------------------------------------------------
class MyPanel(wx.Panel):
def __init__(self, parent):
##############
#~ wx.Panel.__init__(self, parent, wx.ID_ANY, style=0)
wx.Panel.__init__(self, parent, wx.ID_ANY)
###############
self.parent = parent
b1 = wx.Button(self, wx.ID_ANY, 'but1')
b2 = wx.Button(self, wx.ID_ANY, 'but2')
b3 = wx.Button(self, wx.ID_ANY, 'but3')
b4 = wx.Button(self, wx.ID_ANY, 'but4')
b5 = wx.Button(self, wx.ID_ANY, 'but5')
b1.Bind(wx.EVT_BUTTON, self.OnClick1)
b2.Bind(wx.EVT_BUTTON, self.OnClick2)
b3.Bind(wx.EVT_BUTTON, self.OnClick3)
b4.Bind(wx.EVT_BUTTON, self.OnClick4)
b5.Bind(wx.EVT_BUTTON, self.OnClick5)
##############
sty = wx.richtext.RE_MULTILINE | wx.VSCROLL | wx.HSCROLL | wx.NO_BORDER
[self.tc](http://self.tc) = MyRichTextCtrl(self, wx.ID_ANY, '', wx.DefaultPosition, wx.DefaultSize, style=sty)
#~ sty = wx.TE_MULTILINE | wx.NO_BORDER
#~ [self.tc](http://self.tc) = MyTextCtrl(self, wx.ID_ANY, '', wx.DefaultPosition, wx.DefaultSize, style=sty)
##############
sizer1 = wx.BoxSizer(wx.VERTICAL)
b = 8
sizer1.Add(b1, 0, wx.GROW, b)
sizer1.Add(b2, 0, wx.GROW | wx.TOP, b)
sizer1.Add(b3, 0, wx.GROW | wx.TOP, b)
sizer1.Add(b4, 0, wx.GROW | wx.TOP, b)
sizer1.Add(b5, 0, wx.GROW | wx.TOP, b)
sizer2 = wx.BoxSizer(wx.VERTICAL)
b = 0
sizer2.Add([self.tc](http://self.tc), 1, wx.EXPAND, b)
sizer3 = wx.BoxSizer(wx.HORIZONTAL)
b = 10
sizer3.Add(sizer2, 1, wx.EXPAND | wx.ALL, b)
sizer3.Add(sizer1, 0, wx.ALL, b)
self.SetSizer(sizer3)
self.parent.SetClientSize((500, 300))
self.parent.CentreOnScreen()
self.tc.SetFocus()
def OnClick1(self, event):
print 'OnClick1'
def OnClick2(self, event):
print 'OnClick2'
def OnClick3(self, event):
print 'OnClick3'
def OnClick4(self, event):
print 'OnClick4'
def OnClick5(self, event):
print 'OnClick5'
#-------------------------------------------------------------------
class MyFrame(wx.Frame):
def __init__(self, parent, id):
sty = wx.DEFAULT_FRAME_STYLE
s = __file__
wx.Frame.__init__(self, parent, id, s, (0, 0), wx.DefaultSize, sty)
self.panel = MyPanel(self)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
#-------------------------------------------------------------------
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, wx.ID_ANY)
frame.Show(True)
self.SetTopWindow(frame)
return True
#-------------------------------------------------------------------
def main():
app = MyApp(False)
app.MainLoop()
#-------------------------------------------------------------------
if name == “main” :
main()
#eof-------------------------------------------------------------------