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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho