[wxPython-users] Re: text logging widget?

Josiah Carlson jcarlson at uci.edu
Thu Dec 14 11:35:22 PST 2006


Tom Plunket <python at fancy.org> wrote:
> 
> Josiah Carlson wrote:
> 
> > Grant Edwards <grante at visi.com> wrote:
> > > Yea, I finally broke down and forced the cursor to the end each
> > > time after adding any text.  That helps, but it causes a lot of
> > > "flashing" and doesn't completely fix things.
> > 
> > The following should work, and limit flashing...
> > 
> > tc.Freeze()
> > tc.AppendText(text)
> > tc.Thaw()
> 
> This helps my flashing (or rather, "completely disappearing text"), but
> not the scroll position.
> 
> > If not, toss in a tc.SetInsertionPointEnd() call before the Thaw.
> 
> This keeps the scroll position at the top of the window, for some
> reason.  The cursor is at the end of the buffer, but the window won't
> scroll.

Digging into this further, the following seems to work for me in Python
2.3 and wxPython 2.6.3 on Windows....


    self.SetInsertionPointEnd()
    self.WriteText(text)

    linecount = self.GetNumberOfLines()
    lp = lastpos = self.GetLastPosition()
    for i in xrange(min(2, linecount)):
        linecount -= 1
        lastpos -= self.GetLineLength(linecount)
    self.ShowPosition(lastpos + (lp != lastpos and
                     bool(self.GetLineLength(linecount))))

In my case, my output tends to carry an extra newline, so what I really
want to see is somewhere around the second to last line.  The crap
inside the .ShowPosition call is just to make sure we are not trying to
view a newline.

Note that if you get a bunch of text at once, it will probably jump to
view the last two lines.  Also, if you aren't getting scrollbars, you
may need to force a size event just after the text control is first
created.

 - Josiah





More information about the wxpython-users mailing list