How can I fix the scroll bug when using Windows rich edit controls in wxpython?

Posted by ChrisD on Stack Overflow See other posts from Stack Overflow or by ChrisD
Published on 2010-05-16T22:59:34Z Indexed on 2010/05/16 23:00 UTC
Read the original article Hit count: 273

Filed under:
|
|
|
|

When using wx.TextCtl with the wx.TE_RICH2 option in windows, I get this strange bug with the auto-scroll when using the AppendText function. It scrolls so that all the text is above the visible area, which isn't very useful behaviour.

I tried just adding a call to ScrollLines(-1) after appending the text - which does scroll it to the correct position - but this can lead to the window flashing when it auto-scrolls. So I'm looking for another way to automatically scroll to the bottom.

So far, my solution is to bypass the AppendText functions auto-scroll and implement my own, like this:

def append_text(textctrl, text):
    before_number_of_lines = textctrl.GetNumberOfLines()

    textctrl.SetInsertionPointEnd()
    textctrl.WriteText(text)

    after_number_of_lines = textctrl.GetNumberOfLines()
    textctrl.ScrollLines(before_number_of_lines - after_number_of_lines + 1)

Is there a better way?

© Stack Overflow or respective owner

Related posts about python

Related posts about gui