Hi,
I think there might be a problem with textctrl on the mac...
I have a need to be able to capture the line containing
the cursor when a <shift><return> key combo is pressed
I am using a PyValidator to watch for the shift return.
class CharValidator(wx.PyValidator):
def __init__(self,textWin):
wx.PyValidator.__init__(self)
self.Bind(wx.EVT_CHAR, self.OnChar)
self.textWin = textWin
def Clone(self):
"""
Note that every validator must implement the Clone() method.
"""
return CharValidator(self.textWin)
def Validate(self, win):
return True
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True
def OnChar(self, evt):
if (evt.GetKeyCode() == wx.WXK_RETURN) and evt.ShiftDown() :
#wx.MessageBox("Got it %d,%s" % (evt.GetKeyCode(),str(evt.ShiftDown())) )
theCtl = self.GetWindow()
#wx.MessageBox("*"+theCtl.GetStringSelection()+'*')
theStr = theCtl.GetStringSelection()
if theStr != '' :
self.textWin.ExecString(theStr)
else:
# get the line containing the cursor
thePos = theCtl.GetInsertionPoint()
colRow = theCtl.PositionToXY(thePos)
theRow = colRow[1]
str = theCtl.GetLineText(theRow)
if re.search('\S',str)!=None: self.textWin.ExecString(str)
else : evt.Skip()
If my text window can hold 5 lines and I enter numbers 1..10 (on separate lines )
and I "shift return" on any of the top lines. I will get the "right" line.
However if I scroll down past the first 5 lines I and do a shift return I get the
a line containing 1..5 depending on the relative position.
It appears that code to calculate theRow in the above proc does not account
for scrolling in the window.
The same code works *ok* on my linux box!
Is this a known problem with wxMac?
(OSX 10.latest/Python 2.5.1/wxPython 2.8.4
Thanks,
Jerry