Get line number with position in text ctrl

Hi everyone,
  I may miss something, but I have difficulties finding a way to get the line (or line number) from a position with a wxTextCtrl. Is there any simple way?

Thx and regards,

Nicolas

Nicolas Fleury wrote:

Hi everyone,
    I may miss something, but I have difficulties finding a way to get the line (or line number) from a position with a wxTextCtrl. Is there any simple way?

Thx and regards,

Nicolas

The best I have found is:
     startPos = max(position - 200, 0)
     endPos = min(position + 200, self.GetLastPosition())
     middlePos = position - startPos
     largeContent = self.GetRange(startPos, endPos)
     startPos = largeContent.rfind('\n', 0, middlePos) + 1
     endPos = largeContent.find('\n', middlePos)
     if endPos == -1: endPos = len(largeContent)
     line = largeContent[startPos:endPos]

Nicolas Fleury wrote:

Hi everyone,
    I may miss something, but I have difficulties finding a way to get the line (or line number) from a position with a wxTextCtrl. Is there any simple way?

col, line = textctrl.PositionToXY(pos) should do it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Nicolas Fleury wrote:

Hi everyone,
    I may miss something, but I have difficulties finding a way to get the line (or line number) from a position with a wxTextCtrl. Is there any simple way?

col, line = textctrl.PositionToXY(pos) should do it.

Doh. Thx, at the moment of my post I though XY was pixel coordinates to finally realized they were column/line, without realizing it was what I was looking for at first.

I will just need some work to get "before-wrapping" lines.

Regards,

Nicolas