Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bind&accelerator keys

Status
Not open for further replies.

japskar

Programmer
Feb 13, 2002
27
0
0
Hi there,
can anyone help me with the following problem?:

I've got a text for a label or button with something like:

"hi e&veryone, I'm t&ext && happy"

I use the '&' as a flag to indicate that I want to underline the character after it (v e and & in this case). Also, the flags must be filtered out. And last but not least, if this text in not used in a label I want a key-binding on the underlined character, but I think I can figure that out by myself.

-Jasper
 
The -underline option ("Specifies the integer index of a character to underline in the widget. This option is used by the default bindings to implement keyboard traversal for menu buttons and menu entries. 0 corresponds to the first character of the text displayed in the widget, 1 to the next character, and so on.") will let you underline 1 and only 1 character in a label or button. I don't know how to underline more than 1 (but not all) characters. Bob Rashkin
rrashkin@csc.com
 
Yes, I already figured that out. I'll need a proc for this to do the filtering and underlining, but I don't know how to filter the content of the text.

-Jasper
 
Well,
set ix [string first & $text];#finds index of "&"
set text [string map {& ""} $text];#removes the "&"
<.......>... -underline $ix
Bob Rashkin
rrashkin@csc.com
 
A slight problem with your scheme is that the -underline option allows you to specify only one character to underline. You can't underline multiple characters. You can't even play tricks with fonts to try to achieve the same effect, because you can use only one font in a button or label widget. (Only the text widget supports multiple fonts.)

By the way, Bong, there's a bit of a problem using string map to filter out the ampersands. Your example removes all ampersands from the string, even the one we wanted to keep. This is a situation where regsub is actually a better choice:

Code:
regsub -all {&(.)} $text {\1} newtext

We're telling regsub to substitute all occurrences of the pattern specified. The pattern is &quot;&&quot; followed by any character. The parentheses around the &quot;any character&quot; delimit a matching subpattern. In the substitution text argument, we can refer to the characters matched by the first matching subpattern with &quot;\1&quot;, the characters matched by the second matching subpattern with &quot;\2&quot;, etc. So, we're tell regsub to find a &quot;&&quot; followed by a second character, and to substitute that with just the second character. The results are stored in the variable newtext. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
You're right, of course, Avia. I forgot he wanted to keep one of them. Bob Rashkin
rrashkin@csc.com
 
Looks pretty slick, but it's only part of what I'll need, because with this method I can only filter my text (which already helps me lot).
Somewhere, I was hoping for a solution which also gave me the index of the first &quot;&&quot;.
In this way, I can do something like:

set n 0:
foreach key $args {button .b$n -text $key;
if {(&_present)} {bind All <Alt-(char_after_&)> {.b$n invoke};
.b$n configure -underline [lindex $key (char_after_&)]; incr n}}

but it seems that I can't get my indices with the 'string match' or 'lsearch' command.
Can anyone help me thwards completing the italic parts between in the above example?

Best regards
-Jasper
 
Again, I'm not sure if I understand the problem. If I
> set a &quot;hi e&veryone, I'm t&ext && happy&quot;
hi e&veryone, I'm t&ext && happy
> string first & $a
4

Is that what you're after? Bob Rashkin
rrashkin@csc.com
 
Yes, i see my fault now. I left out the stringquotes. This caused the malfunction of
> string first & $a

thanx

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top