From: <ro...@us...> - 2011-12-20 17:47:53
|
Revision: 1950 http://nsclspectcl.svn.sourceforge.net/nsclspectcl/?rev=1950&view=rev Author: ron-fox Date: 2011-12-20 17:47:43 +0000 (Tue, 20 Dec 2011) Log Message: ----------- Simplify focus management Modified Paths: -------------- trunk/SpecTcl/treegui/gateCreate.tcl trunk/SpecTcl/treegui/spectrumAxis.tcl trunk/SpecTcl/treegui/treeParameterWidget.tcl trunk/SpecTcl/treegui/treeVariableEditor.tcl Modified: trunk/SpecTcl/treegui/gateCreate.tcl =================================================================== --- trunk/SpecTcl/treegui/gateCreate.tcl 2011-12-19 21:53:33 UTC (rev 1949) +++ trunk/SpecTcl/treegui/gateCreate.tcl 2011-12-20 17:47:43 UTC (rev 1950) @@ -117,8 +117,8 @@ $win.type configure -width $labelLen - ttk::entry $win.name -textvariable ${selfns}::options(-gatename) - ttk::entry $win.definition -textvariable ${selfns}::options(-definition) -width 32 + ttk::entry $win.name -textvariable ${selfns}::options(-gatename) -takefocus 1 + ttk::entry $win.definition -textvariable ${selfns}::options(-definition) -width 32 -takefocus 1 # # Layout the widget. Modified: trunk/SpecTcl/treegui/spectrumAxis.tcl =================================================================== --- trunk/SpecTcl/treegui/spectrumAxis.tcl 2011-12-19 21:53:33 UTC (rev 1949) +++ trunk/SpecTcl/treegui/spectrumAxis.tcl 2011-12-20 17:47:43 UTC (rev 1950) @@ -71,7 +71,7 @@ # Top row of stuff: - ttk::menubutton $win.parametermenubutton -text "Parameter" -menu $win.parametermenu + ttk::menubutton $win.parametermenubutton -text "Parameter" -menu $win.parametermenu -takefocus 0 treeMenu $win.parametermenu -command [mymethod Dispatch -command %L %N] ttk::label $win.lowlabel -text Low ttk::label $win.highlabel -text High @@ -80,13 +80,17 @@ # Bottom row of stuff: - ttk::entry $win.parameter -textvariable ${selfns}::options(-parameter) + ttk::entry $win.parameter -textvariable ${selfns}::options(-parameter) \ + -takefocus 1 ttk::entry $win.low -textvariable ${selfns}::options(-low) \ - -validate key -validatecommand [mymethod ValidNumber %P] -width 7 + -validate key -validatecommand [mymethod ValidNumber %P] -width 7 \ + -takefocus 1 ttk::entry $win.high -textvariable ${selfns}::options(-high) \ - -validate key -validatecommand [mymethod ValidNumber %P] -width 7 + -validate key -validatecommand [mymethod ValidNumber %P] -width 7 \ + -takefocus 1 ttk::entry $win.bins -textvariable ${selfns}::options(-bins) \ - -validate key -validatecommand [mymethod ValidNumber %P] -width 7 + -validate key -validatecommand [mymethod ValidNumber %P] -width 7 \ + -takefocus 1 ttk::label $win.units -textvariable ${selfns}::options(-units) -width 8 # Grid the elements: @@ -123,8 +127,12 @@ method StateChange {option value} { set options($option) $value + # Disable/enable focus taking appropriately: + + set focus [expr {($value eq "normal") ? 1 : 0}] + foreach widget [list $win.parameter $win.parametermenubutton $win.low $win.high $win.bins] { - $widget configure -state $value + $widget configure -state $value -takefocus $focus } } Modified: trunk/SpecTcl/treegui/treeParameterWidget.tcl =================================================================== --- trunk/SpecTcl/treegui/treeParameterWidget.tcl 2011-12-19 21:53:33 UTC (rev 1949) +++ trunk/SpecTcl/treegui/treeParameterWidget.tcl 2011-12-20 17:47:43 UTC (rev 1950) @@ -61,13 +61,7 @@ option -changecmd [list] option -title false; # If true titles are put above the text entries. - # The variable below is the focus order ring: - # It allows us to build methods focusLeft and focusRight that shift focus - # the appropriate direction around the ring. - # Note that $win is not necessarily defined here so we just put the widget - # name tails: - variable focusRing [list .name .low .high .unit] ## @@ -96,17 +90,17 @@ foreach entry [list .name .low .high .unit] optionname [list -name -low -high -units] \ width [list 32 5 5 10] { ::ttk::entry $win$entry -textvariable ${selfns}::options($optionname) \ - -width $width + -width $width -takefocus 1 - # Bindings that move focus right: + # Bindings that move focus right.. note that tab is a next focus anyway. - foreach binding [list <Tab> <Return> <Right>] { - bind $win$entry $binding [list after 2 [mymethod focusRight $entry]] + foreach binding [list <Return> <Right>] { + bind $win$entry $binding [list after 2 [mymethod focusRight %W]]; # $entry]] } - # Bindings that move focus left: + # Bindings that move focus left:..note that shift-tab moves focus anyway. - foreach binding [list <Shift-Tab> <Left> <ISO_Left_Tab>] { - bind $win$entry $binding [list after 2 [mymethod focusLeft $entry]] + foreach binding [list <Left>] { + bind $win$entry $binding [list after 2 [mymethod focusLeft %W]];# $entry]] } } @@ -146,22 +140,13 @@ # @param tail tail of current widgetname... actual widget is $win.$tail # method focusRight tail { - set currentIndex [lsearch -exact $focusRing $tail] - set nextIndex [expr {($currentIndex+1) % [llength $focusRing]}] - set nextWidget $win[lindex $focusRing $nextIndex] - - focus $nextWidget + focus [tk_focusNext $tail] } ## # Change the focus to the prior widget in the focus ring. # @param tail # method focusLeft tail { - set currentIndex [lsearch -exact $focusRing $tail] - set nextIndex [expr {($currentIndex-1) % [llength $focusRing]}] - set nextWidget $win[lindex $focusRing $nextIndex] - - focus $nextWidget - + focus [tk_focusPrev $tail] } } \ No newline at end of file Modified: trunk/SpecTcl/treegui/treeVariableEditor.tcl =================================================================== --- trunk/SpecTcl/treegui/treeVariableEditor.tcl 2011-12-19 21:53:33 UTC (rev 1949) +++ trunk/SpecTcl/treegui/treeVariableEditor.tcl 2011-12-20 17:47:43 UTC (rev 1950) @@ -103,28 +103,26 @@ for {set row 1} {$row <= $options(-lines)} {incr row} { ttk::radiobutton $win.radio$row -value $row -variable ${selfns}::options(-current) - ttk::entry $win.name$row -width 32 - ttk::entry $win.value$row -width 10 - ttk::entry $win.units$row -width 10 + ttk::entry $win.name$row -width 32 -takefocus 1 + ttk::entry $win.value$row -width 10 -takefocus 1 + ttk::entry $win.units$row -width 10 -takefocus 1 ttk::button $win.load$row -text Load -command [mymethod ReloadDispatch $row] ttk::button $win.set$row -text Set -command [mymethod SetVariable $row] grid $win.radio$row $win.name$row $win.value$row $win.units$row $win.load$row $win.set$row - # Bindings for this row as well: + # Bindings for this row as well.. note that tab/shift tab normally change focus. - foreach binding [list <Tab> <Return> <Right> ] { + foreach binding [list <Return> <Right> ] { foreach \ - widget [list $win.name$row $win.value$row $win.units$row] \ - nextwidget [list $win.value$row $win.units$row $win.name$row] { - bind $widget $binding [list after 2 focus $nextwidget] + widget [list $win.name$row $win.value$row $win.units$row] { + bind $widget $binding [mymethod changeFocus tk_focusNext %W] } } - foreach binding [list <Shift-Tab> <Left> <ISO_Left_Tab> ] { + foreach binding [list <Left>] { foreach \ - widget [list $win.name$row $win.value$row $win.units$row] \ - prior [list $win.units$row $win.name$row $win.value$row] { - bind $widget $binding [list after 2 focus $prior] + widget [list $win.name$row $win.value$row $win.units$row] { + bind $widget $binding [mymethod changeFocus tk_focusPrev %W] } } } @@ -213,7 +211,18 @@ #--------------------------------------------------------------------- # Private utilities. # + ## + # Change the focus: + # @param nextcmd - command that determines the next widget given the current widget. + # @param widget - Current widget. + # + method changeFocus {nextcmd widget} { + # after since entry widgets do immediate focus games with some chars. + + after 2 {focus [$nextcmd $widget]}; + } + ## # Dispatch to a script at the global level with substitutions: # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |