text logging widget?

Don Dwiggins wrote:

Take a look at the logging window at the bottom of the wx demo app...

I'm doing virtually the same thing but I too have
unsatisfactory behavior of the TextCtrl; I write a lot of
stuff to it (it's a log for a build process), and the text
frequently disappears altogether, and the location to which
the window scrolls seems fairly arbitrary.

Sounds similar to but not entirely the same as the problems I
see.

I'm thinking I may need to periodically reset the cursor
position or something, but started working on something else
for the time being.

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.

That's interesting to be sure, although I'm just hooking the
build's stdout and stderr (each to a different log window) so
I'd just like to get a Plain Ol' Box Which Displays Text. :slight_smile:

Me too. I'm surprised there isn't one included along with the
batteries...

···

On 2006-12-08, Tom Plunket <python@fancy.org> wrote:

--
Grant Edwards grante Yow! Is a tattoo
                                  at real, like a curb or a
                               visi.com battleship? Or are we
                                                   suffering in Safeway?

Josiah Carlson 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.

It wasn't immediately apparent how I can manually control the scroll
position. Is there a way? The old behavior (prior to the addition of
Freeze/Thaw) was that the scroll position would end up beyond the end of
the text.

In some cases I'm appending a lot of text; it is catching stdout from
other processes, and some of those processes buffer their output (grr!),
so when they end, WHAM I get several Kb of text.

thx,
-tom!

···

Grant Edwards <grante@visi.com> wrote:

--

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

···

Tom Plunket <python@fancy.org> wrote:

Josiah Carlson wrote:

> Grant Edwards <grante@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.