unwanted automatic over scrolling in TextCtrl on windows

47 views
Skip to first unread message

raf

unread,
Aug 13, 2009, 3:48:04 AM8/13/09
to wxpytho...@groups.google.com
hi,

wxpython-2.8.10.1-unicode
python-2.6.2
windows-xp and windows-2000

i have a TextCtrl with:

style = TE_MULTILINE | TE_READONLY | TE_RICH

and i append text to it with:

def msg(self, msg='', colour=BLACK, nl=true):
self.mainframe.text_ctrl.SetDefaultStyle(TextAttr(colour))
self.mainframe.text_ctrl.AppendText(msg + ('\n' if nl else ''))
self.mainframe.text_ctrl.SetDefaultStyle(TextAttr(BLACK))
self.mainframe.text_ctrl.Update()

on macosx, the text that is appended to the control is always visible
when it is appended but on windows, it regularly scrolls up past the
top of the view and so becomes invisible as soon as it is appended
and the user has to scroll up in order to see the new text.

if i change TE_RICH to TE_RICH2, this behaviour stays the same.

if i remove TE_RICH altogether, this behaviour is fixed but the
colours no longer work and i really need the colours as well.

i couldn't see anything in the documentation that would allow me
to do any programmatic scrolling to put the text where it can
be seen.

it seems that when it sees that it needs to scroll in order to
place the next message, it scrolls up by one page plus one line
rather than just scrolling up one line. even scrolling up by
one page minus one line would be a great improvement.

does anyone know any solutions to this?

i've attached a demonstration program. click the button until
the textctrl fills up, click again and all the text disappears
from view but if you scroll up manually, it's there.

cheers,
raf

p.s. if you ask me for further information please be patient.
google doesn't send me these list messages even though i'm
subscribed so i won't see any list replies until i get around
to searching for them on the web. a solution for that (that doesn't
require creating a google account) would be nice too :)

unwanted_automatic_over_scrolling_in_textctrl_on_windows.py

Robin Dunn

unread,
Aug 13, 2009, 12:02:30 PM8/13/09
to wxPytho...@googlegroups.com
raf wrote:
> does anyone know any solutions to this?
>

In the past I've worked around this issue by replacing AppendText with a
method that gets the current value, adds the new text to it, replaces
the whole value of the textctrl and then sets the insertion point to the
end. However since you are using colors that won't work...
Unfortunately I can't think of any other workarounds to try unless the
text will be read-only, then making a custom widget derived from
wx.ScrolledWindow would be fairly simple to do.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Vlastimil Brom

unread,
Aug 13, 2009, 1:09:27 PM8/13/09
to wxPytho...@googlegroups.com, wxpytho...@groups.google.com
2009/8/13 raf <r...@raf.org>:
> hi,
...

> i have a TextCtrl with:
>
>  style = TE_MULTILINE | TE_READONLY | TE_RICH
>
> and i append text to it with:
>
>  def msg(self, msg='', colour=BLACK, nl=true):
>    self.mainframe.text_ctrl.SetDefaultStyle(TextAttr(colour))
>    self.mainframe.text_ctrl.AppendText(msg + ('\n' if nl else ''))
>    self.mainframe.text_ctrl.SetDefaultStyle(TextAttr(BLACK))
>    self.mainframe.text_ctrl.Update()
>
> on macosx, the text that is appended to the control is always visible
> when it is appended but on windows, it regularly scrolls up past the
> top of the view and so becomes invisible as soon as it is appended
> and the user has to scroll up in order to see the new text.
...

> does anyone know any solutions to this?
>
> i've attached a demonstration program. click the button until
> the textctrl fills up, click again and all the text disappears
> from view but if you scroll up manually, it's there.
>
> cheers,
> raf
>
...

Hi,
does something like:
self.mainframe.text_ctrl.ShowPosition(self.mainframe.text_ctrl.GetLastPosition()-1)

(after the AppendText and SetDefaultStyle calls) work in your case?
For me it almost seems to, normally by clicking the append button, not
allways if there is some interfering manual scrolling.
(if I repeat the above line twice, it seems to work in all cases; call
it voodoo or cargo cult programming :-)

Alternatively, if it is an option, there is a richtext.RichTextCtrl
and stc.StyledTextCtrl with similar functionality, which might not
have this issue.

hth,
vbr

Reply all
Reply to author
Forward
0 new messages