Re: Binding to menu entry - not just to menu(-tree)



"Zbigniew B." <Zbigniew@xxxxxxxxxxxxxxxxx> writes:

Of course I would to setup such help for all menus - and so I must bind the
same event to several different paths, like:

bind .menubar.help.menu <<MenuSelect>> {showHelp %W}
bind .menubar.edit.menu <<MenuSelect>> {showHelp %W}

...and so on.

Found an explanation in man: "It is possible for several bindings to match a
given X event.". I'm just not sure: does there exist any limit? Does it have
any (significant) influence on the load? Can I make - let's say - 9 such
bindings "quite safely"?

This is not what that bit of help was referring to. It refers to
cases like

bind .menubar.help.menu <Key> {foo}
bind .menubar.help.menu <Key-H> {bar}
bind Menu <Key> {baz}

where all three match when you type H. The first two both have the
same tag, so only the <Key-H> binding will fire, because it is more
specific. The Menu binding will also fire because it has a separate
tag (use [bindtags .menubar.help.menu] to see the list of tags).

proc showHelp {w} {
if { [$w index active] != "none" } {
if { [$w index active] > 0 } {
set chosen [.menubar.help.menu entrycget active -label]
.statusBar.lab config -text $helptext($chosen)
}
} else {
.statusBar.lab config -text ""
}

You can simpligy the handling of "none" by using the raw entry index
as the index to helptext, and setting
set ::helptext(none) ""
set ::helptext(1) "..."

(I generally use a -textvariable instead of .statusBar.lab config )

If you are making context help for all (or most) menus you can use a
single [bind] command, and use helptext() lookup instead of most
programming, with entries like $::helptext($w,$chosen)

bind Menu <<MenuSelect>> {showHelp %W}

proc showHelp { w } {
set active [$w index active]
if { [string is integer $active] && $active > 0 } {
set chosen [.menubar.help.menu entrycget active -label]
set ::menuHelpText $::helptext($w,$chosen)
} else {
set ::menuHelpText ""
}
}

set helptext(.menubar.help.menu,foo) "Help for foo in menubar.help"



Donald Arseneau asnd@xxxxxxxxx
.



Relevant Pages

  • Re: cpuset and affinity implementation
    ... An example would be some sort of system with multiple CPUs where some ... So if you just make a set that includes all cpus in the system you can then bind your realtime threads to specific cpus and the other threads to the remainder. ... The reason individual threads can't be assigned to groups is because cpuset_getidfor a pid wouldn't make sense then and I expect administrators to be mostly interested in managing groups of processes. ... bindings when returning the processor set for the process. ...
    (freebsd-arch)
  • Re: Recovering keys from key events
    ... bind the key events that correspond to these actions, ... other bindings flow through. ... This is exactly how Leo works. ... making a unique callback for every binding. ...
    (comp.lang.tcl)
  • RE: Source Safe Visual Studio bindings incorrect after Share and B
    ... latest version from the new branch so it is easy for the incorrect bindings ... only for some solutions while others appear to bind to the new branch. ... The binding information is stored in .sln file. ... VSS doesn't know about it. ...
    (microsoft.public.vsnet.ide)
  • Re: Tktable question
    ... was doing for bindings and asked why, ... bind Table ... virtual events, but the lack of double angle braces (in other words, ... place the data into the appropriate buffer? ...
    (comp.lang.tcl)
  • Re: Interaction Modes and Canvas Widgets
    ... "bind" subcommand to add bindings for particular canvas items and ... Changing the widget's bindtags has no effect on the item ... Bind all commands for the mode to a canvas item tag named for the ... foreach seq { ...
    (comp.lang.tcl)