RichText widget, <cr> not working !?

Hi,

w2k, Py252, wxPy2881-ansi

This message should probably have been sent to a dev list (wxWidgets, wxPython). Beeing not
subscribed I submit this msg here.

Yesterday I started to have a look at the RichText widget and I got stuck after a few minutes!

It seems impossible to enter an / newline from the keyboard in this widget or in other
words it is impossible to type a multiline text.

History

As usual I wrote a small test application

Frame - Panel - Sizer - a few Buttons - RichText

ran it and tested it by typing sone text in the RichText widget. It was just impossible to
write a multiline text, the did not work. I spent some time with the doc and the demo

to see if I forgot to define a correct style, no luck.

Then came the idea to repeat the experiment with a simplified test application.

Frame - RichText

and it worked correctely.

“Technical” conclusions from an user perspective.

It seems when one lays out a RichText widget on a panel, some events are not progagated
correctly if they ever are.
I attempted to bind an EVT_KEY_DOWN to the control and noticed some key strokes are not
intercepted (enter or tab).

In the test application having buttons, I also noticed hitting an will set the focus
to one of them.
(I did not forget to toy with event.Skip())

Unless I’m doing something wrong, I’have the feeling there is an issue here.

Regards.
Jean-Michel Fauth, Switzerland

I remember there was something tricky about this. If you wanted to intercept enter key events by adding the wx.TE_PROCESS_ENTER style when you create the control, you had to insert the newline characters yourself. If you didn’t intercept them, things worked as they were supposed to. There’s a similar wx.TE_PROCESS_TAB event, but I think it works backward–if you don’t include it, the tab is passed up to the containing widget rather than having a tab inserted.

I just looked at some code I wrote a while ago and I have a handler for wx.EVT_KEY_DOWN that checks to see if the key is wx.WXK_RETURN or wx.WXK_NUMPAD_ENTER and does something special for them, but only in a shell-like editor. In my text editor, I don’t do anything special.

The styles you can pass are the same as those you can pass to a wx.TextCtrl.

Wish I could be more helpful, but hopefully that gives you someplace to start…
Todd

···

On Sat, Aug 30, 2008 at 3:57 AM, Jean-Michel Fauth wxjmfauth@gmail.com wrote:

Hi,

w2k, Py252, wxPy2881-ansi

This message should probably have been sent to a dev list (wxWidgets, wxPython). Beeing not

subscribed I submit this msg here.

Yesterday I started to have a look at the RichText widget and I got stuck after a few minutes!

It seems impossible to enter an / newline from the keyboard in this widget or in other
words it is impossible to type a multiline text.

History

As usual I wrote a small test application

Frame - Panel - Sizer - a few Buttons - RichText

ran it and tested it by typing sone text in the RichText widget. It was just impossible to
write a multiline text, the did not work. I spent some time with the doc and the demo

to see if I forgot to define a correct style, no luck.

Then came the idea to repeat the experiment with a simplified test application.

Frame - RichText

and it worked correctely.

“Technical” conclusions from an user perspective.

It seems when one lays out a RichText widget on a panel, some events are not progagated
correctly if they ever are.
I attempted to bind an EVT_KEY_DOWN to the control and noticed some key strokes are not
intercepted (enter or tab).

In the test application having buttons, I also noticed hitting an will set the focus
to one of them.
(I did not forget to toy with event.Skip())

Unless I’m doing something wrong, I’have the feeling there is an issue here.

Regards.
Jean-Michel Fauth, Switzerland


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I remember there was something tricky about this. If you wanted to intercept enter key events by adding the wx.TE_PROCESS_ENTER style when you create the control, you had to insert the newline characters yourself. If you didn’t intercept them, things worked as they were supposed to. There’s a similar wx.TE_PROCESS_TAB event, but I think it works backward–if you don’t include it, the tab is passed up to the containing widget rather than having a tab inserted.

I just looked at some code I wrote a while ago and I have a handler for wx.EVT_KEY_DOWN that checks to see if the key is wx.WXK_RETURN or wx.WXK_NUMPAD_ENTER and does something special for them, but only in a shell-like editor. In my text editor, I don’t do anything special.

The styles you can pass are the same as those you can pass to a wx.TextCtrl.

Wish I could be more helpful, but hopefully that gives you someplace to start…
Todd

Hi,

w2k, Py252, wxPy2881-ansi

This message should probably have been sent to a dev list (wxWidgets, wxPython). Beeing not

subscribed I submit this msg here.

Yesterday I started to have a look at the RichText widget and I got stuck after a few minutes!

It seems impossible to enter an / newline from the keyboard in this widget or in other
words it is impossible to type a multiline text.

History

As usual I wrote a small test application

Frame - Panel - Sizer - a few Buttons - RichText

ran it and tested it by typing sone text in the RichText widget. It was just impossible to
write a multiline text, the did not work. I spent some time with the doc and the demo

to see if I forgot to define a correct style, no luck.

Then came the idea to repeat the experiment with a simplified test application.

Frame - RichText

and it worked correctely.

“Technical” conclusions from an user perspective.

It seems when one lays out a RichText widget on a panel, some events are not progagated
correctly if they ever are.
I attempted to bind an EVT_KEY_DOWN to the control and noticed some key strokes are not
intercepted (enter or tab).

In the test application having buttons, I also noticed hitting an will set the focus
to one of them.
(I did not forget to toy with event.Skip())

Unless I’m doing something wrong, I’have the feeling there is an issue here.

Regards.
Jean-Michel Fauth, Switzerland


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

···

2008/8/30 Todd O’Bryan toddobryan@gmail.com

On Sat, Aug 30, 2008 at 3:57 AM, Jean-Michel Fauth wxjmfauth@gmail.com wrote:


Yes, I undestand what you mean and the comparaison with a wx.TextCtrl is not a bad idea, but

  • as when working with a TextCtrl I do not no want to process enter or tab keys, so I should not have to setup event handlers for this, neither I should add the appropriate style flags.

  • my RichText widget has an analogous multiline style flag, wx.richtext.RE_MULTILINE ↔ wx.TE_MULTILINE .

  • and finally, the fact that the RichText is working or not depending the frame layout (with / without a wx.Panel) seems to indicate a problem at this level.

Anyway, thanks for your reply.

Jean-Michel Fauth, Switzerland

Jean-Michel Fauth wrote:

Hi,

w2k, Py252, wxPy2881-ansi

This message should probably have been sent to a dev list (wxWidgets, wxPython). Beeing not
subscribed I submit this msg here.

Yesterday I started to have a look at the RichText widget and I got stuck after a few minutes!
It seems impossible to enter an <enter> / newline from the keyboard in this widget or in other
words it is impossible to type a multiline text.

History

As usual I wrote a small test application

Frame - Panel - Sizer - a few Buttons - RichText

ran it and tested it by typing sone text in the RichText widget. It was just impossible to
write a multiline text, the <enter> did not work. I spent some time with the doc and the demo
to see if I forgot to define a correct style, no luck.

Then came the idea to repeat the experiment with a simplified test application.

Frame - RichText

and it worked correctely.

"Technical" conclusions from an user perspective.

Since the panel is designed to handle tab traversal it takes the enter and tab keys for keyboard navigation. To turn off tab-traversal in the panel pass style=0 to the constructor.

···

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

Jean-Michel Fauth wrote:

Hi,

w2k, Py252, wxPy2881-ansi

This message should probably have been sent to a dev list (wxWidgets, wxPython). Beeing not

subscribed I submit this msg here.

Yesterday I started to have a look at the RichText widget and I got stuck after a few minutes!

It seems impossible to enter an / newline from the keyboard in this widget or in other

words it is impossible to type a multiline text.

History

As usual I wrote a small test application

Frame - Panel - Sizer - a few Buttons - RichText

ran it and tested it by typing sone text in the RichText widget. It was just impossible to

write a multiline text, the did not work. I spent some time with the doc and the demo

to see if I forgot to define a correct style, no luck.

Then came the idea to repeat the experiment with a simplified test application.

Frame - RichText

and it worked correctely.

“Technical” conclusions from an user perspective.

Since the panel is designed to handle tab traversal it takes the enter and tab keys for keyboard navigation. To turn off tab-traversal in the panel pass style=0 to the constructor.

···

2008/8/31 Robin Dunn robin@alldunn.com

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

Jean-Michel Fauth wrote:

2008/8/31 Robin Dunn <robin@alldunn.com <mailto:robin@alldunn.com>>

    Jean-Michel Fauth wrote:

        Hi,

        w2k, Py252, wxPy2881-ansi

        This message should probably have been sent to a dev list
        (wxWidgets, wxPython). Beeing not
        subscribed I submit this msg here.

        Yesterday I started to have a look at the RichText widget and I
        got stuck after a few minutes!
        It seems impossible to enter an <enter> / newline from the
        keyboard in this widget or in other
        words it is impossible to type a multiline text.

        History

        As usual I wrote a small test application

        Frame - Panel - Sizer - a few Buttons - RichText

        ran it and tested it by typing sone text in the RichText widget.
        It was just impossible to
        write a multiline text, the <enter> did not work. I spent some
        time with the doc and the demo
        to see if I forgot to define a correct style, no luck.

        Then came the idea to repeat the experiment with a simplified
        test application.

        Frame - RichText

        and it worked correctely.

        "Technical" conclusions from an user perspective.

    Since the panel is designed to handle tab traversal it takes the
    enter and tab keys for keyboard navigation. To turn off
    tab-traversal in the panel pass style=0 to the constructor.

-----

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.

If I understand correctly, it is Windows that is making the enter key behave this way, not wx.

···

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

Jean-Michel Fauth wrote:

2008/8/31 Robin Dunn <robin@alldunn.com mailto:robin@alldunn.com>

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.

If I understand correctly, it is Windows that is making the enter key behave this way, not wx.

I do not know if Windows (the OS) or the RichText wx.Windows is making the problem. If I compare the TextCtrl and the RichText behaviours, I tend to see an internal RichText problem. I toyed a little bit more and saw other problems related with the cr key/char.

Any way, I’m not subsribed to the wx-dev list and I sent blindly a message to the wx-dev list. It seems it has been lost in the web hyperspace. If you can follow up it…

···

http://lists.wxwidgets.org/pipermail/wxpython-users/2008-August/079750.html

Jean-Michel Fauth wrote:

Any way, I'm not subsribed to the wx-dev list and I sent blindly a message to the wx-dev list. It seems it has been lost in the web hyperspace. If you can follow up it...

The message will only be delivered if the sending address is subscribed to the list. (A spam reduction precaution.)

···

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