2 option add *Dict*Text.font -*-helvetica-medium-r-normal--12-*-iso10646-1
3 option add *Dict*Entry.font -*-helvetica-medium-r-normal--12-*-iso10646-1
4 namespace eval ::dict {
6 $m add command -label "Word..." -command "create_or_raise\
7 .find_dict dict::mkWindow -class Dict; focus .find_dict.e1"
8 #balloonhelp $m -index 2 "Search for a word in dictionary"
9 if {![findInPath "dict"]} {
10 $m entryconfigure "Word..." -state disabled
14 wm title $w "Dictionary lookup"
15 label $w.l1 -text "Word"
16 entry $w.e1 -exportselection false
17 button $w.b1 -text Lookup -command "::dict::lookup $w \[$w.e1 get\]"
18 bind $w.e1 <Return> "::dict::lookup $w \[$w.e1 get\]"
19 text $w.t -yscrollcommand "$w.y set" -state disabled
20 bind $w.t <<Paste>> [list event generate $w.e1 <<Paste>>]
21 bind $w.t <<PasteSelection>> [list event generate $w.e1 <<PasteSelection>>]
22 bind $w.t <Double-1> {%W tag delete sel
23 %W tag add sel "@%x,%y wordstart" "@%x,%y wordend"
24 event generate [winfo parent %W].e1 <<PasteSelection>>
27 bind $w.e1 <<Paste>> {%W delete 0 end;
28 %W insert 0 [selection get -selection CLIPBOARD]
29 ::dict::lookup [winfo parent %W] [%W get]
32 bind $w.e1 <<PasteSelection>> {%W delete 0 end;
33 %W insert 0 [selection get]
34 ::dict::lookup [winfo parent %W] [%W get]
37 scrollbar $w.y -orient vert -command "$w.t yview"
39 grid $w.l1 $w.e1 $w.b1 - -sticky news
40 grid $w.t - - $w.y -sticky news
41 grid rowconfigure $w 1 -weight 1
42 grid columnconfigure $w 1 -weight 1
43 $w.t tag configure error -foreground red
44 $w.t tag configure source -foreground darkgreen -relief raised -borderwidth 2
47 proc lookup {w word} {
48 if {![string length $word]} {
51 set f [open "|dict \"[encoding convertfrom [encoding convertto utf-8 $word]]\"" r]
52 fconfigure $f -encoding utf-8
54 $w.t configure -state normal
56 if {[catch {close $f} msg]} {
57 $w.t insert 0.0 $msg error
59 $w.t insert 0.0 $answer
62 while {[string length [set mark [$w.t search -regex -- {^From .*\[[^ ]+\]:} "$mark+1lines" end]]]} {
63 $w.t tag add source $mark "$mark lineend"
65 $w.t configure -state disabled
67 $w.e1 selection range 0 end