chiark / gitweb /
Adjust match context radiobutton states
[ypp-sc-tools.db-test.git] / pctb / dictionary-manager
index 81a480ef476a0278f84f6a7bd6a1f85e66899efa..51140c69a003cda31d76952d41b4c878030c19d0 100755 (executable)
@@ -104,7 +104,7 @@ proc init_widgets {} {
     frame .d -bd 2 -relief groove -pady 2 -padx 2
 
     image create bitmap image/main
-    label .d.mi -image image/main -borderwidth 0
+    label .d.mi -image image/main -bd 0
 
     frame .d.csr -bg black -height $csrh
     frame .d.got -bg black -height $gotsh
@@ -123,6 +123,7 @@ static unsigned char csr_bits[] = {
     entry .d.csr.csr.e -bd 0
     pack .d.csr.csr.l -side left
 
+    frame .d.selctx -bd 2 -relief groove
     frame .d.mi.csr_0 -bg white -width 1
     frame .d.mi.csr_1 -bg white -width 1
     frame .d.pe
@@ -244,7 +245,8 @@ proc do_database_update {im def} {
 }
     
 proc required/char {} {
-    global mulrows glyphsdone unk_l unk_r unk_contexts rows
+    global mulrows glyphsdone unk_l unk_r unk_contexts rows new_context
+    global all_contexts
     
     must_gets stdin l
 
@@ -254,6 +256,8 @@ proc required/char {} {
 
     char_read_xpm stdin
 
+    catch { unset all_contexts }
+
     resize_widgets_core
     foreach w {0 1} {
        .d.mi.csr_$w configure -height $mulrows
@@ -261,12 +265,34 @@ proc required/char {} {
     set maxh 0
     foreach {min max contexts got} $glyphsdone {
        show_context maxh $min $contexts
+       foreach ctx $contexts { set all_contexts($ctx) 1 }
+    }
+    foreach ctx $unk_contexts { set all_contexts($ctx) 1 }
+
+    destroy [winfo children .d.selctx]
+    label .d.selctx.title -text \
+       {Select match context for altering dictionary:}
+    pack .d.selctx.title -side left
+    set new_context [lindex $unk_contexts 0]
+
+    set ci 0; foreach ctx [lsort [array names all_contexts]] {
+       set all_contexts($ctx) $ci
+       set selw .d.selctx.c$ci
+       set seltxt $ctx
+       radiobutton $selw -variable new_context -value $ctx -text $seltxt
+       pack $selw -side left
+       incr ci
     }
+    $selw configure -text "$seltxt."
+    label .d.selctx.warning -text {See README.charset.}
+    pack .d.selctx.warning -side left
+
     show_context maxh $unk_l $unk_contexts
     .d.ctx configure -height $maxh
     pack forget .d.pe
-    pack .d.csr -side top -before .d.mi
+    pack .d.selctx .d.csr -side top -before .d.mi
     pack .d.got .d.ctx -side top -after .d.mi
+    pack configure .d.selctx -fill x
     focus .d
 
     select_database char$rows
@@ -274,6 +300,11 @@ proc required/char {} {
     startup_cursor
 }
 
+proc approve_showentry_xinfo/char {w def} {
+    set unic [string2unicodenames $def]
+    label $w -text $unic
+}
+
 #========== PIXMAPS ==========
 
 #---------- pixmap database read and write ----------
@@ -380,7 +411,7 @@ proc required/pixmap {} {
     place forget .d.mi.csr_0
     place forget .d.mi.csr_1
 
-    pack forget .d.csr .d.got
+    pack forget .d.selctx .d.csr .d.got
     pack .d.pe -side top -before .d.mi -pady 2
     .d configure -takefocus 0
     #-pady 2 -fill x
@@ -406,6 +437,10 @@ proc required/pixmap {} {
     }
 }
 
+proc approve_showentry_xinfo/pixmap {w def} {
+    label $w -image image/empty
+}
+
 #========== UPLOADS TO DICTIONARY SERVER ==========
 
 proc upload_init {} {
@@ -683,13 +718,31 @@ proc startup_cursor {} {
 
 #---------- character set runtime display and keystroke handling ----------
 
+proc char_exactly_selctxts {contexts} {
+    global all_contexts
+    foreach ctx [array names all_contexts] {
+       set ci $all_contexts($ctx)
+       set selw .d.selctx.c$ci
+       if {[lsearch -exact $contexts $ctx]>=0} {
+           set state normal
+       } else {
+           set state disabled
+       }
+       $selw configure -state $state
+    }
+}
+
 proc recursor/0 {} { recursor//01 0 }
 proc recursor/1 {} { recursor//01 1 }
 proc recursor//01 {z1} {
-    global mul rhsmost_max cols glyphsdone
+    global mul rhsmost_max cols glyphsdone cur_0 cur_1
     upvar #0 cur_$z1 cur
     .d.csr.csr.l configure -text {adjust}
     place .d.csr.csr -x [expr {$cur*$mul - 7}]
+
+    manyset [char_get_definition_info $cur_0 $cur_1] contexts
+    char_exactly_selctxts $contexts
+
     bind_key space { othercursor }
     bind_leftright_q cur_$z1 0 [expr {$cols-1}]
     if {[llength $glyphsdone]} {
@@ -719,6 +772,8 @@ proc othercursor {} {
 }
 
 proc recursor/text {} {
+    global all_contexts
+    
     helptext {
        {Return   {confirm entry of new glyph}}
        {Escape   {abandon entry}}
@@ -729,8 +784,8 @@ proc recursor/text {} {
     focus .d.csr.csr.e
     bind .d.csr.csr.e <Key-Return> {
        set strq [.d.csr.csr.e get]
-       if {[regexp -line {^(?:[!-[]|[]-~]|\\\\|\\x[0-9a-f]{2})+} $strq]} {
-           RETURN_RESULT DEFINE "$cur_0 $cur_1 $strq"
+       if {[string length $strq]} {
+           RETURN_RESULT DEFINE [list $cur_0 $cur_1 $strq]
        }
     }
     bind .d.csr.csr.e <Key-Escape> {
@@ -747,6 +802,9 @@ proc recursor/already {} {
     global glyphsdone
     global cur_already mul
     global glyphsdone cur_already mul
+
+    char_exactly_selctxts [lindex $glyphsdone [expr {$cur_already*4+2}]]
+
     .d.csr.csr.l configure -text {correct}
     set rmax [lindex $glyphsdone [expr {$cur_already*4}]]
     place .d.csr.csr -x [expr {$rmax*$mul-3}]
@@ -840,9 +898,12 @@ proc dbkey {ctx l r} {
     return $bm
 }
 
-proc update_database/DEFINE {c0 c1 strq} {
+proc char_get_definition_info {c0 c1} {
+    # => ncontexts cl cr
     global glyphsdone unk_l unk_contexts wordmap database
+    
     if {$c0 > $c1} { manyset [list $c0 $c1] c1 c0 }
+    
     if {$c0 == $unk_l} {
        set ncontexts $unk_contexts
     } else {
@@ -850,11 +911,21 @@ proc update_database/DEFINE {c0 c1 strq} {
            if {$l==$c0} { set ncontexts $contexts; break }
        }
        if {![info exists ncontexts]} {
-           puts stderr "must start at letter LHS!"
-           return
+           set ncontexts {}
        }
     }
     incr c1 -1
+    set r [list $ncontexts $c0 $c1]
+    debug "CDGI $r"
+    return $r
+}
+
+proc update_database/DEFINE {c0 c1 strq} {
+    manyset [char_get_definition_info $c0 $c1] ncontexts c0 c1
+    if {![llength $ncontexts]} {
+       puts stderr "must start at letter LHS!"
+       return
+    }
     foreach c $ncontexts {
        set bm [dbkey $c $c0 $c1]
        do_database_update $bm $strq
@@ -916,14 +987,7 @@ proc remote-serv/take {yesno file dict} {
 
     must_gets_exactly stdin confirmed
 
-    if {![string compare pixmap $dict]} {
-       set reqkind pixmap
-       debug "DICT PIXMAP"
-    } elseif {[regexp {^(char)([1-9]\d*)$} $dict dummy reqkind rows]} {
-       debug "DICT CHAR rqk=$reqkind r=$rows."
-    } else {
-       error "$dict ?"
-    }
+    manyset [dict2_reqkind_rows reqkind rows]
     
     if {$yesno} {
        read_database $dictdir/master-$dict.txt
@@ -984,6 +1048,18 @@ proc regsub-data {exp subspec args} {
     }
 }
 
+proc dict2_reqkind_rows {dict} {
+    if {![string compare pixmap $dict]} {
+       return {pixmap {}}
+       debug "DICT PIXMAP"
+    } elseif {[regexp {^(char)([1-9]\d*)$} $dict dummy reqkind rows]} {
+       debug "DICT CHAR rqk=$reqkind r=$rows."
+       return [list $reqkind rows]
+    } else {
+       error "$dict ?"
+    }
+}
+
 proc chop_counted {var} {
     upvar 1 $var val
     global data
@@ -1018,8 +1094,18 @@ proc approve_compare {fd1 fd2} {
     return [string compare $sv1 $sv2]
 }
 
+proc string2unicodenames {str} {
+    return [exec perl -e {
+       use Unicode::CharName qw(uname);
+       $ARGV[0] =~ s/^ //;
+       foreach $_ (split //,$ARGV[0]) {
+           print uname(ord),"\n" or die $!
+       }
+    } " $str"]
+}
+
 proc approve_showentry {ix file specdata} {
-    global approve_ixes
+    global approve_ixes reqkind
     
     approve_decompose_data $specdata
 
@@ -1043,14 +1129,8 @@ proc approve_showentry {ix file specdata} {
     image create photo approve/$ix -data $ppm
     label $wb-image -image approve/$ix -bd 2 -relief sunken
 
-    set unic [exec perl -e {
-       use Unicode::CharName qw(uname);
-       $ARGV[0] =~ s/^ //;
-       foreach $_ (split //,$ARGV[0]) {
-           print uname(ord),"\n" or die $!
-       }
-    } " $def"]
-    label $wb-unicode -text $unic
+    manyset [dict2_reqkind_rows $dict] reqkind
+    approve_showentry_xinfo/$reqkind $wb-xinfo $def
 
     if {$ix} {
        label $wb-div -bd 1 -relief sunken -image image/empty
@@ -1061,7 +1141,7 @@ proc approve_showentry {ix file specdata} {
     button $wb-act.rej -text Reject -command [list approve_reject $ix]
     pack $wb-act.rej
 
-    grid $wb-def $wb-image $wb-unicode $wb-act $wb-inf -padx 3
+    grid $wb-def $wb-image $wb-xinfo $wb-act $wb-inf -padx 3
     grid configure $wb-image -ipadx 3 -ipady 3 -sticky w
 
     lappend approve_ixes $ix