I am using a wx.TextCtrl to output text from a network daemon.
As the output is quite verbose, the size of text in the TextCtrl can become huge (BTW is there any limitation on the size of the contents of a TextCtrl?)
I would like to delete the top N lines from the TextCtrl when TextCtrl.GetNumberOfLines() exceeds a predefined treshold.
What is the best way to accomplish this?
views:
308answers:
3
A:
How about the Remove method of wx.TextCtrl?
Whenever you're about to add new text, you can check if the current text appears too long and remove some from the start.
Eli Bendersky
2009-01-16 12:43:31
A:
The SetMaxLength reference says that the limitation depends on the underlying native text control,but should be 32KB at least.
About deleting the top N lines, you could try to call GetLineLength for 0..N-1, calculate the sum S and then call Remove(0,S)
schnaader
2009-01-16 12:44:11
Thanks. This is what I came up with:def deleteLines(self, numLines): size = 0 for i in range(numLines): self.outputdevice.Remove(0, self.outputdevice.GetLineLength(0))
KornP
2009-01-16 13:43:32
Yes, this looks good, removes the need of sum calculating.
schnaader
2009-01-16 13:48:05
I'd compare the performance of calling N times GetLineLength() and 1 time Remove() vs calling N times Remove *and* N times GetLineLength(). Just for the reference.
Abgan
2009-01-16 22:49:40
A:
Remove() should do the trick.
TextCtrl without wx.TE_RICH flag can't have more than 64 KB on Windows.
Abgan
2009-01-16 12:46:25