2 # Clock plugin for fubar
3 # Shows current time and pops up calendar for current month
6 option add *Calenar.Label.Font -*-times-bold-r-normal--12-*-*-*-*-*-iso10646-1 widgetDefault
7 option add *Calendar.Canvas.BoldFont -*-times-bold-r-normal--12-*-*-*-*-*-iso10646-1 widgetDefault
8 option add *Calendar.Canvas.DateFont -*-times-medium-r-normal--12-*-*-*-*-iso10646-1 widgetDefault
10 array set monthNames {
33 set weekDayAbbr {÷Ó ðÎ ÷Ô óÒ þÔ ðÔ óÂ}
34 proc currentMonth {} {
35 eval fill_calendar [clock format [clock seconds] -format "%m %Y"]
38 catch {destroy .calendar}
39 popup .calendar -bd 3 -relief raised -class Calendar
40 label .calendar.title -anchor n
41 canvas .calendar.m -width 150 -height 120
42 grid .calendar.title - - -sticky news
43 grid .calendar.m - - -sticky news
44 .calendar.m bind date <1> {::clock::showEvents [::clock::getCalendarDate %x %y]}
45 button .calendar.prev -text "<<" -command "::clock::other_month -1"
46 button .calendar.next -text ">>" -command "::clock::other_month [expr 32*86400]"
47 button .calendar.cur -text "Current" -command ::clock::currentMonth
48 grid .calendar.prev .calendar.cur .calendar.next -sticky ns
49 grid .calendar.prev -sticky nws
50 grid .calendar.next -sticky nes
51 eval fill_calendar [clock format [clock seconds] -format "%m %Y"]
54 proc other_month {offset} {
56 eval fill_calendar [clock format [expr {$firstOfMonth +$offset}] -format "%m %Y" -gmt y]
59 proc fill_calendar {month year} {
65 variable holydaysStamp
67 if {[file exist $CONFIGDIR/holydays]&&
68 (![info exist holydaysStamp]||
69 [file mtime $CONFIGDIR/holydays]>$holydaysStamp)} {
72 set month [string trimleft $month 0]
73 set firstOfMonth [clock scan "$month/01/$year" -gmt y]
79 .calendar.m delete all
80 foreach w $weekDayAbbr { #<=List of abbreviated weekdays here
81 .calendar.m create text $x $y -anchor ne -text $w -fill $color \
82 -font [option get .calendar.m boldFont BoldFont]
87 .calendar.title configure -text "[lindex $monthNames($month) 1] $year"
88 for {set t $firstOfMonth} {[string trimleft \
89 [clock format $t -format "%m"] 0]==$month} {incr t 86400} {
90 set day [clock format $t -format "%e" -gmt y]
91 set wd [clock format $t -format "%w" -gmt y]
92 set x [expr $wd*19+25]
93 if {!$wd&&$day>1} { incr y 18 }
94 if [info exist holydays([string trimleft $day]/$month)] {
95 set color $holydays([string trimleft $day]/$month)
97 set color [lindex $weekday($wd) 1]
99 .calendar.m create text $x $y -anchor ne -text $day -fill $color \
100 -font [option get .calendar.m dateFont DateFont] -tags [list date d[string trimleft $day]]
102 if {"[string trimleft [clock format [clock seconds] -format "%m-%Y"] 0]"
104 set box [.calendar.m bbox\
105 "d[string trimleft [clock format [clock seconds] -format "%d"] 0]" ]
107 eval .calendar.m create rectangle $box -fill green -outline green -tags today
108 .calendar.m lower today
114 proc getCalendarDate {x y} {
115 variable firstOfMonth
116 set dateId [.calendar.m find closest $x $y]
117 set day [.calendar.m itemcget $dateId -text]
118 return "[clock format $firstOfMonth -format %m]/$day/[clock format $firstOfMonth -format %y] [clock format [clock seconds] -format "%H:%M"]"
120 proc read_holydays {} {
122 variable holydaysStamp
124 if {![catch {open $CONFIGDIR/holydays} f]} {
125 array set holydays [read $f]
131 set holydaysStamp [file mtime $CONFIGDIR/holydays]
134 proc showtime {seconds} {
136 set TimeVar [clock format $seconds -format "%H:%M"]
137 balloonhelp .clock [clock format $seconds]
140 proc showEvents {date} {
141 if {![winfo exists .events]} {
142 toplevel .events -class Calendar
143 label .events.l -width 20
145 button .events.ok -text Ok -command {wm withdraw .events}
147 wm protocol .events WM_DELETE_WINDOW {wm withdraw .events}
149 .events.l configure -text $date
156 catch {destroy .clock}
157 catch {destroy .events}
158 button .clock -textvar ::clock::TimeVar -width 7 -bd 1 -relief sunken\
159 -command {::clock::currentMonth
160 show_popup .calendar .clock}
161 balloonhelp .clock "Click to view calendar"
162 pack .clock -side right -padx 5
163 showtime [clock seconds]
164 notifier ::clock::showtime