Version 0 of Q&D Unicode Character Selecter

Updated 2009-06-04 16:23:55 by LarrySmith
 if 0 {

The Windows charmap utility drives me crazy. It has no way I can find to configure the size of the character display - you have to actually click on one and get the little pop-up in order to see the character. Aside from the basic ascii characters, none of the characters are recognizable.

Now, this should be a simple application, so I knocked one together. It works, it's configurable, it's handy except for one thing. IT'S SLOWER THAN MOLASSES IN JANUARY!!! And I can't figure out why! The actual relabeling of the buttons takes no appreciable time, but using the scale to jump about in the unicode space leaves me with fifteen to thirty seconds of dead air before the darn thing repaints. Any gurus out there up to telling me what's wrong with my approach?

 }



        # charmap

        package require Tk

        wm withdraw .

        proc relabel { args } {
          set ::lastscr ""
          set row $::currow
          for { set i 0 } { $i < 200 } { incr i } {
                set r [ expr int($i/20)+1 ]
                set c [ expr ($i%20)+1 ]
                if { $c == 1 } {
                  .top.rowlbl$r configure \
                        -text [ format %04X [expr $row+$i]]
                }
                set text [ format %04X [expr $row+$i]]
                if { "0x$text" > "0xffff" } { set text "" }
                eval set char "\\u$text"
                set font [ font create \
                  -family [ file rootname $::curfont ] -size 16 ]
                .top.btn-$r-$c configure -text $char -font $font
          }
        }

        proc insert { w } {
          set font [ font create \
                -family [ file rootname $::curfont ] -size 24 ]
          .top.entry configure -font $font
          set char [ $w cget -text ]
          .top.entry insert end $char
        }

        set fontlist [ glob C:/WINDOWS/Fonts/\*  ]
        if { [ catch {
                         set font [ font create -family CODE2000 -size 24 ]
                         set curfont [ glob C:/WINDOWS/Fonts/CODE2000* ]
           } ] != 0 } {
          set font [ font create -family Tahoma -size 24 ]
          set curfont [ glob C:/WINDOWS/Fonts/Tahoma* ]
          }
        set currow 0
        toplevel .top
        wm protocol .top WM_DELETE_WINDOW { exit }
        ttk::combobox .top.fontlist -textvariable curfont \
          -state readonly -values $fontlist -width 36
        trace variable curfont w relabel
        label .top.font -text "Font: " -anchor w
        grid .top.font -row 0 -column 0 -sticky e
        grid .top.fontlist -row 0 -column 1 -columnspan 21 \
          -sticky snew
        for {  set i 1 } { $i <= 20 } { incr i } {
          for { set j 1 } { $j <= 10 } { incr j } {
                button .top.btn-$j-$i -width 1 -text "x" \
                  -command [ list insert .top.btn-$j-$i ]
                grid .top.btn-$j-$i -row $j -column $i -sticky snew
          }
        }
        for { set i 1 } { $i <= 10 } { incr i } {
          label .top.rowlbl$i -text "NNNN"
          grid .top.rowlbl$i -row $i -column 0
        }
        scale .top.scale -showvalue 0 -from 0x0000 -to 0xffff \
          -variable currow -resolution 200
        bind .top.scale <ButtonRelease-1> relabel
        grid .top.scale -row 1 -rowspan 11 -column 21 -sticky ns

        label .top.copy -text "Copy:"
        grid .top.copy -row 11 -column 0 -sticky e

        entry .top.entry -font $font
        grid .top.entry -row 11 -column 1 -columnspan 21 -sticky nsew
        relabel