📄 watch.itk
字号:
should be -string or -clicks" } }}# -----------------------------------------------------------------------------# METHOD: watch ?args?## Evaluates the specified args against the canvas component.# -----------------------------------------------------------------------------itcl::body iwidgets::Watch::watch {args} { return [eval $itk_component(canvas) $args]}# -----------------------------------------------------------------------------# METHOD: _drawHand tag## -----------------------------------------------------------------------------itcl::body iwidgets::Watch::_drawHand {tag} { set degrees [expr {abs(450-($_timeVar($tag)*$_theta($tag)))%360}] set radians [expr {$degrees*($PI/180)}] set x [expr {$_x0+$_radius($tag)*cos($radians)}] set y [expr {$_y0+$_radius($tag)*sin($radians)*(-1)}] watch coords $tag \ [expr {$x-$_radius($tag)}] \ [expr {$y-$_radius($tag)}] \ [expr {$x+$_radius($tag)}] \ [expr {$y+$_radius($tag)}] set start [expr {$degrees-180-($_extent($tag)/2)}] watch itemconfigure $tag -start $start}# ------------------------------------------------------------------# PUBLIC METHOD: show time## Changes the currently displayed time to be that of the time# argument. The time may be specified either as a string or an# integer clock value. Reference the clock command for more # information on obtaining times and their formats.# ------------------------------------------------------------------itcl::body iwidgets::Watch::show {{time "now"}} { if {$time == "now"} { set seconds [clock seconds] } elseif {![catch {clock format $time}]} { set seconds $time } elseif {[catch {set seconds [clock scan $time]}]} { error "bad time: \"$time\", must be a valid time\ string, clock clicks value or the keyword now" } set timestring [clock format $seconds -format "%I %M %S %p"] set _timeVar(hour) [expr int(1[lindex $timestring 0] - 100)] set _timeVar(minute) [expr int(1[lindex $timestring 1] - 100)] set _timeVar(second) [expr int(1[lindex $timestring 2] - 100)] set _ampmVar($this) [lindex $timestring 3] _drawHand hour _drawHand minute _drawHand second}# -----------------------------------------------------------------------------# PROTECTED METHOD: _displayClock ?when?## Places the hour, minute, and second dials in the canvas. 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.# -----------------------------------------------------------------------------itcl::body iwidgets::Watch::_displayClock {{when "later"}} { if {$when == "later"} { if {$_reposition == ""} { set _reposition [after idle [itcl::code $this _displayClock now]] } return } # # Compute the center coordinates for the clock based on the # with and height of the canvas. # set width [winfo width $itk_component(canvas)] set height [winfo height $itk_component(canvas)] set _x0 [expr {$width/2}] set _y0 [expr {$height/2}] # # Set the radius of the watch, pivot, hour, minute and second items. # set _radius(outer) [expr {$_x0 < $_y0 ? $_x0 : $_y0}] set _radius(pivot) [expr {$itk_option(-pivotradius)*$_radius(outer)}] set _radius(hour) [expr {$itk_option(-hourradius)*$_radius(outer)}] set _radius(minute) [expr {$itk_option(-minuteradius)*$_radius(outer)}] set _radius(second) [expr {$itk_option(-secondradius)*$_radius(outer)}] set outerWidth [watch itemcget clock -width] # # Set the coordinates of the clock item # set x1Outer $outerWidth set y1Outer $outerWidth set x2Outer [expr {$width-$outerWidth}] set y2Outer [expr {$height-$outerWidth}] watch coords clock $x1Outer $y1Outer $x2Outer $y2Outer # # Set the coordinates of the tick items # set offset [expr {$outerWidth*2}] set x1Tick [expr {$x1Outer+$offset}] set y1Tick [expr {$y1Outer+$offset}] set x2Tick [expr {$x2Outer-$offset}] set y2Tick [expr {$y2Outer-$offset}] for {set i 0} {$i < 60} {incr i} { watch coords tick$i $x1Tick $y1Tick $x2Tick $y2Tick } set maxTickWidth [expr {$_radius(outer)-$_radius(second)+1}] set minTickWidth [expr {round($maxTickWidth/2)}] watch itemconfigure big -width $maxTickWidth watch itemconfigure little -width [expr {round($maxTickWidth/2)}] # # Set the coordinates of the pivot item # set x1Center [expr {$_x0-$_radius(pivot)}] set y1Center [expr {$_y0-$_radius(pivot)}] set x2Center [expr {$_x0+$_radius(pivot)}] set y2Center [expr {$_y0+$_radius(pivot)}] watch coords pivot $x1Center $y1Center $x2Center $y2Center # # Set the coordinates of the hour, minute, and second dial items # watch itemconfigure hour -extent $_extent(hour) _drawHand hour watch itemconfigure minute -extent $_extent(minute) _drawHand minute watch itemconfigure second -extent $_extent(second) _drawHand second set _reposition ""}# -----------------------------------------------------------------------------# OPTIONS# -----------------------------------------------------------------------------# ------------------------------------------------------------------# OPTION: state## Configure the editable state of the widget. Valid values are# normal and disabled. In a disabled state, the hands of the # watch are not selectabled.# ------------------------------------------------------------------itcl::configbody ::iwidgets::Watch::state { if {$itk_option(-state) == "normal"} { watch bind minute <B1-Motion> \ [itcl::code $this _handMotionCB minute %x %y] watch bind minute <ButtonRelease-1> \ [itcl::code $this _handReleaseCB minute %x %y] watch bind hour <B1-Motion> \ [itcl::code $this _handMotionCB hour %x %y] watch bind hour <ButtonRelease-1> \ [itcl::code $this _handReleaseCB hour %x %y] watch bind second <B1-Motion> \ [itcl::code $this _handMotionCB second %x %y] watch bind second <ButtonRelease-1> \ [itcl::code $this _handReleaseCB second %x %y] $itk_component(am) configure -state normal $itk_component(pm) configure -state normal } elseif {$itk_option(-state) == "disabled"} { watch bind minute <B1-Motion> {} watch bind minute <ButtonRelease-1> {} watch bind hour <B1-Motion> {} watch bind hour <ButtonRelease-1> {} watch bind second <B1-Motion> {} watch bind second <ButtonRelease-1> {} $itk_component(am) configure -state disabled \ -disabledforeground [$itk_component(am) cget -background] $itk_component(pm) configure -state normal \ -disabledforeground [$itk_component(am) cget -background] } else { error "bad state option \"$itk_option(-state)\":\ should be normal or disabled" }}# ------------------------------------------------------------------# OPTION: showampm## Configure the display of the AM/PM radio buttons.# ------------------------------------------------------------------itcl::configbody ::iwidgets::Watch::showampm { switch -- $itk_option(-showampm) { 0 - no - false - off { pack forget $itk_component(am) pack forget $itk_component(pm) } 1 - yes - true - on { pack $itk_component(am) -side left -fill both -expand 1 pack $itk_component(pm) -side right -fill both -expand 1 } default { error "bad showampm option \"$itk_option(-showampm)\":\ should be boolean" } }}# ------------------------------------------------------------------# OPTION: pivotcolor## Configure the color of the clock pivot.#itcl::configbody ::iwidgets::Watch::pivotcolor { watch itemconfigure pivot -fill $itk_option(-pivotcolor)}# ------------------------------------------------------------------# OPTION: clockstipple## Configure the stipple pattern for the clock fill color.#itcl::configbody ::iwidgets::Watch::clockstipple { watch itemconfigure clock -stipple $itk_option(-clockstipple)}# ------------------------------------------------------------------# OPTION: clockcolor## Configure the color of the clock.#itcl::configbody ::iwidgets::Watch::clockcolor { watch itemconfigure clock -fill $itk_option(-clockcolor)}# ------------------------------------------------------------------# OPTION: hourcolor## Configure the color of the hour hand.#itcl::configbody ::iwidgets::Watch::hourcolor { watch itemconfigure hour -fill $itk_option(-hourcolor)}# ------------------------------------------------------------------# OPTION: minutecolor## Configure the color of the minute hand.#itcl::configbody ::iwidgets::Watch::minutecolor { watch itemconfigure minute -fill $itk_option(-minutecolor)}# ------------------------------------------------------------------# OPTION: secondcolor## Configure the color of the second hand.#itcl::configbody ::iwidgets::Watch::secondcolor { watch itemconfigure second -fill $itk_option(-secondcolor)}# ------------------------------------------------------------------# OPTION: tickcolor## Configure the color of the ticks.#itcl::configbody ::iwidgets::Watch::tickcolor { watch itemconfigure tick -outline $itk_option(-tickcolor)}# ------------------------------------------------------------------# OPTION: hourradius## Configure the radius of the hour hand.#itcl::configbody ::iwidgets::Watch::hourradius { _displayClock}# ------------------------------------------------------------------# OPTION: minuteradius## Configure the radius of the minute hand.#itcl::configbody ::iwidgets::Watch::minuteradius { _displayClock}# ------------------------------------------------------------------# OPTION: secondradius## Configure the radius of the second hand.#itcl::configbody ::iwidgets::Watch::secondradius { _displayClock}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -