chiark / gitweb /
WIP island determination; ocr resolver can make query to user
[ypp-sc-tools.db-live.git] / pctb / yppsc-ocr-resolver
index ec4473d2205ed19f7c114ad81775701490266916..6ff436b12858d831efd182d3515f7145f870b370 100755 (executable)
@@ -82,8 +82,12 @@ static unsigned char csr_bits[] = {
 
     frame .d.mi.csr_0 -bg white -width 1
     frame .d.mi.csr_1 -bg white -width 1
+    frame .d.pe
+    frame .d.pe.grid
+    button .d.pe.ok -text OK
+    pack .d.pe.grid .d.pe.ok -side left
 
-    pack .d.csr .d.mi .d.got .d.ctx -side top
+    pack .d.mi .d.got .d.ctx -side top
     pack .d
 
     frame .help
@@ -101,26 +105,15 @@ proc show_context {maxhv x ctxs} {
     if {$wh > $maxh} { set maxh $wh }
 }
 
-proc resize_widgets {} {
+proc resize_widgets_core {} {
     global mulcols mulrows csrh gotsh ctxh glyphsdone
     global unk_l unk_contexts
     
     foreach w {.d.csr .d.got .d.ctx} {
        $w configure -width $mulcols
     }
-    #.d configure -height [expr {$csrh+$mulrows+$gotsh+$ctxh}]
-    foreach w {0 1} {
-       .d.mi.csr_$w configure -height $mulrows
-    }
 
     eval destroy [winfo children .d.ctx]
-
-    set maxh 0
-    foreach {min max contexts got} $glyphsdone {
-       show_context maxh $min $contexts
-    }
-    show_context maxh $unk_l $unk_contexts
-    .d.ctx configure -height $maxh
 }
 
 
@@ -260,7 +253,6 @@ proc startup_cursor {} {
 
     set cur_0 $unk_l
     set cur_1 [expr {$unk_r+1}]
-    set last_ht {}
 
     recursor
 }
@@ -268,6 +260,8 @@ proc startup_cursor {} {
 
 #---------- runtime display and keystroke handling ----------
 
+set last_ht {}
+
 proc helptext {t} {
     global last_ht
     if {![string compare $t $last_ht]} return
@@ -525,26 +519,6 @@ proc RETURN_RESULT {how what} {
 proc main/default {} {
     puts stderr "Do not run this program directly."
     exit 12
-    
-    global glyphsdone unk_l unk_r unk_contexts
-
-    set glyphsdone {
-       7 11 1 M
-       13 17 0 a
-       19 23 0 n
-    }
-    set unk_l 25
-    set unk_r 29
-    set unk_contexts Test
-
-    set f [open text.xpm]
-    read_xpm $f
-    close $f
-
-    read_database
-    resize_widgets
-    draw_glyphsdone
-    startup_cursor
 }
 proc done/default {} {
 }
@@ -561,13 +535,97 @@ proc required {} {
     required/$l
 }
 
+
+proc foreach_pixmap_col {var body} {
+    global alloptions
+    upvar 1 $var col
+    for {set col 0} {$col < [llength $alloptions]/3} {incr col} {
+       uplevel 1 $body
+    }
+}
+
+proc pixmap_select {ncol} {
+    global alloptions
+    debug "PIX SELECT $ncol [llength $alloptions]"
+    foreach_pixmap_col col {
+       if {$col==$ncol} continue
+       .d.pe.grid.l$col selection clear 0 end
+    }
+    pixmap_maybe_ok
+}
+proc pixmap_maybe_ok {} {
+    global alloptions pixmap_selcol pixmap_selrow
+    set nsel 0
+    foreach_pixmap_col col {
+       set cs [.d.pe.grid.l$col curselection]
+       incr nsel [llength $cs]
+       set pixmap_selcol $col
+       set pixmap_selrow [lindex $cs 0]
+    }
+    if {$nsel==1} {
+       .d.pe.ok configure -state normal -command pixmap_ok
+    } else {
+       .d.pe.ok configure -state disabled -command {}
+    }
+}
+proc pixmap_ok {} {
+    foreach_pixmap_col col {
+       .d.pe.grid.l$col configure -state disabled
+    }
+    .d.pe.ok configure -state disabled
+    helptext {{{ Processing }}}
+}
+
 proc required/pixmap {} {
-    global unk_what
+    global unk_what ppm mulcols alloptions
     must_gets stdin unk_what
-    error nyi
+    debug "GOT pixmap $unk_what"
+    set ppm {}
+    while 1 {
+       must_gets stdin ppml
+       if {![string length $ppml]} break
+       append ppm $ppml "\n"
+    }
+    set data [exec pnmscale 2 << $ppm]
+    image create photo image/main -data $data
+
+    set alloptions [exec ./yppsc-resolver-pixoptions $unk_what]
+
+    #read_database_pixmaps
+
+    set mulcols [image width image/main]
+    set mulrows [image height image/main]
+    resize_widgets_core
+    place forget .d.mi.csr_0
+    place forget .d.mi.csr_1
+    .d.ctx configure -height 0
+    pack forget .d.csr
+    pack .d.pe -side top -before .d.mi -pady 10
+
+    eval destroy [winfo children .d.pe.grid]
+    set col 0; foreach {colname coldesc rows} $alloptions {
+       debug "INIT $col $colname \"$coldesc\""
+       label .d.pe.grid.t$col -text $colname
+       listbox .d.pe.grid.l$col
+       foreach {rowname rowdesc} $rows {
+           debug "INIT $col $colname \"$coldesc\" $rowname \"$rowdesc\""
+           .d.pe.grid.l$col insert end $rowdesc
+       }
+       bind .d.pe.grid.l$col <<ListboxSelect>> [list pixmap_select $col]
+       grid .d.pe.grid.t$col -column $col -row 0
+       grid .d.pe.grid.l$col -column $col -row 1
+       incr col
+    }
+    pixmap_maybe_ok
+    
+    helptext {
+       {{Indicate the correct parse of this image, and click OK.}}
+    }
 }
 
 proc required/char {} {
+    global mulrows
+    
     must_gets stdin l
 
     manyset [lrange $l 0 3] unk_l unk_r unk_contexts
@@ -578,7 +636,20 @@ proc required/char {} {
     fconfigure stdin -blocking yes
 
     read_xpm stdin
-    resize_widgets
+
+    resize_widgets_core
+    foreach w {0 1} {
+       .d.mi.csr_$w configure -height $mulrows
+    }
+    set maxh 0
+    foreach {min max contexts got} $glyphsdone {
+       show_context maxh $min $contexts
+    }
+    show_context maxh $unk_l $unk_contexts
+    .d.ctx configure -height $maxh
+    pack forget .d.pe
+    pack .d.csr -side top -before .d.mi
+
     read_database
     draw_glyphsdone
     startup_cursor