chiark / gitweb /
Privacy control UI
[ypp-sc-tools.db-test.git] / pctb / dictionary-manager
index aaa9e132e457297435b425d0c58cc6f6e8a84a87..c2ea2b59f5b371fe99d72de6afa30b27123c468b 100755 (executable)
@@ -85,8 +85,13 @@ proc init_widgets {} {
     global csrh gotsh ctxh
 
     if {[winfo exists .d]} return
+
+    frame .privacy -bd 2 -relief groove
+    pack .privacy -side top -padx 2 -pady 2 -fill x
+
+    upload_init_widgets
     
-    frame .d
+    frame .d -bd 2 -relief groove -pady 2 -padx 2
 
     image create bitmap image/main
     label .d.mi -image image/main -borderwidth 0
@@ -112,14 +117,15 @@ static unsigned char csr_bits[] = {
     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.mi .d.ctx -side top
-    pack .d
+    pack .d -fill x -padx 2 -pady 2
 
-    frame .help
-    pack .help
+    frame .help -bd 2 -relief groove
+    pack .help -pady 2 -padx 2
 }
 
 proc resize_widgets_core {} {
@@ -143,7 +149,7 @@ proc helptext {t} {
        set x 0; foreach c $l {
            set w .help.at${x}x${y}
            label $w -text $c
-           grid $w -row $y -column $x -padx 5
+           grid $w -row $y -column $x -padx 5 -sticky w
            incr x
        }
        incr y
@@ -237,7 +243,7 @@ proc required/char {} {
     pack .d.csr -side top -before .d.mi
     pack .d.got .d.ctx -side top -after .d.mi
 
-    read_database ./charset-$rows.txt
+    read_database "./#local-char$rows#.txt"
     draw_glyphsdone
     startup_cursor
 }
@@ -294,11 +300,14 @@ proc pixmap_maybe_ok {} {
     set nsel 0
     foreach_pixmap_col col {
        set cs [.d.pe.grid.l$col curselection]
-       incr nsel [llength $cs]
+       set lcs [llength $cs]
+       if {!$lcs} continue
+       incr nsel $lcs
        set pixmap_selcol $col
        set pixmap_selrow [lindex $cs 0]
     }
     if {$nsel==1} {
+       debug "MAYBE_OK YES col=$pixmap_selcol row=$pixmap_selrow."
        .d.pe.ok configure -state normal -command pixmap_ok
     } else {
        .d.pe.ok configure -state disabled -command {}
@@ -335,9 +344,9 @@ proc required/pixmap {} {
     set data [exec pnmscale 2 << $ppm]
     image create photo image/main -data $data
 
-    set alloptions [exec ./yppsc-resolver-pixoptions $unk_what]
+    set alloptions [exec ./dictionary-pixmap-options $unk_what]
 
-    read_database ./pixmaps.txt
+    read_database "./#local-pixmap#.txt"
 
     set mulcols [image width image/main]
     set mulrows [image height image/main]
@@ -346,7 +355,8 @@ proc required/pixmap {} {
     place forget .d.mi.csr_1
 
     pack forget .d.csr .d.got
-    pack .d.pe -side top -before .d.mi -pady 10
+    pack .d.pe -side top -before .d.mi -pady 2
+    #-pady 2 -fill x
 
     eval destroy [winfo children .d.pe.grid]
     set col 0; foreach {colname coldesc rows} $alloptions {
@@ -365,8 +375,58 @@ proc required/pixmap {} {
     pixmap_maybe_ok
     
     helptext {
-       {{Indicate the correct parse of this image, and click OK.}}
+       {{Indicate the meaning of this image, and click OK.}}
+    }
+}
+
+#========== UPLOADS TO DICTIONARY SERVER ==========
+
+proc upload_init_widgets {} {
+    global privacy_setting
+
+    set privacy_setting [upload_status]
+
+    label .privacy.warn -text " Privacy "
+    if {$privacy_setting} {
+       .privacy.warn configure -background yellow -foreground black
     }
+    label .privacy.overall -text " Upload new dictionary entry:"
+    label .privacy.reference -text " See README.privacy."
+
+    pack .privacy.warn .privacy.overall -side left
+
+    foreach {setting string} {
+       0 {No}
+       1 {Yes, anonymously}
+       2 {Yes, quoting my pirate name.}
+    } {
+       radiobutton .privacy.o$setting -text $string \
+           -value $setting -variable privacy_setting
+       pack .privacy.o$setting -side left
+       if {$setting > $privacy_setting} {
+           .privacy.o$setting configure -state disabled
+       }
+    }
+    pack .privacy.reference -side left
+
+    if {!$privacy_setting} {
+       foreach w [winfo children .privacy] {
+           $w configure -state disabled
+       }
+    }
+}
+
+proc upload_status {} {
+    # returns 0, 1, 2 for none, anon, with pirate name
+    global env
+
+    if {![info exists env(YPPSC_PCTB_DICT_SUBMIT)]} { debug a; return 0 }
+    if {![string compare 0 $env(YPPSC_PCTB_DICT_SUBMIT)]} { debug b; return 0 }
+
+    if {![info exists env(YPPSC_PIRATE)]} { return 1 }
+    if {![string length $env(YPPSC_PIRATE)]} { return 1 }
+
+    return 2
 }
 
 #========== CHARACTER SET ==========
@@ -528,9 +588,9 @@ proc recursor//01 {z1} {
     bind_key space { othercursor }
     bind_leftright_q cur_$z1 0 [expr {$cols-1}]
     if {[llength $glyphsdone]} {
-       bind_key Tab { set cur_mode already; recursor }
+       bind_key BackSpace { set cur_mode already; recursor }
     } else {
-       bind_key Tab {}
+       bind_key BackSpace {}
     }
     bind_key Return {
        if {$cur_0 != $cur_1} {
@@ -543,7 +603,7 @@ proc recursor//01 {z1} {
        {{<- ->}   {move cursor, adjusting area to define}}
        {Space     {switch to moving other cursor}}
        {Return    {confirm location, enter letter(s)}}
-       {Tab       {switch to correcting earlier ocr}}
+       {Backspace {switch to correcting earlier ocr}}
        {Q         {quit and abandon OCR run}}
     }
 }
@@ -585,9 +645,8 @@ proc recursor/already {} {
     set rmax [lindex $glyphsdone [expr {$cur_already*4}]]
     place .d.csr.csr -x [expr {$rmax*$mul-3}]
     bind_key Return {}
-    bind_key space {}
     bind_leftright_q cur_already 0 [expr {[llength $glyphsdone]/4-1}]
-    bind_key Tab { bind_key Delete {}; set cur_mode 1; recursor }
+    bind_key space { bind_key Delete {}; set cur_mode 1; recursor }
     bind_key Delete {
        RETURN_RESULT DELETE [lrange $glyphsdone \
                                  [expr $cur_already*4] \
@@ -596,7 +655,7 @@ proc recursor/already {} {
     helptext {
        {{<- ->}   {move cursor, selecting glyph to correct}}
        {Del       {clear this glyph from the recognition database}}
-       {Tab       {switch to selecting area to define as new glyph}}
+       {Space     {switch to selecting area to define as new glyph}}
        {Q         {quit and abandon OCR run}}
     }
 }