/usr/share/tcltk/iwidgets4.0.1/scripts/spintime.itk is in iwidgets4 4.0.1-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | # Spintime
# ----------------------------------------------------------------------
# Implements a Time spinner widget. A time spinner contains three
# integer spinners: one for hours, one for minutes and one for
# seconds. Options exist to manage to behavior, appearance, and
# format of each component spinner.
#
# ----------------------------------------------------------------------
# AUTHOR: Sue Yockey EMAIL: yockey@actc.com
# Mark L. Ulferts mulferts@austin.dsccc.com
#
# @(#) $Id: spintime.itk,v 1.3 2001/08/17 19:04:45 smithc Exp $
# ----------------------------------------------------------------------
# Copyright (c) 1997 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.
# ======================================================================
#
# Default resources.
#
option add *Spintime.hourLabel "Hour" widgetDefault
option add *Spintime.minuteLabel "Minute" widgetDefault
option add *Spintime.secondLabel "Second" widgetDefault
option add *Spintime.hourWidth 3 widgetDefault
option add *Spintime.minuteWidth 3 widgetDefault
option add *Spintime.secondWidth 3 widgetDefault
#
# Usual options.
#
itk::usual Spintime {
keep -background -cursor -foreground -labelfont -textbackground -textfont
}
# ------------------------------------------------------------------
# SPINTIME
# ------------------------------------------------------------------
itcl::class iwidgets::Spintime {
inherit itk::Widget
constructor {args} {}
destructor {}
itk_option define -orient orient Orient vertical
itk_option define -labelpos labelPos Position w
itk_option define -houron hourOn HourOn true
itk_option define -minuteon minuteOn MinuteOn true
itk_option define -secondon secondOn SecondOn true
itk_option define -timemargin timeMargin Margin 1
itk_option define -militaryon militaryOn MilitaryOn true
public {
method get {{format "-string"}}
method show {{date now}}
}
protected {
method _packTime {{when later}}
method _down60 {comp}
variable _repack {} ;# Reconfiguration flag.
variable _interior
}
}
#
# Provide a lowercased access method for the Spintime class.
#
proc ::iwidgets::spintime {pathName args} {
uplevel ::iwidgets::Spintime $pathName $args
}
# ------------------------------------------------------------------
# CONSTRUCTOR
# ------------------------------------------------------------------
itcl::body iwidgets::Spintime::constructor {args} {
set _interior $itk_interior
set clicks [clock seconds]
#
# Create Hour Spinner
#
itk_component add hour {
iwidgets::Spinint $itk_interior.hour -fixed 2 -range {0 23} -justify right
} {
keep -background -cursor -arroworient -foreground \
-labelfont -labelmargin -relief -textbackground \
-textfont -repeatdelay -repeatinterval
rename -labeltext -hourlabel hourLabel Text
rename -width -hourwidth hourWidth Width
}
#
# Take off the default bindings for selction and motion.
#
bind [$itk_component(hour) component entry] <1> {break}
bind [$itk_component(hour) component entry] <Button1-Motion> {break}
#
# Create Minute Spinner
#
itk_component add minute {
iwidgets::Spinint $itk_interior.minute \
-decrement [itcl::code $this _down60 minute] \
-fixed 2 -range {0 59} -justify right
} {
keep -background -cursor -arroworient -foreground \
-labelfont -labelmargin -relief -textbackground \
-textfont -repeatdelay -repeatinterval
rename -labeltext -minutelabel minuteLabel Text
rename -width -minutewidth minuteWidth Width
}
#
# Take off the default bindings for selction and motion.
#
bind [$itk_component(minute) component entry] <1> {break}
bind [$itk_component(minute) component entry] <Button1-Motion> {break}
#
# Create Second Spinner
#
itk_component add second {
iwidgets::Spinint $itk_interior.second \
-decrement [itcl::code $this _down60 second] \
-fixed 2 -range {0 59} -justify right
} {
keep -background -cursor -arroworient -foreground \
-labelfont -labelmargin -relief -textbackground \
-textfont -repeatdelay -repeatinterval
rename -labeltext -secondlabel secondLabel Text
rename -width -secondwidth secondWidth Width
}
#
# Take off the default bindings for selction and motion.
#
bind [$itk_component(second) component entry] <1> {break}
bind [$itk_component(second) component entry] <Button1-Motion> {break}
#
# Initialize the widget based on the command line options.
#
eval itk_initialize $args
#
# Show the current time.
#
show now
}
# ------------------------------------------------------------------
# DESTRUCTOR
# ------------------------------------------------------------------
itcl::body iwidgets::Spintime::destructor {} {
if {$_repack != ""} {after cancel $_repack}
}
# ------------------------------------------------------------------
# OPTIONS
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# OPTION: -orient
#
# Specifies the orientation of the 3 spinners for Hour, Minute
# and second.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Spintime::orient {
_packTime
}
# ------------------------------------------------------------------
# OPTION: -labelpos
#
# Specifies the location of all 3 spinners' labels.
# Overloaded
# ------------------------------------------------------------------
itcl::configbody iwidgets::Spintime::labelpos {
switch $itk_option(-labelpos) {
n {
$itk_component(hour) configure -labelpos n
$itk_component(minute) configure -labelpos n
$itk_component(second) configure -labelpos n
#
# Un-align labels
#
$itk_component(hour) configure -labelmargin 1
$itk_component(minute) configure -labelmargin 1
$itk_component(second) configure -labelmargin 1
}
s {
$itk_component(hour) configure -labelpos s
$itk_component(minute) configure -labelpos s
$itk_component(second) configure -labelpos s
#
# Un-align labels
#
$itk_component(hour) configure -labelmargin 1
$itk_component(minute) configure -labelmargin 1
$itk_component(second) configure -labelmargin 1
}
w {
$itk_component(hour) configure -labelpos w
$itk_component(minute) configure -labelpos w
$itk_component(second) configure -labelpos w
}
e {
$itk_component(hour) configure -labelpos e
$itk_component(minute) configure -labelpos e
$itk_component(second) configure -labelpos e
#
# Un-align labels
#
$itk_component(hour) configure -labelmargin 1
$itk_component(minute) configure -labelmargin 1
$itk_component(second) configure -labelmargin 1
}
default {
error "bad labelpos option \"$itk_option(-labelpos)\",\
should be n, s, w or e"
}
}
_packTime
}
# ------------------------------------------------------------------
# OPTION: -houron
#
# Specifies whether or not to display the hour spinner.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Spintime::houron {
_packTime
}
# ------------------------------------------------------------------
# OPTION: -minuteon
#
# Specifies whether or not to display the minute spinner.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Spintime::minuteon {
_packTime
}
# ------------------------------------------------------------------
# OPTION: -secondon
#
# Specifies whether or not to display the second spinner.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Spintime::secondon {
_packTime
}
# ------------------------------------------------------------------
# OPTION: -timemargin
#
# Specifies the margin space between the hour and minute spinners
# and the minute and second spinners.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Spintime::timemargin {
_packTime
}
# ------------------------------------------------------------------
# OPTION: -militaryon
#
# Specifies 24-hour clock or 12-hour.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Spintime::militaryon {
set clicks [clock seconds]
if {$itk_option(-militaryon)} {
$itk_component(hour) configure -range {0 23}
$itk_component(hour) delete 0 end
$itk_component(hour) insert end [clock format $clicks -format "%H"]
} else {
$itk_component(hour) configure -range {1 12}
$itk_component(hour) delete 0 end
$itk_component(hour) insert end [clock format $clicks -format "%I"]
}
}
# ------------------------------------------------------------------
# METHODS
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# METHOD: get ?format?
#
# Get the value of the time spinner in one of two formats string or
# as an integer clock value using the -string and -clicks options
# respectively. The default is by string. Reference the clock
# command for more information on obtaining time and its formats.
# ------------------------------------------------------------------
itcl::body iwidgets::Spintime::get {{format "-string"}} {
set hour [$itk_component(hour) get]
set minute [$itk_component(minute) get]
set second [$itk_component(second) get]
switch -- $format {
"-string" {
return "$hour:$minute:$second"
}
"-clicks" {
return [clock scan "$hour:$minute:$second"]
}
default {
error "bad format option \"$format\":\
should be -string or -clicks"
}
}
}
# ------------------------------------------------------------------
# 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 time and its format.
# ------------------------------------------------------------------
itcl::body iwidgets::Spintime::show {{time "now"}} {
if {$time == "now"} {
set seconds [clock seconds]
} else {
if {[catch {clock format $time}] == 0} {
set seconds $time
} elseif {[catch {set seconds [clock scan $time]}] != 0} {
error "bad time: \"$time\", must be a valid time\
string, clock clicks value or the keyword now"
}
}
$itk_component(hour) delete 0 end
if {$itk_option(-militaryon)} {
scan [clock format $seconds -format "%H"] "%d" hour
} else {
scan hour [clock format $seconds -format "%I"] "%d" hour
}
$itk_component(hour) insert end $hour
$itk_component(minute) delete 0 end
scan [clock format $seconds -format "%M"] "%d" minute
$itk_component(minute) insert end $minute
$itk_component(second) delete 0 end
scan [clock format $seconds -format "%S"] "%d" seconds
$itk_component(second) insert end $seconds
return
}
# ------------------------------------------------------------------
# PROTECTED METHOD: _packTime ?when?
#
# Pack components of time 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.
# ------------------------------------------------------------------
itcl::body iwidgets::Spintime::_packTime {{when later}} {
if {$when == "later"} {
if {$_repack == ""} {
set _repack [after idle [itcl::code $this _packTime now]]
}
return
} elseif {$when != "now"} {
error "bad option \"$when\": should be now or later"
}
for {set i 0} {$i < 5} {incr i} {
grid rowconfigure $_interior $i -minsize 0
grid columnconfigure $_interior $i -minsize 0
}
if {$itk_option(-minuteon)} {
set minuteon 1
} else {
set minuteon 0
}
if {$itk_option(-secondon)} {
set secondon 1
} else {
set secondon 0
}
set _repack ""
switch $itk_option(-orient) {
vertical {
set row -1
if {$itk_option(-houron)} {
grid $itk_component(hour) -row [incr row] -column 0 \
-sticky nsew
} else {
grid forget $itk_component(hour)
}
if {$itk_option(-minuteon)} {
if {$itk_option(-houron)} {
grid rowconfigure $_interior [incr row] \
-minsize $itk_option(-timemargin)
}
grid $itk_component(minute) -row [incr row] -column 0 \
-sticky nsew
} else {
grid forget $itk_component(minute)
}
if {$itk_option(-secondon)} {
if {$minuteon || $secondon} {
grid rowconfigure $_interior [incr row] \
-minsize $itk_option(-timemargin)
}
grid $itk_component(second) -row [incr row] -column 0 \
-sticky nsew
} else {
grid forget $itk_component(second)
}
if {$itk_option(-labelpos) == "w"} {
iwidgets::Labeledwidget::alignlabels $itk_component(hour) \
$itk_component(minute) $itk_component(second)
}
}
horizontal {
set column -1
if {$itk_option(-houron)} {
grid $itk_component(hour) -row 0 -column [incr column] \
-sticky nsew
} else {
grid forget $itk_component(hour)
}
if {$itk_option(-minuteon)} {
if {$itk_option(-houron)} {
grid columnconfigure $_interior [incr column] \
-minsize $itk_option(-timemargin)
}
grid $itk_component(minute) -row 0 -column [incr column] \
-sticky nsew
} else {
grid forget $itk_component(minute)
}
if {$itk_option(-secondon)} {
if {$minuteon || $secondon} {
grid columnconfigure $_interior [incr column] \
-minsize $itk_option(-timemargin)
}
grid $itk_component(second) -row 0 -column [incr column] \
-sticky nsew
} else {
grid forget $itk_component(second)
}
#
# Un-align labels
#
$itk_component(hour) configure -labelmargin 1
$itk_component(minute) configure -labelmargin 1
$itk_component(second) configure -labelmargin 1
}
default {
error "bad orient option \"$itk_option(-orient)\", should\
be \"vertical\" or \"horizontal\""
}
}
}
# ------------------------------------------------------------------
# METHOD: down60
#
# Down arrow button press event. Decrement value in the minute
# or second entry.
# ------------------------------------------------------------------
itcl::body iwidgets::Spintime::_down60 {comp} {
set step [$itk_component($comp) cget -step]
set val [$itk_component($comp) get]
incr val -$step
if {$val < 0} {
set val [expr {60-$step}]
}
$itk_component($comp) delete 0 end
$itk_component($comp) insert 0 $val
}
|