Version 7 of virtual event

Updated 2003-05-06 05:03:18

[Explain virtual events. Is there a tutorial? Illustrate usage. Put forward references in appropriate places--what are those? "advanced Tk-ing?"]

[Important thread: http://groups.google.com/groups?th=5f799aadcb2caf35 ]


Bryan Oakley's wizard mega- (meta?) widget taught me a wonderful use of virtual events. Whereas I had code in my wizard implementation like:

    proc doNextThing { args } {
       ...
    }
    button $w.next -text "Next" -command doNextThing

Bryan had the foresight to indirect the button handling via virtual events. Now I do something like:

    proc doNextThing { args } {
    }
    proc dispatch { event } {
        switch -- $event {
            <<Next>> {
                doNextThing
            } 
            ...
        }
    }
    ...
    button $w.next -text "Next" \
        -command [list event generate $w <<Next>>]
    bind $w <<Next>> [list dispatch <<Next>>]

The wonder of this is that my testing harness can do:

    bind $w <<Next>> {+doTestingThing}

and trap the button presses without making invasive changes to the wizard code!

--Chris Nelson


MC (5 May 2003): Until today I hadn't realized that you could create Virtual Events that weren't associated with a real physical event. Then while googling on event add I came across this[L1 ] enlightening comp.lang.tcl post from Bryan Oakley.