I'm trying to extract a zone of text fro a multiline textControl. For this I'm using GetSelection(). If the selection is on the first line, this works perfectly, but if it is on other lines, I have a kind of offset for the selection:
What about using GetStringSelection instead of GetValue?
Werner
···
On 10/17/2011 10:28 AM, VINOT Sébastien wrote:
Hello,
I'm trying to extract a zone of text fro a multiline textControl. For this I'm using GetSelection(). If the selection is on the first line, this works perfectly, but if it is on other lines, I have a kind of offset for the selection:
If I have the text:
LINE 1
LINE 2
LINE 3
And my visual selection looks like:
LINE 1
L[INE] 2
LINE 3
Let do this piece of code (ctrl is my textCtrl):
pos = ctrl.GetPosition() #gives (9, 12). text = ctrl.GetValue()
beginText = text[:pos[0]] # Returns
middleText = text[pos[0]:pos[1]]
endText = text[pos[1]:]
I get:
beginText : "LINE 1\nLI"
middleText: "NE "
endText: "2\nLINE 3\n"
With a selection in the first line this works perfectly.
GetStringSelection works but my problem is that I have to insert a kind of tag before and after the selection.
···
Le 17 oct. 2011 à 10:45, werner a écrit :
On 10/17/2011 10:28 AM, VINOT Sébastien wrote:
Hello,
I'm trying to extract a zone of text fro a multiline textControl. For this I'm using GetSelection(). If the selection is on the first line, this works perfectly, but if it is on other lines, I have a kind of offset for the selection:
If I have the text:
LINE 1
LINE 2
LINE 3
And my visual selection looks like:
LINE 1
L[INE] 2
LINE 3
Let do this piece of code (ctrl is my textCtrl):
pos = ctrl.GetPosition() #gives (9, 12). text = ctrl.GetValue()
beginText = text[:pos[0]] # Returns
middleText = text[pos[0]:pos[1]]
endText = text[pos[1]:]
I get:
beginText : "LINE 1\nLI"
middleText: "NE "
endText: "2\nLINE 3\n"
With a selection in the first line this works perfectly.
What about using GetStringSelection instead of GetValue?
On Windows the textctrl uses DOS style line endings of '\r\n' internally, so when positions are calculated you get differences between what the widget tells you and the positions in the value of the widget that has only '\n' for the end of line characters. So one way to work around this would be to do something like text = text.replace('\n', '\r\n') if you are on Windows, and then do the opposite with each segment after you extract them from the value to turn them back into platform neutral strings.
···
On 10/17/11 1:28 AM, VINOT S�bastien wrote:
Hello,
I'm trying to extract a zone of text fro a multiline textControl. For this I'm using GetSelection(). If the selection is on the first line, this works perfectly, but if it is on other lines, I have a kind of offset for the selection: