Version 1 of A little logic notation editor

Updated 2006-08-04 08:15:47

NEM 3 August 2006: Here's a simple little text widget editor I knocked up. It's sole contribution is that it has some convenient bindings for entering symbols from predicate logic. I also added a binding for lambda too, on a whim.

http://www.cs.nott.ac.uk/~nem/logiceditor.png

 # logiceditor.tcl --
 #
 #       A simple text editor with convenient bindings for entering logic
 #       symbols.
 #
 # Copyright (c) 2006 Neil Madden ([email protected]).
 #
 # License: BSD-style.

 package require Tcl         8.5
 package require Tk          8.4
 package provide logiceditor 1.0

 namespace eval logiceditor {
    # List of special symbols
    #   Symbol name         UTF-8       Binding
    variable symbols {
        implication         \u21D2      i
        equivalence         \u21D4      =
        negation            \u00AC      n
        conjuction          \u2227      a
        disjunction         \u2228      o
        universal           \u2200      u
        existential         \u2203      e
        definition          \u2261      d
        entails             \u22A8      t
        proof               \u22A2      p

        lambda              \u03BB      l
    }
    variable modifier   Control
    proc setup {} {
        variable symbols
        variable modifier
        foreach {name unicode key} $symbols {
            bind LogicEditor <$modifier-$key> \
                "%W insert insert [subst $unicode]; break"
        }
    }
    setup

    proc create {path args} {
        set top [toplevel $path]
        wm title $top "Logic Editor"
        text $top.editor {expand}$args -font {{Lucida Sans} 12} \
            -yscrollcommand [list $top.vsb set] \
            -xscrollcommand [list $top.hsb set] \
            -wrap none 
        bindtags $top.editor [linsert [bindtags $top.editor] 1 LogicEditor]
        scrollbar $top.vsb -orient vertical \
            -command [list $top.editor yview]
        scrollbar $top.hsb -orient horizontal \
            -command [list $top.editor xview]

        grid $top.editor -row 0 -column 0 -sticky nsew
        grid $top.vsb -row 0 -column 1 -sticky ns
        grid $top.hsb -row 1 -column 0 -sticky ew

        grid rowconfigure $top 0 -weight 1
        grid columnconfigure $top 0 -weight 1
        return $top
    }
 }
 logiceditor::create .t

The code above actually requires 8.5 due to the use of {expand}. I corrected it to require Tcl 8.5 instead of 8.4. Here's a version for 8.4:

 # logiceditor.tcl --
 #
 #       A simple text editor with convenient bindings for entering logic
 #       symbols.
 #
 # Copyright (c) 2006 Neil Madden ([email protected]).
 #
 # License: BSD-style.

 package require Tcl         8.5
 package require Tk          8.4
 package provide logiceditor 1.0

 namespace eval logiceditor {
    # List of special symbols
    #   Symbol name         UTF-8       Binding
    variable symbols {
        implication         \u21D2      i
        equivalence         \u21D4      =
        negation            \u00AC      n
        conjuction          \u2227      a
        disjunction         \u2228      o
        universal           \u2200      u
        existential         \u2203      e
        definition          \u2261      d
        entails             \u22A8      t
        proof               \u22A2      p

        lambda              \u03BB      l
    }
    variable modifier   Control
    proc setup {} {
        variable symbols
        variable modifier
        foreach {name unicode key} $symbols {
            bind LogicEditor <$modifier-$key> \
                "%W insert insert [subst $unicode]; break"
        }
    }
    setup

    proc create {path args} {
        set top [toplevel $path]
        wm title $top "Logic Editor"
        eval [concat text $top.editor $args -font {{{Lucida Sans} 12}} \
            -yscrollcommand [list [list $top.vsb set]] \
            -xscrollcommand [list [list $top.hsb set]] \
            -wrap none]
        bindtags $top.editor [linsert [bindtags $top.editor] 1 LogicEditor]
        scrollbar $top.vsb -orient vertical \
            -command [list $top.editor yview]
        scrollbar $top.hsb -orient horizontal \
            -command [list $top.editor xview]

        grid $top.editor -row 0 -column 0 -sticky nsew
        grid $top.vsb -row 0 -column 1 -sticky ns
        grid $top.hsb -row 1 -column 0 -sticky ew

        grid rowconfigure $top 0 -weight 1
        grid columnconfigure $top 0 -weight 1
        return $top
    }
 }
 logiceditor::create .t

[ Category GUI | Category Mathematics | Category Word and Text Processing | Category Widget ]