1

GetLineText is great for getting a particular line, but there is no corresponding SetLineText. If one existed, that's what I'm looking for. Since it doesn't appear to, what's the best way to handle this?

Note: I don't want to replace ALL of the text each time as I'm concerned about performance. My use case has me replacing a line (or range of lines) for every character change in another control. So a solution which has me calling SetValue is not what I'm looking for.

Software Prophets
  • 2,838
  • 3
  • 21
  • 21

1 Answers1

2

I think what you're looking for is the Replace() method:

Replace(self, from, to, value)

http://wxpython.org/docs/api/wx.TextCtrl-class.html

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • I was at that URL earlier, noticed replace and found there were no details on replace. Going elsewhere (http://docs.wxwidgets.org/2.8/wx_wxtextctrl.html#wxtextctrlreplace) and looking at the details, it speaks of character position. I suppose I could work with that, but how do I get to a specific line without scanning all the text looking for and counting '\n'? I thought XYToPosition would give me joy, but providing it with parms of (5,0), it returned back a 5 when I was expecting some much higher number representing a character position 5 lines into the text control. Further thoughts? – Software Prophets Oct 10 '12 at 16:07
  • GetSelection() should return the two values – Mike Driscoll Oct 10 '12 at 18:15
  • I appreciate your follow-up. The documentation says, "Gets the current selection span." The problem is that this is all programmatic, so there is no selection. – Software Prophets Oct 10 '12 at 18:37
  • Yeah, I know that. But I assumed you are somehow selecting a string in the textctrl, which would imply that you knew the positions of that which you were replacing. You might want to ask over on the wxPython mailing list too. And providing a small runnable example might help too. – Mike Driscoll Oct 10 '12 at 18:44
  • I was looking for the "best" way, and I guess this is probably it. I'll just have to keep track of where the \n's are then use the positions intelligently. Thanks Mike! – Software Prophets Oct 12 '12 at 12:04