Kurt Pattyn
Kurt Pattyn

Reputation: 2788

Deleting lines from wx.TextCtrl

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?

Upvotes: 3

Views: 4059

Answers (4)

Craig McQueen
Craig McQueen

Reputation: 43436

You should be able to use wx.TextCtrl.PositionToXY() and wx.TextCtrl.XYToPosition() to convert position (measured in characters from start) to and from a (column, line_num) pair.

So, you can use i = wx.TextCtrl.XYToPosition(0, n) to get the position i of a particular line n (or n+1, depending on how you count them 0- or 1-based), then call wx.TextCtrl.Remove(0, i) to remove the first n lines.

Upvotes: 0

Abgan
Abgan

Reputation: 3716

Remove() should do the trick.

TextCtrl without wx.TE_RICH flag can't have more than 64 KB on Windows.

Upvotes: 0

schnaader
schnaader

Reputation: 49719

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)

Upvotes: 1

Eli Bendersky
Eli Bendersky

Reputation: 273426

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.

Upvotes: 0

Related Questions