1

I need to know where the text pointer (blinking line) is in the textctrl. I would also like to know if it is possible to get the entire line that the pointer is on, or if I would just have to write the code to get the current line from the pointer position.

drfrev
  • 35
  • 2
  • 7

2 Answers2

2

You can use GetInsertionPoint() to find the current position of the cursor. You can use: len( self.LogWindow.GetRange( 0, self.LogWindow.GetInsertionPoint() ).split("\n") ) to get the line number itself.

And then you can use: GetLineText() to get the entire line of text...

So:

curPos = self.LogWindow.GetInsertionPoint
lineNum = self.LogWindow.GetRange( 0, self.LogWindow.GetInsertionPoint() ).split("\n")
lineText = self.LogWindow.GetLineText(lineNum)

In thoery that should work...?

Check This Out...

chow
  • 484
  • 2
  • 8
  • 21
1

You can use PositionToXY() to find out the line number of a given insertion point, rather than hunting for or counting \ns.

lineNum = self.LogWindow.PositionToXY(curPos)[1]   # lineNum is the y coord from PosToXY()
Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
GreenAsJade
  • 14,459
  • 11
  • 63
  • 98
  • 1
    In current version as of this comment, wxPython Phoenix TextCtrl.PositionToXY() returns a (bool, x, y) so PositionToXY(curPos)[2] is appropriate. – DevPlayer Dec 21 '14 at 01:10
  • Wow - did they change that call? That seems a bit nasty? – GreenAsJade Dec 21 '14 at 08:29
  • Yeah. Althought I was using the TextCtrl, I imagine it is likely both wx.LogWindow.PositionToXY() and wx.TextCtrl.PositionToXY() are both inherited from the same place and return a triple instead of a tuple. but I haven't tested it. I'm also doing thing in Python 3.4.2 instead of Python 2.x. There is now some form of overloading used in the Phoenix package although I can't imagine that effecting the return value structure. I did not see any depreciated version (i.e. a backwards compatible) of PositionToXY() – DevPlayer Dec 21 '14 at 20:35