Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
Unintelligible behaviour of tk_dialog function

Posted by Dimon (Dimon), 20 February 2007
Being in testing of new script, I saw a strange behavior of standart Tk's dialog showing function - tk_dialog.
The syntax of function call is:
Code:
set reply [tk_dialog .some "The Title" "Do you want to say yes?" question 0 Yes No "I'm not sure"]

Zero means the index of the button that is to be the default button of the dialog (0 for the leftmost button, and so on). There are 3 buttons in the sample.

If any button would be pressed by mouse, tk_dialog returns a code: 0 if 1-st button was pressed, 1 if 2-nd and so on.
But when I try to select a buttons with pressing 'tab' key, focus is changing, but I see only one button pressed when Enter key is pressing.  
Can I change buttons focus with keyboard withous mouse?

Posted by admin (Graham Ellis), 21 February 2007
The behaviour is controlled not only by the widgit itself, but also by the window manager.   The windows defaults, etc, get involved too.  So navigation keystrokes may indeed not reach your application.  I think that's what your looking for me to confirm and explain?

Posted by Dimon (Dimon), 21 February 2007
Well Graham, yesterday's evening I have correct that dialog's behavior. I found the next code block in tk_dialog's source code (the 'dialog.tcl' file in tk8.4 library):
Code:
# 4. Create a binding for <Return> on the dialog if there is
# a default button.

if {$default >= 0} {
  bind $w <Return> "
     [list $w.button$default] configure -state active -relief sunken
     update idletasks
     after 100
     set ::tk::Priv(button) $default
     "
}

It means that author has design one common <Return> event for dialog's toplevel form.

Well, I have delete code snippet showed above and have written the next code block to improve tk_dialog's functionality:
Code:
# 4. Create a binding for <Return>, <Tab> and <Shift+Tab> on each button of the dialog

# Binding <Tab> event for each button
 set butCount [llength $args]
 for {set i 0} {$i<$butCount} {incr i} {
     bind $w.button$i <Tab> "
     $w.button$i configure -default normal
 if {$i<[expr [llength $args]-1]} { $w.button[expr $i+1] configure -default active } else {$w.button0 configure -default active}
 "

# Binding <Return> event for each button  
 bind $w.button$i <Return> "
     [list $w.button$i] configure -state active -relief sunken
     update idletasks
     after 100
     set ::tk::Priv(button) $i
 "
 }
 
# Binding <Shift-Key-Tab> event for each button
 for {set i [expr $butCount-1]} {$i>=0} {incr i -1} {
     bind $w.button$i <Shift-Key-Tab> "
     $w.button$i configure -default normal
 if {$i==0} { $w.button[expr [llength $args]-1] configure -default active } else {$w.button[expr $i-1] configure -default active}
 "
 }  

It works correctly  

Posted by admin (Graham Ellis), 21 February 2007
Excellent ... I hope you're gooing to submit yor change back to the Tcl team for inclusion in a future release?



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho