📄 spinner.itk
字号:
} }# ------------------------------------------------------------------# OPTION: -repeatdelay## Arrow repeat delay in milliseconds. # ------------------------------------------------------------------configbody iwidgets::Spinner::repeatdelay { if {$itk_option(-repeatdelay) < 0} { set itk_option(-repeatdelay) 0 } }# ------------------------------------------------------------------# OPTION: -foreground## Set the foreground color of the up and down arrows. Remember# to make sure the "tag" exists before setting them...# ------------------------------------------------------------------configbody iwidgets::Spinner::foreground { if { [$itk_component(uparrow) gettags up] != "" } { $itk_component(uparrow) itemconfigure up \ -fill $itk_option(-foreground) } if { [$itk_component(downarrow) gettags down] != "" } { $itk_component(downarrow) itemconfigure down \ -fill $itk_option(-foreground) }}# ------------------------------------------------------------------# METHODS# ------------------------------------------------------------------# ------------------------------------------------------------------# METHOD: up## Up arrow command. Meant to be overloaded by derived class. # ------------------------------------------------------------------body iwidgets::Spinner::up {} {}# ------------------------------------------------------------------# METHOD: down ## Down arrow command. Meant to be overloaded by derived class.# ------------------------------------------------------------------body iwidgets::Spinner::down {} {}# ------------------------------------------------------------------# PROTECTED METHOD: _positionArrows ?when?## Draw Arrows for spinner. 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::Spinner::_positionArrows {{when later}} { if {$when == "later"} { if {$_reposition == ""} { set _reposition [after idle [code $this _positionArrows now]] } return } elseif {$when != "now"} { error "bad option \"$when\": should be now or later" } set _reposition "" set bdw [cget -borderwidth] # # Based on the orientation of the arrows, pack them accordingly and # determine the width and height of the spinners. For vertical # orientation, it is really tight in the y direction, so we'll take # advantage of the highlightthickness. Horizontal alignment has # plenty of space vertically, thus we'll ignore the thickness. # switch $itk_option(-arroworient) { vertical { grid $itk_component(uparrow) -row 0 -column 0 grid $itk_component(downarrow) -row 1 -column 0 set totalHgt [winfo reqheight $itk_component(entry)] set spinHgt [expr $totalHgt / 2] set spinWid [expr round ($spinHgt * 1.6)] } horizontal { grid $itk_component(uparrow) -row 0 -column 0 grid $itk_component(downarrow) -row 0 -column 1 set spinHgt [expr [winfo reqheight $itk_component(entry)] - \ (2 * [$itk_component(entry) cget -highlightthickness])] set spinWid $spinHgt } default { error "bad orientation option \"$itk_option(-arroworient)\",\ should be horizontal or vertical" } } # # Configure the width and height of the spinners minus the borderwidth. # Next delete the previous spinner polygons and create new ones. # $itk_component(uparrow) config \ -height [expr $spinHgt - (2 * $bdw)] \ -width [expr $spinWid - (2 * $bdw)] $itk_component(uparrow) delete up $itk_component(uparrow) create polygon \ [expr $spinWid / 2] $bdw \ [expr $spinWid - $bdw - 1] [expr $spinHgt - $bdw -1] \ [expr $bdw + 1] [expr $spinHgt - $bdw - 1] \ -fill $itk_option(-foreground) -tags up $itk_component(downarrow) config \ -height [expr $spinHgt - (2 * $bdw)] \ -width [expr $spinWid - (2 * $bdw)] $itk_component(downarrow) delete down $itk_component(downarrow) create polygon \ [expr $spinWid / 2] [expr ($spinHgt - $bdw) - 1] \ [expr $bdw + 2] [expr $bdw + 1] \ [expr $spinWid - $bdw - 2] [expr $bdw + 1] \ -fill $itk_option(-foreground) -tags down}# ------------------------------------------------------------------# PRIVATE METHOD: _pushup## Up arrow button press event. Call _doup with repeatdelay. # ------------------------------------------------------------------body iwidgets::Spinner::_pushup {} { $itk_component(uparrow) config -relief sunken _doup $itk_option(-repeatdelay)}# ------------------------------------------------------------------# PRIVATE METHOD: _pushdown## Down arrow button press event. Call _dodown with repeatdelay. # ------------------------------------------------------------------body iwidgets::Spinner::_pushdown {} { $itk_component(downarrow) config -relief sunken _dodown $itk_option(-repeatdelay)}# ------------------------------------------------------------------# PRIVATE METHOD: _doup## Call _up and post to do another one after "rate" milliseconds if# repeatinterval > 0.# ------------------------------------------------------------------body iwidgets::Spinner::_doup {rate} { _up if {$itk_option(-repeatinterval) > 0} { set _uptimer [after $rate [code $this _doup $itk_option(-repeatinterval)]] }}# ------------------------------------------------------------------# PRIVATE METHOD: _dodown## Call _down and post to do another one after "rate" milliseconds if # repeatinterval > 0.# ------------------------------------------------------------------body iwidgets::Spinner::_dodown {rate} { _down if {$itk_option(-repeatinterval) > 0} { set _downtimer \ [after $rate [code $this _dodown $itk_option(-repeatinterval)]] }}# ------------------------------------------------------------------# PRIVATE METHOD: _relup## Up arrow button release event. Cancel pending up timer.# ------------------------------------------------------------------body iwidgets::Spinner::_relup {} { $itk_component(uparrow) config -relief raised if {$_uptimer != ""} { after cancel $_uptimer set _uptimer "" }}# ------------------------------------------------------------------# PRIVATE METHOD: _reldown## Up arrow button release event. Cancel pending down timer.# ------------------------------------------------------------------body iwidgets::Spinner::_reldown {} { $itk_component(downarrow) config -relief raised if {$_downtimer != ""} { after cancel $_downtimer set _downtimer "" }}# ------------------------------------------------------------------# PRIVATE METHOD: _up## Up arrow button press event. Call defined increment command. # ------------------------------------------------------------------body iwidgets::Spinner::_up {} { uplevel #0 $itk_option(-increment)}# ------------------------------------------------------------------# PRIVATE METHOD: _down ## Down arrow button press event. Call defined decrement command. # ------------------------------------------------------------------body iwidgets::Spinner::_down {} { uplevel #0 $itk_option(-decrement)}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -