Luc <
[email protected]d> wrote:
On Sat, 2 Mar 2024 06:44:29 -0000 (UTC), Rich wrote:
The text widget already tells you, with perfect accuracy, what text is >>selected. And you not only get lines, but character position within
line accuracy (of the start and end) for the text widget selection
data.
If you were trying to track it yourself, yes, that can be a pain. But
why did the widget's built in tracking not work for you?
Yes, of course. I didn't provide you with enough details so you don't
really understand what is going on. My fault. Sorry.
Yep, that's *very* true.
It's a series of pairs. I want to keep track of what pair is selected.
And I can't afford to make the text widget editable. The user could
delete one, two, God knows how many lines, and I would no longer know
what is what and what is where.
So I have to "disable" the text widget. The user thus cannot select
any text in the most obvious way. And I can no longer keep track of
cursor position because there is no cursor in a disabled text widget.
I have to provide a very controlled method for selecting a pair.
So, create a 'read only' text widget instead. That way the user can't
make changes to the text, but all the normal text widget features still
work. See code example at end.
I am no longer using text widgets. Now the big text widget contains
a series of labels. The whole thing looks and behaves a lot better
now. I thought it would be cool to let the user edit the boxes at
leisure, but I've decided that idea is not very viable. It may be
possible, but too much work and not really necessary.
Using tags to mark pairs, you could even extend the example below to
allow editing within a single pair by checking that the position being
edited is within the range of a tag attched to a given pair that is
meant to be editable at the moment.
Quick code example of a read only text widget:
#!/usr/bin/wish
text .text
.text insert end "Lorem ipsum dolor sit amet, consectetur\n"
.text insert end "adipiscing elit, sed do eiusmod tempor\n"
.text insert end "incididunt ut labore et dolore magna\n"
.text insert end "aliqua. Ut enim ad minim veniam,\n"
.text insert end "quis nostrud exercitation ullamco laboris\n"
.text insert end "nisi ut aliquip ex ea commodo consequat.\n"
.text insert end "Duis aute irure dolor in reprehenderit\n"
.text insert end "in voluptate velit esse cillum dolore\n"
.text insert end "eu fugiat nulla pariatur. Excepteur\n"
.text insert end "sint occaecat cupidatat non proident,\n"
.text insert end "sunt in culpa qui officia deserunt mollit\n"
.text insert end "anim id est laborum."
pack .text
# now, rename the text widget to a new name
rename .text .real-text-widget
# and create a proc to 'watch' for 'change content' commands and
# reject any attempts to change the contents
proc .text {subcommand args} {
switch -exact -- $subcommand {
delete -
insert -
replace {
# modification command - reject it
puts stderr "Refusing to edit text widget contents"
}
default {
# chain everything else to the real text widget
.real-text-widget $subcommand {*}$args
}
}
}
# also bind to <<Selection>> to show changes in the selection
bind .text <<Selection>> [list show-selection .text]
proc show-selection {w} {
puts stderr ".text selection is: [.text tag ranges sel]"
}
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)