comp.lang.tcl
[Top] [All Lists]

invoking

Subject: invoking
From: Ralf Fassel
Date: Fri, 30 May 2008 12:48:11 +0200
Newsgroups: comp.lang.tcl

In my app I have a Start and a Stop button which start/stop processing.

When the focus is on 'Start', pressing the space key starts processing
and sets the focus to 'Stop', so that I can press space again and stop
the processing (which sets the focus back to 'Start' etc).

This works as long as the focus stays on Start.  Sometimes some other
widget takes the focus, and then this no longer works.

When I simply
   bind . <space> doStartStop
then I call doStartStop even from e.g. entries which should not invoke
it.  I would have to disable the {.}-binding in all those entries
which is a bit tedious, dito for checkbuttons etc.

Using virtual events:
    bind {.} <<MyEvent>> {doStartStop %W}
    bind {.} <space> {event generate %W <<MyEvent>>}

    # now disable all those which have space default behaviour
    bind Entry <<MyEvent>> {break}
    bind Button <<MyEvent>> {break}
    ...
    # Hope I don't miss any... :-/

    pack [entry .e] [button .b -command "doStartStop from btn"]
    bind . <Escape> {focus .}

    proc doStartStop {args} {
        puts "doStartStop $args"
    }

Or *add* <<MyEvent>> to all widgets/classes which should handle the
space key as start/stop?    

Or just make <Escape> re/set the focus to the Start/Stop button?

I'm sure there is a better way, I just don't get it.

R'

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy