Thank you,
as far as I can tell with absolutely no knowledge of Tcl, you delete all ins* and del* mappings of .text widget and rename the result, if you find the parameter 'readonly'. I believe it works fine, but unfortunately I have no idea how to use it to create proper ROText in Tcl::Tk module.

I have just re-read what I have originally written and realised, you have answered my question just fine, but what I meant is how to implement it in the Tcl::Tk module, not in Tcl language with Tk toolkit.
Sorry if I phrased it wrongly.

Pavel


On 18.5.2006, at 23:31, Jeff Hobbs wrote:

Currently your ROText widget is a disabled Text, which means it
doesn't take focus and consequently key bindings don't work.
Yet I want to use the ROText for tagging text via simple key
bindings. So I need to move cursor, make selections with keyboard and
use my bindings to create tags from selection. I can use buttons now,
but using mouse is too slow for this kind of work.
        ...
In Perl/Tk both of these widgets are actually quite simple, but I
have no idea, how much work would it be in Tcl/Tk to implement them.

OK, what you are asking for isn't really "read-only text", but it is also not that hard to do in Tcl/Tk. The following simple example makes any text tagged
"readonly" ... read only:

pack [text .text]
.text tag configure readonly -background yellow
rename .text ..text
proc .text args {
    if {[string match ins* $args] &&
        [lsearch -exact [.text tag names [lindex $args 1]] readonly]>-1}
return
    if {[string match del* $args]} {
        if {[string compare {} [lindex $args 2]]} {
            if {[string compare {} [eval .text tag nextrange \
                readonly [lrange $args 1 2]]]} return
        } else {
            if {[lsearch -exact [.text tag names \
                [lindex $args 1]] readonly]>-1} return
        }
    }
    uplevel ..text $args
}

Jeff

Reply via email to