Version 0 of Inheriting Widget Binding Classes

Updated 2002-01-31 19:24:33

Thu Jan 31 12:16:22 MST 2002 - GPS: I looked at the various ways in which people modify bindings to make a read only text widget and came up with the code below. The nice thing about this vs. the Read-only text widget page is that it doesn't require a modified file -- it does it all in memory.


  #!/bin/wish8.3

  proc copyBindingClass {class newClass} {
        set bindingList [bind $class]
        #puts $bindingList

        foreach binding $bindingList {
                bind $newClass $binding [bind Text $binding]
        }
  }

  proc removeBindingsFromClass {class removeList} {
        foreach item $removeList {
                bind $class <$item> {}
        }
  }

  pack [text .t]
  .t insert end "Hello World"

  copyBindingClass Text Text.t

  bindtags .t ".t Text.t all"

  removeBindingsFromClass Text.t [list KeyPress Delete BackSpace Meta-Key-Delete \
        Key-Tab Key-Insert Key-Left Key-Right Key-Up Key-Down Shift-Key-Left \
        Shift-Key-Right Shift-Key-Up Shift-Key-Down Control-Key-Left Control-Key-Right \
        Control-Key-Up Control-Key-Down Control-Shift-Key-Left Control-Shift-Key-Right \
        Key-Return Key-BackSpace Control-Key-space Control-Shift-Key-space \
        Shift-Key-Select <Paste> <Cut> <Clear>]