Forcing the position of scroll bars on a wxTextCtrl

Clans Of Intrigue clansofintrigue at gmail.com
Wed Nov 2 11:47:12 EST 2005


Hello, this is my first post here so apologies if it's in the wrong
place, inappropriate or embarrassingly stupid - please let me know :)

My problem seems quite simple - I've redirected stdout to a wxTextCtrl,
so that any trace messages appear in a log window at the bottom of my
app.  The problem is that whenever I update the text, the scrollbar
resets to the top - i.e. to the earliest log message.  What I really
want it to do is reset to the bottom, so that the most recent log
messages are on screen.

Calling SetScrollPos( GetScrollRange() ) sets the scrollbar slider to
the correct position, but *doesn't update the text in the window* :(

Is there a call to tell it to update the visible text based on the new
slider position?  Or is there a better way to update the slider
position, e.g. by sending the control an event?

I'm new to wxWindows and new to Python, so any help (and as much
detail!) as possible would be appreciated!  Here's the class I'm using
to capture stdout:

class LogControl:
    """ Simple helper to redirect stdout to a panel in the GUI """
    def __init__( self, textCtrl ):
        self._ctrl = textCtrl
        self._log = ""
        self.write( "Application Started...\n" )

    def write( self, Message ):
        self._log = self._log + Message
        self._ctrl.SetValue( self._log )
        # Force scroll bars to end of window - does not update text in
control!
        self._ctrl.SetScrollPos( wx.VERTICAL,
self._ctrl.GetScrollRange( wx.VERTICAL) )

Thanks!




More information about the Python-list mailing list