A Little Hex Editor Widget

GPS: The code that was here is gone. If you want it, see the excellent Starkit that kroc has created.


David Zolli 2004-03-25: I've put a slightly modified starkit of this (tkhexedit) here: http://web.archive.org/web/https://www.zolli.fr/fichiers/TkHexedit.zip


Comments?

TV: I don't dislike WM... It looks neat, I didn't try it out or really scan the code, but it allways appears to me that certain things in tcl should be possible in less code, like one command gives you a standard text processor ,not knowing whether that's reasonable to say about this as example.

AM: I looked at the starkit - the problem I have is that the font is proportional. It makes viewing the file rather awkward! (This was on Windows XP)


I wonder - is this something that would fit into tklib ?


SS: Great widget! I suggest two changes: 1) in the hex visualization, to show in some way what couple of digits are about the same byte. 2) Ability to toggle between insert and replace mode.

AM: I have a few other wishes too (like the ability to interpret consecutive bytes as a number), but one gem hidden in here is that the two text widgets with the file's contents have visible line numbers. With a bit of reworking the code to isolate that behaviour that could be a valuable tool for Tklib as well!


Googie: I modified the widget that kroc put into sdarchive as tkhexedit. I added "marking" of two hex characters that represents single ascii character when user clicks on ascii character. There was already similar functionality working backwards, so I thought this is useful. The only procedure modified is widget:hex:ascii:event:Button-1, so it looks like this:

proc widget:hex:ascii:event:Button-1 {win x y} {
    set pos [$win.ascii index @$x,$y]
    $win.ascii mark set insert $pos
    $win.ascii mark set anchor insert
    focus $win.ascii

    $win.hex tag remove sel 0.0 end
    $win.ascii tag remove sel 0.0 end

    set cur [$win.ascii index insert]
    set splitIndex [split $cur .]

    set line [lindex $splitIndex 0]
    set curChar [lindex $splitIndex 1]

    set curChar [expr {$curChar * 2}]

    set asciiLine [$win.hex index @0,0]
    set offset [expr {int($line + $asciiLine - 1.0)}]

    set cur "$offset.$curChar"
    set end [$win.hex index "$cur + 2 chars"]
    $win.hex tag add sel $cur $end
}

See Also

WISH Binary Viewer