Debian Codegraph @

examples/calendar.tcl

raw
1 #!../src/bltwish
2
3 package require BLT
4
5 # --------------------------------------------------------------------------
6 # Starting with Tcl 8.x, the BLT commands are stored in their own
7 # namespace called "blt". The idea is to prevent name clashes with
8 # Tcl commands and variables from other packages, such as a "table"
9 # command in two different packages.
10 #
11 # You can access the BLT commands in a couple of ways. You can prefix
12 # all the BLT commands with the namespace qualifier "blt::"
13 #
14 # blt::graph .g
15 # blt::table . .g -resize both
16 #
17 # or you can import all the command into the global namespace.
18 #
19 # namespace import blt::*
20 # graph .g
21 # table . .g -resize both
22 #
23 # --------------------------------------------------------------------------
24
25 if { $tcl_version >= 8.0 } {
26 namespace import blt::*
27 namespace import -force blt::tile::*
28 }
29
30 #source scripts/demo.tcl
31
32 set file ../demos/images/chalk.gif
33 set active ../demos/images/rain.gif
34
35 image create photo calendar.texture.1 -file $file
36 image create photo calendar.texture.2 -file $active
37
38 option add *Tile calendar.texture.1
39
40 option add *HighlightThickness 0
41 option add *calendar.weekframe*Tile calendar.texture.2
42 option add *Calendar.Label.borderWidth 0
43 option add *Calendar.Label.relief sunken
44 option add *Calendar.Frame.borderWidth 2
45 option add *Calendar.Frame.relief raised
46 option add *Calendar.Label.font { Helvetica 11 }
47 option add *Calendar.Label.foreground navyblue
48 option add *button.foreground navyblue
49 option add *background grey85
50 #option add *button.activeForeground red
51 #option add *button.activeBackground blue4
52 option add *Label.ipadX 200
53
54 array set monthInfo {
55 Jan { January 31 }
56 Feb { February 28 }
57 Mar { March 31 }
58 Apr { April 30 }
59 May { May 31 }
60 Jun { June 30 }
61 Jul { July 31 }
62 Aug { August 31 }
63 Sep { September 30 }
64 Oct { October 31 }
65 Nov { November 30 }
66 Dec { December 31 }
67 }
68
69 option add *tile calendar.texture.2
70 set abbrDays { Sun Mon Tue Wed Thu Fri Sat }
71
72 proc Calendar { weekday day month year } {
73 global monthInfo abbrDays
74
75 set wkdayOffset [lsearch $abbrDays $weekday]
76 if { $wkdayOffset < 0 } {
77 error "Invalid week day \"$weekday\""
78 }
79 set dayOffset [expr ($day-1)%7]
80 if { $wkdayOffset < $dayOffset } {
81 set wkdayOffset [expr $wkdayOffset+7]
82 }
83 set wkday [expr $wkdayOffset-$dayOffset-1]
84 if { [info commands .calendar] == ".calendar" } {
85 destroy .calendar
86 }
87 frame .calendar -class Calendar -width 3i -height 3i
88
89 if ![info exists monthInfo($month)] {
90 error "Invalid month \"$month\""
91 }
92
93 set info $monthInfo($month)
94 label .calendar.month \
95 -text "[lindex $info 0] $year" \
96 -font { Courier 14 bold }
97 table .calendar .calendar.month 1,0 -cspan 7 -pady 10
98
99 set cnt 0
100 frame .calendar.weekframe -relief sunken -bd 1
101 table .calendar .calendar.weekframe 2,0 -columnspan 7 -fill both
102 foreach dayName $abbrDays {
103 set name [string tolower $dayName]
104 label .calendar.$name \
105 -text $dayName \
106 -font { Helvetica 12 }
107 table .calendar .calendar.$name 2,$cnt -pady 2 -padx 2
108 incr cnt
109 }
110 table configure .calendar c* r2 -pad 4
111 set week 0
112 set numDays [lindex $info 1]
113 for { set cnt 1 } { $cnt <= $numDays } { incr cnt } {
114 label .calendar.day${cnt} -text $cnt
115 if { $cnt == $day } {
116 .calendar.day${cnt} configure -relief sunken -bd 1
117 }
118 incr wkday
119 if { $wkday == 7 } {
120 incr week
121 set wkday 0
122 }
123 table .calendar .calendar.day${cnt} $week+3,$wkday \
124 -fill both -ipadx 10 -ipady 4
125 }
126 frame .calendar.quit -bd 1 -relief sunken
127 button .calendar.quit.button -command { exit } -text {Quit} -bd 2
128 table .calendar.quit \
129 .calendar.quit.button -padx 4 -pady 4
130 table .calendar \
131 .calendar.quit $week+4,5 -cspan 2 -pady 4
132 table . \
133 .calendar -fill both
134 table configure .calendar r0 -resize none
135 table configure .calendar c0 c6
136 }
137
138 set date [clock format [clock seconds] -format {%a %b %d %Y}]
139 scan $date { %s %s %d %d } weekday month day year
140
141 Calendar $weekday $day $month $year