Heya Folks,
I'm trying to get my (read-only) multiline wxTextCtrl to select/highlight a line when clicked on. Clicking on a button besides the wxTextCtrl should allow you to remove the selected line.
Selecting/highlighting the line i manage to perform using the code you find below, however, using it i run into the following problem:
1) Click in the wxTextCtrl, the line is highlighted (so far, so good)
2) Click on the button to remove the line, focus is removed from the wxTextCtrl (as expected). However, the eventhandler for the button is not performed (unexpected). Besides, the selection is lost.
3) Click on the button to remove the line, now the eventhandler is performed but as the selection is lost in the previous attempt this has no effect.
Any suggestions as to how to get the eventhandler for the button performed correctly in step two?
Mazzel,
Martijn.
···
EVT_LEFT_UP(self.text, self.On_Click)
def OnClick(evt):
text = evt.GetEventObject()
if text.GetInsertionPoint() <= text.GetLastPosition():
start, end = text.GetSelection()
input = text.GetValue()
if start > 0:
start = input.rfind('\n', 0, start)
if start == -1:
start = 0
else:
start = start + 1
if end < text.GetLastPosition():
end = input.find('\n', end)
if end == -1:
end = text.GetLastPosition()
else:
end = end + 1
if start < end:
text.SetSelection(start, end)