📄 buttonbox.itk
字号:
set index [index $index] set defbtn [lindex $_buttonList $index] foreach knownButton $_displayList { if {$knownButton == $defbtn} { $itk_component($knownButton) configure -defaultring yes } else { $itk_component($knownButton) configure -defaultring no } }}# ------------------------------------------------------------------# METHOD: hide index## Hide the push button given by index. This doesn't remove the button # permanently from the display list, just inhibits its display.# ------------------------------------------------------------------body iwidgets::Buttonbox::hide {index} { set index [index $index] set tag [lindex $_buttonList $index] if {[set dind [lsearch $_displayList $tag]] != -1} { place forget $itk_component($tag) set _displayList [lreplace $_displayList $dind $dind] _setBoxSize }}# ------------------------------------------------------------------# METHOD: show index## Displays a previously hidden push button given by index. Check if # the button is already in the display list. If not then add it back # at it's original location and redisplay.# ------------------------------------------------------------------body iwidgets::Buttonbox::show {index} { set index [index $index] set tag [lindex $_buttonList $index] if {[lsearch $_displayList $tag] == -1} { set _displayList [linsert $_displayList $index $tag] _setBoxSize }}# ------------------------------------------------------------------# METHOD: invoke ?index?## Invoke the command associated with a push button. If no arguments# are given then the default button is invoked, otherwise the argument# is expected to be a button index.# ------------------------------------------------------------------body iwidgets::Buttonbox::invoke {args} { if {[llength $args] == 0} { $itk_component([lindex $_buttonList [index default]]) invoke } else { $itk_component([lindex $_buttonList [index [lindex $args 0]]]) \ invoke }}# ------------------------------------------------------------------# METHOD: buttonconfigure index ?option? ?value option value ...?## Configure a push button given by index. This method allows # configuration of pushbuttons from the Buttonbox level. The options# may have any of the values accepted by the add method.# ------------------------------------------------------------------body iwidgets::Buttonbox::buttonconfigure {index args} { set tag [lindex $_buttonList [index $index]] set retstr [uplevel $itk_component($tag) configure $args] _setBoxSize return $retstr}# ------------------------------------------------------------------# METHOD: buttonccget index option## Return value of option for push button given by index. Option may# have any of the values accepted by the add method.# ------------------------------------------------------------------body iwidgets::Buttonbox::buttoncget {index option} { set tag [lindex $_buttonList [index $index]] set retstr [uplevel $itk_component($tag) cget [list $option]] return $retstr}# -----------------------------------------------------------------# PRIVATE METHOD: _getMaxWidth## Returns the required width of the largest button.# -----------------------------------------------------------------body iwidgets::Buttonbox::_getMaxWidth {} { set max 0 foreach tag $_displayList { set w [winfo reqwidth $itk_component($tag)] if {$w > $max} { set max $w } } return $max}# -----------------------------------------------------------------# PRIVATE METHOD: _getMaxHeight## Returns the required height of the largest button.# -----------------------------------------------------------------body iwidgets::Buttonbox::_getMaxHeight {} { set max 0 foreach tag $_displayList { set h [winfo reqheight $itk_component($tag)] if {$h > $max} { set max $h } } return $max}# ------------------------------------------------------------------# METHOD: _setBoxSize ?when?## Sets the proper size of the frame surrounding all the buttons.# If "when" is "now", the change is applied immediately. If it is # "later" or it is not specified, then the change is applied later, # when the application is idle.# ------------------------------------------------------------------body iwidgets::Buttonbox::_setBoxSize {{when later}} { if {[winfo ismapped $itk_component(hull)]} { if {$when == "later"} { if {$_resizeFlag == ""} { set _resizeFlag [after idle [code $this _setBoxSize now]] } return } elseif {$when != "now"} { error "bad option \"$when\": should be now or later" } set _resizeFlag "" set numBtns [llength $_displayList] if {$itk_option(-orient) == "horizontal"} { set minw [expr $numBtns * [_getMaxWidth] \ + ($numBtns+1) * $itk_option(-padx)] set minh [expr [_getMaxHeight] + 2 * $itk_option(-pady)] } else { set minw [expr [_getMaxWidth] + 2 * $itk_option(-padx)] set minh [expr $numBtns * [_getMaxHeight] \ + ($numBtns+1) * $itk_option(-pady)] } # # Remove the configure event bindings on the hull while we adjust the # width/height and re-position the buttons. Once we're through, we'll # update and reinstall them. This prevents double calls to position # the buttons. # set tags [bindtags $itk_component(hull)] if {[set i [lsearch $tags bbox-config]] != -1} { set tags [lreplace $tags $i $i] bindtags $itk_component(hull) $tags } component hull configure -width $minw -height $minh update idletasks _positionButtons bindtags $itk_component(hull) [linsert $tags 0 bbox-config] }} # ------------------------------------------------------------------# METHOD: _positionButtons# # This method is responsible setting the width/height of all the # displayed buttons to the same value and for placing all the buttons# in equidistant locations.# ------------------------------------------------------------------body iwidgets::Buttonbox::_positionButtons {} { set bf $itk_component(hull) set numBtns [llength $_displayList] # # First, determine the common width and height for all the # displayed buttons. # if {$numBtns > 0} { set bfWidth [winfo width $itk_component(hull)] set bfHeight [winfo height $itk_component(hull)] if {$bfWidth >= [winfo reqwidth $itk_component(hull)]} { set _btnWidth [_getMaxWidth] } else { if {$itk_option(-orient) == "horizontal"} { set _btnWidth [expr $bfWidth / $numBtns] } else { set _btnWidth $bfWidth } } if {$bfHeight >= [winfo reqheight $itk_component(hull)]} { set _btnHeight [_getMaxHeight] } else { if {$itk_option(-orient) == "vertical"} { set _btnHeight [expr $bfHeight / $numBtns] } else { set _btnHeight $bfHeight } } } # # Place the buttons at the proper locations. # if {$numBtns > 0} { if {$itk_option(-orient) == "horizontal"} { set leftover [expr [winfo width $bf] \ - 2 * $itk_option(-padx) - $_btnWidth * $numBtns] if {$numBtns > 0} { set offset [expr $leftover / ($numBtns + 1)] } else { set offset 0 } if {$offset < 0} {set offset 0} set xDist [expr $itk_option(-padx) + $offset] set incrAmount [expr $_btnWidth + $offset] foreach button $_displayList { place $itk_component($button) -anchor w \ -x $xDist -rely .5 -y 0 -relx 0 \ -width $_btnWidth -height $_btnHeight set xDist [expr $xDist + $incrAmount] } } else { set leftover [expr [winfo height $bf] \ - 2 * $itk_option(-pady) - $_btnHeight * $numBtns] if {$numBtns > 0} { set offset [expr $leftover / ($numBtns + 1)] } else { set offset 0 } if {$offset < 0} {set offset 0} set yDist [expr $itk_option(-pady) + $offset] set incrAmount [expr $_btnHeight + $offset] foreach button $_displayList { place $itk_component($button) -anchor n \ -y $yDist -relx .5 -x 0 -rely 0 \ -width $_btnWidth -height $_btnHeight set yDist [expr $yDist + $incrAmount] } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -