drfrev
drfrev

Reputation: 35

wxpython textctrl How to find out where the text pointer is

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.

Upvotes: 1

Views: 3275

Answers (2)

GreenAsJade
GreenAsJade

Reputation: 14685

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()

Upvotes: 1

chow
chow

Reputation: 484

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...

Upvotes: 2

Related Questions