option add *Dict*Text.font -*-helvetica-medium-r-normal--12-*-iso10646-1 option add *Dict*Entry.font -*-helvetica-medium-r-normal--12-*-iso10646-1 namespace eval ::dict { set m .find.m $m add command -label "Word..." -command "create_or_raise\ .find_dict dict::mkWindow -class Dict; focus .find_dict.e1" #balloonhelp $m -index 2 "Search for a word in dictionary" if {![findInPath "dict"]} { $m entryconfigure "Word..." -state disabled } proc mkWindow {w} { wm title $w "Dictionary lookup" label $w.l1 -text "Word" entry $w.e1 -exportselection false button $w.b1 -text Lookup -command "::dict::lookup $w \[$w.e1 get\]" bind $w.e1 "::dict::lookup $w \[$w.e1 get\]" text $w.t -yscrollcommand "$w.y set" -state disabled bind $w.t <> [list event generate $w.e1 <>] bind $w.t <> [list event generate $w.e1 <>] bind $w.t {%W tag delete sel %W tag add sel "@%x,%y wordstart" "@%x,%y wordend" event generate [winfo parent %W].e1 <> break } bind $w.e1 <> {%W delete 0 end; %W insert 0 [selection get -selection CLIPBOARD] ::dict::lookup [winfo parent %W] [%W get] break } bind $w.e1 <> {%W delete 0 end; %W insert 0 [selection get] ::dict::lookup [winfo parent %W] [%W get] break } scrollbar $w.y -orient vert -command "$w.t yview" grid $w.l1 $w.e1 $w.b1 - -sticky news grid $w.t - - $w.y -sticky news grid rowconfigure $w 1 -weight 1 grid columnconfigure $w 1 -weight 1 $w.t tag configure error -foreground red $w.t tag configure source -foreground darkgreen -relief raised -borderwidth 2 } proc lookup {w word} { if {![string length $word]} { return } set f [open "|dict \"[encoding convertfrom [encoding convertto utf-8 $word]]\"" r] fconfigure $f -encoding utf-8 set answer [read $f] $w.t configure -state normal $w.t delete 0.0 end if {[catch {close $f} msg]} { $w.t insert 0.0 $msg error } $w.t insert 0.0 $answer $w.t see 0.0 set mark 0.0 while {[string length [set mark [$w.t search -regex -- {^From .*\[[^ ]+\]:} "$mark+1lines" end]]]} { $w.t tag add source $mark "$mark lineend" } $w.t configure -state disabled $w.t see 0.0 $w.e1 selection range 0 end } }