return event in richTextCtrl

Hello,

I'm going round the bend trying to figure out what's wrong with my
event binding. I want to be able to add new paragraphs in a
richtextctrl. Unfortunately, the event I've created does not produce
any result. It looks like it doesn't get triggered, since I don't see
the print statement I've placed into the event function. Would greatly
appreciate any help with it.

Thank you,
Eli

···

#######################

import wx
import wx.richtext

def create(parent):
    return topFrame(parent)

[wxID_TOPFRAME, wxID_TOPFRAMEPANEL, wxID_TOPFRAMERTC,
] = [wx.NewId() for _init_ctrls in range(3)]

class topFrame(wx.Frame):
    def _init_coll_topSizer_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.rtc, 1, border=0, flag=wx.EXPAND)

    def _init_sizers(self):
        # generated method, don't edit
        self.topSizer = wx.BoxSizer(orient=wx.VERTICAL)

        self._init_coll_topSizer_Items(self.topSizer)

        self.panel.SetSizer(self.topSizer)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_TOPFRAME, name=u'topFrame',
parent=prnt,
              pos=wx.Point(562, 289), size=wx.Size(418, 250),
              style=wx.DEFAULT_FRAME_STYLE, title=u'topFrame')
        self.SetClientSize(wx.Size(410, 216))
        self.SetToolTipString(u'topFrame')

        self.panel = wx.Panel(id=wxID_TOPFRAMEPANEL, name=u'panel',
parent=self,
              pos=wx.Point(0, 0), size=wx.Size(410, 216),
              style=wx.TAB_TRAVERSAL)
        self.panel.SetToolTipString(u'panel')

        self.rtc = wx.richtext.RichTextCtrl(id=wxID_TOPFRAMERTC,
              parent=self.panel, pos=wx.Point(0, 0), size=wx.Size(410,
216),
              style=wx.richtext.RE_MULTILINE, value=u'')
        self.rtc.SetToolTipString(u'rtc')
        self.rtc.SetLabel(u'rtc')
        self.rtc.SetName(u'rtc')
        self.rtc.Bind(wx.richtext.EVT_RICHTEXT_RETURN, self.OnReturn,
              id=wxID_TOPFRAMERTC)

        self._init_sizers()

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnReturn(self, event):
        self.richTextCtrl1.NewLine()
        print "I'm in OnReturn"
        event.Skip()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()

Eli Nazarova wrote:

I'm going round the bend trying to figure out what's wrong with my
event binding. I want to be able to add new paragraphs in a
richtextctrl. Unfortunately, the event I've created does not produce
any result. It looks like it doesn't get triggered, since I don't see
the print statement I've placed into the event function. Would greatly
appreciate any help with it.

        self.rtc = wx.richtext.RichTextCtrl(id=wxID_TOPFRAMERTC,
              parent=self.panel, pos=wx.Point(0, 0), size=wx.Size(410,
216),
              style=wx.richtext.RE_MULTILINE, value=u'')

Make that
            style=wx.WANTS_CHARS|wx.richtext.RE_MULTILINE.

Actually, RE_MULTILINE is the default for a rich edit control, so you
don't have to specify that.

        self.rtc.Bind(wx.richtext.EVT_RICHTEXT_RETURN, self.OnReturn,
              id=wxID_TOPFRAMERTC)

Make that
        self.Bind(wx.richtext.EVT_RICHTEXT_RETURN, self.OnReturn, self.rtc)

That makes it work for me.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Thank you so much, Tim! It works for me too.

Eli

···

On Jun 1, 5:20 pm, Tim Roberts <t...@probo.com> wrote:

Eli Nazarova wrote:
> I'm going round the bend trying to figure out what's wrong with my
> event binding. I want to be able to add new paragraphs in a
> richtextctrl. Unfortunately, the event I've created does not produce
> any result. It looks like it doesn't get triggered, since I don't see
> the print statement I've placed into the event function. Would greatly
> appreciate any help with it.

> self.rtc = wx.richtext.RichTextCtrl(id=wxID_TOPFRAMERTC,
> parent=self.panel, pos=wx.Point(0, 0), size=wx.Size(410,
> 216),
> style=wx.richtext.RE_MULTILINE, value=u'')

Make that
style=wx.WANTS_CHARS|wx.richtext.RE_MULTILINE.

Actually, RE_MULTILINE is the default for a rich edit control, so you
don't have to specify that.

> self.rtc.Bind(wx.richtext.EVT_RICHTEXT_RETURN, self.OnReturn,
> id=wxID_TOPFRAMERTC)

Make that
self.Bind(wx.richtext.EVT_RICHTEXT_RETURN, self.OnReturn, self.rtc)

That makes it work for me.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.