⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spindate.itk

📁 这是一个Linux下的集成开发环境
💻 ITK
📖 第 1 页 / 共 2 页
字号:
	    } elseif {$itk_option(-monthformat) == "full"} {	$itk_component(month) configure -width 9 -fixed 9	$itk_component(month) delete 0 end	$itk_component(month) insert 0 [clock format $clicks -format "%B"]	set _monthFormatStr "%B"	    } elseif {$itk_option(-monthformat) == "integer"} {	$itk_component(month) configure -width 2 -fixed 2 	$itk_component(month) delete 0 end	$itk_component(month) insert 0 [clock format $clicks -format "%m"]	set _monthFormatStr "%m"	    } else {	error "bad monthformat option\		\"$itk_option(-monthformat)\", should be\		\"integer\", \"brief\" or \"full\""    }}# ------------------------------------------------------------------#                            METHODS# ------------------------------------------------------------------# ------------------------------------------------------------------# METHOD: get ?format?## Return the current contents of the spindate widget 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 dates # and their formats.# ------------------------------------------------------------------body iwidgets::Spindate::get {{format "-string"}} {     set month [$itk_component(month) get]    set day [$itk_component(day) get]    set year [$itk_component(year) get]    if {[regexp {[0-9]+} $month]} {	set datestr "$month/$day/$year"    } else {	set datestr "$day $month $year"    }    switch -- $format {	"-string" {	    return $datestr	}	"-clicks" {	    return [clock scan $datestr]	}	default {	    error "bad format option \"$format\":\                   should be -string or -clicks"	}    }}# ------------------------------------------------------------------# PUBLIC METHOD: show date## Changes the currently displayed date to be that of the date # argument.  The date may be specified either as a string or an# integer clock value.  Reference the clock command for more # information on obtaining dates and their formats.# ------------------------------------------------------------------body iwidgets::Spindate::show {{date "now"}} {    #    # Convert the date to a clock clicks value.    #    if {$date == "now"} {	set seconds [clock seconds]    } else {	if {[catch {clock format $date}] == 0} {	    set seconds $date	} elseif {[catch {set seconds [clock scan $date]}] != 0} {	    error "bad date: \"$date\", must be a valid date\               string, clock clicks value or the keyword now"	}    }    #    # Display the month based on the -monthformat option.    #    switch $itk_option(-monthformat) {	"brief" {	    $itk_component(month) delete 0 end	    $itk_component(month) insert 0 [clock format $seconds -format "%b"]	}		"full" {	    $itk_component(month) delete 0 end	    $itk_component(month) insert 0 [clock format $seconds -format "%B"]	}		"integer" {	    $itk_component(month) delete 0 end	    $itk_component(month) insert 0 [clock format $seconds -format "%m"]	}    }    #    # Display the day.    #    $itk_component(day) delete 0 end    $itk_component(day) insert end [clock format $seconds -format "%d"]    #    # Display the year based on the -yeardigits option.    #    switch $itk_option(-yeardigits) {	"2" {	    $itk_component(year) delete 0 end	    $itk_component(year) insert 0 [clock format $seconds -format "%y"]	}		"4" {	    $itk_component(year) delete 0 end	    $itk_component(year) insert 0 [clock format $seconds -format "%Y"]	}    }    return}# ----------------------------------------------------------------# PRIVATE METHOD: _spinMonth direction## Increment or decrement month value.  We need to get the values# for all three fields so we can make sure the day agrees with# the month.  Should the current day be greater than the day for# the spun month, then the day is set to the last day for the# new month.# ----------------------------------------------------------------body iwidgets::Spindate::_spinMonth {direction} {    set month [$itk_component(month) get]    set day [$itk_component(day) get]    set year [$itk_component(year) get]    #    # There appears to be a bug in the Tcl clock command in that it    # can't scan a date like "12/31/1999 1 month" or any other date with    # a year above 2000, but it has no problem scanning "07/01/1998 1 month".    # So, we're going to play a game and increment by days until this    # is fixed in Tcl.    #    if {$direction == 1} {	set incrdays 32	set day 01    } else {	set incrdays -28	set day 28    }    if {[regexp {[0-9]+} $month]} {	set clicks [clock scan "$month/$day/$year $incrdays day"]    } else {	set clicks [clock scan "$day $month $year $incrdays day"]    }    $itk_component(month) clear    $itk_component(month) insert 0 \	[clock format $clicks -format $_monthFormatStr]    set lastday [_lastDay [$itk_component(month) get] $year]    if {$day > $lastday} {	$itk_component(day) clear	$itk_component(day) insert end $lastday    }}# ----------------------------------------------------------------# PRIVATE METHOD: _spinDay direction## Increment or decrement day value.  If the previous day was the# first, then set the new day to the last day for the current# month.  If it was the last day of the month, change it to the# first.  Otherwise, spin it to the next day.# ----------------------------------------------------------------body iwidgets::Spindate::_spinDay {direction} {    set month [$itk_component(month) get]    set day [$itk_component(day) get]    set year [$itk_component(year) get]    set lastday [_lastDay $month $year]    set currclicks [get -clicks]    $itk_component(day) delete 0 end    if {(($day == "01") || ($day == "1")) && ($direction == -1)} {	$itk_component(day) insert 0 $lastday        return    }    if {($day == $lastday) && ($direction == 1)} {	$itk_component(day) insert 0 "01"        return    }    set clicks [clock scan "$direction day" -base $currclicks]    $itk_component(day) insert 0 [clock format $clicks -format "%d"]}# ------------------------------------------------------------------# PRIVATE METHOD: _packDate when## Pack the components of the date 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::Spindate::_packDate {{when later}} {    if {$when == "later"} {	if {$_repack == ""} {	    set _repack [after idle [code $this _packDate now]]	}	return    } elseif {$when != "now"} {	error "bad option \"$when\": should be now or later"    }    #    # Turn off the minsizes for all the rows and columns.      #    for {set i 0} {$i < 5} {incr i} {	grid rowconfigure $_interior $i -minsize 0	grid columnconfigure $_interior $i -minsize 0    }    set _repack ""    #    # Based on the orientation, use the grid to place the components into    # the proper rows and columns.    #    switch $itk_option(-orient) {	vertical {	    set row -1	    	    if {$itk_option(-monthon)} {		grid $itk_component(month) -row [incr row] -column 0 \		    -sticky nsew 	    } else {		grid forget $itk_component(month)	    }	    	    if {$itk_option(-dayon)} {		if {$itk_option(-dayon)} {		    grid rowconfigure $_interior [incr row] \			-minsize $itk_option(-datemargin)		}		grid $itk_component(day) -row [incr row] -column 0 \		    -sticky nsew 	    } else {		grid forget $itk_component(day)	    }	    	    if {$itk_option(-yearon)} {		if {$itk_option(-monthon) || $itk_option(-dayon)} {		    grid rowconfigure $_interior [incr row] \			-minsize $itk_option(-datemargin)		}		grid $itk_component(year) -row [incr row] -column 0 \		    -sticky nsew 	    } else {		grid forget $itk_component(year)	    }	    	    if {$itk_option(-labelpos) == "w"} {		iwidgets::Labeledwidget::alignlabels $itk_component(month) \			$itk_component(day) $itk_component(year)	    }	}		horizontal {	    set column -1	    if {$itk_option(-monthon)} {		grid $itk_component(month) -row 0 -column [incr column] \		    -sticky nsew 	    } else {		grid forget $itk_component(month)	    }	    	    if {$itk_option(-dayon)} {		if {$itk_option(-monthon)} {		    grid columnconfigure $_interior [incr column] \			-minsize $itk_option(-datemargin)		}		grid $itk_component(day) -row 0 -column [incr column] \		    -sticky nsew 	    } else {		grid forget $itk_component(day)	    }	    	    if {$itk_option(-yearon)} {		if {$itk_option(-monthon) || $itk_option(-dayon)} {		    grid columnconfigure $_interior [incr column] \			-minsize $itk_option(-datemargin)		}		grid $itk_component(year) -row 0 -column [incr column] \		    -sticky nsew 	    } else {		grid forget $itk_component(year)	    }	    	    #	    # Un-align labels.	    #	    $itk_component(month) configure -labelmargin 1	    $itk_component(day) configure -labelmargin 1	    $itk_component(year) configure -labelmargin 1	}		default {	    error "bad orient option \"$itk_option(-orient)\", should\		    be \"vertical\" or \"horizontal\""	}     }} # ------------------------------------------------------------------# PRIVATE METHOD: _lastDay month year## Internal method which determines the last day of the month for# the given month and year.  We start at 28 and go forward till# we fail.  Crude but effective.# ------------------------------------------------------------------body iwidgets::Spindate::_lastDay {month year} {    set lastone 28    for {set lastone 28} {$lastone < 32} {incr lastone} {	if {[regexp {[0-9]+} $month]} {	    if {[catch {clock scan "$month/[expr $lastone + 1]/$year"}] != 0} {		return $lastone	    }	} else {	    if {[catch {clock scan "[expr $lastone + 1] $month $year"}] != 0} {		return $lastone	    }	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -