How to get the caret position within the wx.TextCtrl?
vronskij
vronskij at gmail.com
Mon Jan 1 14:04:34 PST 2007
Hi,
I would like to get the current position of the caret within the wx.TextCtr=
l.
I want to display a window near that caret, so I need to get it's position.
Preferably the position on the whole screen.
There is a GetCaret() method in wx.Window base class and the caret has a
GetPosition() method which is probably the way to go. But the GetCaret()
method returns None in my example.
Am I missing something? How do I accomplish this?
I tried several workerounds. To no effect.
I am running Linux and wxPython 2.6.3.3
#!/usr/bin/python
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=3D(450, 400))
self.tc =3D wx.TextCtrl(self, -1, style=3Dwx.TE_MULTILINE)
self.tc.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.tc.SetFocus()
#print dir(self.tc.GetCursor())
#print self.tc.GetCursor().thisown
#print self.tc.GetCursor()
self.Centre()
print self.tc.GetCaret() # returns None
self.Show(True)
def OnKeyDown(self, event):
keycode =3D event.GetKeyCode()
if keycode =3D=3D wx.WXK_SPACE:
#print dir(event)
#print event.GetX.__doc__
#print event.GetPositionTuple()
#print self.tc.GetLastPosition()
#(x, y) =3D self.tc.PositionToXY(self.tc.GetLastPosition())
#x, y =3D event.GetPositionTuple()
#print event.m_x, event.m_y
event.Skip()
app =3D wx.App(0)
MyFrame(None, -1, 'Get Caret Position')
app.MainLoop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200701=
01/a9da684b/attachment.htm
More information about the wxpython-users
mailing list