📄 spinner.itk
字号:
# Spinner # ----------------------------------------------------------------------# Implements a spinner widget. The Spinner is comprised of an # EntryField plus up and down arrow buttons. # Spinner is meant to be used as a base class for creating more# specific spinners such as SpinInt.itk# Arrows may be drawn horizontally or vertically.# User may define arrow behavior or accept the default arrow behavior.## ----------------------------------------------------------------------# AUTHOR: Sue Yockey Phone: (214) 519-2517# E-mail: syockey@spd.dsccc.com# yockey@acm.org## @(#) $Id: spinner.itk,v 1.1 2003/02/05 10:54:09 mdejong Exp $# ----------------------------------------------------------------------# Copyright (c) 1995 DSC Technologies Corporation# ======================================================================# Permission to use, copy, modify, distribute and license this software # and its documentation for any purpose, and without fee or written # agreement with DSC, is hereby granted, provided that the above copyright # notice appears in all copies and that both the copyright notice and # warranty disclaimer below appear in supporting documentation, and that # the names of DSC Technologies Corporation or DSC Communications # Corporation not be used in advertising or publicity pertaining to the # software without specific, written prior permission.# # DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL # DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE.# ======================================================================## Usual options.#itk::usual Spinner { keep -background -borderwidth -cursor -foreground -highlightcolor \ -highlightthickness -insertbackground -insertborderwidth \ -insertofftime -insertontime -insertwidth -labelfont \ -selectbackground -selectborderwidth -selectforeground \ -textbackground -textfont}# ------------------------------------------------------------------# SPINNER# ------------------------------------------------------------------class iwidgets::Spinner { inherit iwidgets::Entryfield constructor {args} {} destructor {} itk_option define -arroworient arrowOrient Orient vertical itk_option define -textfont textFont \ Font -Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* itk_option define -borderwidth borderWidth BorderWidth 2 itk_option define -highlightthickness highlightThickness \ HighlightThickness 2 itk_option define -increment increment Command {} itk_option define -decrement decrement Command {} itk_option define -repeatdelay repeatDelay RepeatDelay 300 itk_option define -repeatinterval repeatInterval RepeatInterval 100 itk_option define -foreground foreground Foreground black public method down {} public method up {} protected method _pushup {} protected method _pushdown {} protected method _relup {} protected method _reldown {} protected method _doup {rate} protected method _dodown {rate} protected method _up {} protected method _down {} protected method _positionArrows {{when later}} protected variable _interior {} protected variable _reposition "" ;# non-null => _positionArrows pending protected variable _uptimer "" ;# non-null => _uptimer pending protected variable _downtimer "" ;# non-null => _downtimer pending} ## Provide a lowercased access method for the Spinner class.# proc ::iwidgets::spinner {pathName args} { uplevel ::iwidgets::Spinner $pathName $args}# ------------------------------------------------------------------# CONSTRUCTOR# ------------------------------------------------------------------body iwidgets::Spinner::constructor {args} { # # Save off the interior for later use. # set _interior $itk_interior # # Create up arrow button. # itk_component add uparrow { canvas $itk_interior.uparrow -height 10 -width 10 \ -relief raised -highlightthickness 0 } { keep -background -borderwidth } # # Create down arrow button. # itk_component add downarrow { canvas $itk_interior.downarrow -height 10 -width 10 \ -relief raised -highlightthickness 0 } { keep -background -borderwidth } # # Add bindings for button press events on the up and down buttons. # bind $itk_component(uparrow) <ButtonPress-1> [code $this _pushup] bind $itk_component(uparrow) <ButtonRelease-1> [code $this _relup] bind $itk_component(downarrow) <ButtonPress-1> [code $this _pushdown] bind $itk_component(downarrow) <ButtonRelease-1> [code $this _reldown] eval itk_initialize $args # # When idle, position the arrows. # _positionArrows}# ------------------------------------------------------------------# DESTRUCTOR# ------------------------------------------------------------------body iwidgets::Spinner::destructor {} { if {$_reposition != ""} {after cancel $_reposition} if {$_uptimer != ""} {after cancel $_uptimer} if {$_downtimer != ""} {after cancel $_downtimer}}# ------------------------------------------------------------------# OPTIONS# ------------------------------------------------------------------# ------------------------------------------------------------------# OPTION: -arroworient## Place arrows vertically or horizontally .# ------------------------------------------------------------------configbody iwidgets::Spinner::arroworient { _positionArrows}# ------------------------------------------------------------------# OPTION: -textfont## Change font, resize arrow buttons.# ------------------------------------------------------------------configbody iwidgets::Spinner::textfont { _positionArrows}# ------------------------------------------------------------------# OPTION: -highlightthickness## Change highlightthickness, resize arrow buttons.# ------------------------------------------------------------------configbody iwidgets::Spinner::highlightthickness { _positionArrows}# ------------------------------------------------------------------# OPTION: -borderwidth## Change borderwidth, resize arrow buttons.# ------------------------------------------------------------------configbody iwidgets::Spinner::borderwidth { _positionArrows}# ------------------------------------------------------------------# OPTION: -increment## Up arrow callback. # ------------------------------------------------------------------configbody iwidgets::Spinner::increment { if {$itk_option(-increment) == {}} { set itk_option(-increment) [code $this up] }}# ------------------------------------------------------------------# OPTION: -decrement## Down arrow callback. # ------------------------------------------------------------------configbody iwidgets::Spinner::decrement { if {$itk_option(-decrement) == {}} { set itk_option(-decrement) [code $this down] }}# ------------------------------------------------------------------# OPTION: -repeatinterval## Arrow repeat rate in milliseconds. A repeatinterval of 0 disables # button repeat.# ------------------------------------------------------------------configbody iwidgets::Spinner::repeatinterval { if {$itk_option(-repeatinterval) < 0} { set itk_option(-repeatinterval) 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -