Forcing the position of scroll bars on a wxTextCtrl

Magnus Lycka lycka at
Thu Nov 3 14:49:53 CET 2005

Clans Of Intrigue wrote:
> Thanks, that did the trick perfectly :)
> also got rid of the self._log member so the class is now just:
> class LogControl:
>     """ Simple helper to redirect stdout to a panel in the GUI """
>     def __init__( self, textCtrl ):
>         self._ctrl = textCtrl
>         self.write( "Application Started..." )
>     def write( self, Message ):
>         # Add message to log and force scroll bars to end of window
>         self._ctrl.SetValue( self._ctrl.GetValue() + Message )
>         self._ctrl.ShowPosition(self._ctrl.GetLastPosition())

But if you have 100kB text in the control, and add another 1kB log
message, it certainly seems suboptimal to use:
self._ctrl.SetValue( self._ctrl.GetValue() + Message )
Here, you first copy all the text in the control to a Python
string, build a new string with old+new text, and replace the old
text with the context of this bigger string. You should simply use
self._ctrl.AppendText( Message ). I'm not sure exactly what happens
under he hood, but I suspect that's more efficient, besides being
prettier in the source...

    Thou shalt study thy libraries and strive not to reinvent them
    without cause, that thy code may be short and readable and thy
    days pleasant and productive.


More information about the Python-list mailing list