# # Clock plugin for fubar # Shows current time and pops up calendar for current month # option add *Calenar.Label.Font -*-times-bold-r-normal--12-*-*-*-*-*-iso10646-1 widgetDefault option add *Calendar.Canvas.BoldFont -*-times-bold-r-normal--12-*-*-*-*-*-iso10646-1 widgetDefault option add *Calendar.Canvas.DateFont -*-times-medium-r-normal--12-*-*-*-*-iso10646-1 widgetDefault namespace eval clock { array set monthNames { 1 {января январь} 2 {февраля февраль} 3 {марта март} 4 {апреля апрель} 5 {мая май} 6 {июня июнь} 7 {июля июль} 8 {августа август} 9 {сентября сентябрь} 10 {октября октябрь} 11 {ноября ноябрь} 12 {декабря декабрь} } array set weekday { 0 {воскресенье red} 1 {понедельник black} 2 {вторник black} 3 {среда black} 4 {четверг black} 5 {пятница black} 6 {суббота red} } set weekDayAbbr {Вс Пн Вт Ср Чт Пт Сб} proc currentMonth {} { eval fill_calendar [clock format [clock seconds] -format "%m %Y"] } proc calendar {} { catch {destroy .calendar} popup .calendar -bd 3 -relief raised -class Calendar label .calendar.title -anchor n canvas .calendar.m -width 150 -height 120 grid .calendar.title - - -sticky news grid .calendar.m - - -sticky news .calendar.m bind date <1> {::clock::showEvents [::clock::getCalendarDate %x %y]} button .calendar.prev -text "<<" -command "::clock::other_month -1" button .calendar.next -text ">>" -command "::clock::other_month [expr 32*86400]" button .calendar.cur -text "Current" -command ::clock::currentMonth grid .calendar.prev .calendar.cur .calendar.next -sticky ns grid .calendar.prev -sticky nws grid .calendar.next -sticky nes eval fill_calendar [clock format [clock seconds] -format "%m %Y"] } proc other_month {offset} { variable firstOfMonth eval fill_calendar [clock format [expr {$firstOfMonth +$offset}] -format "%m %Y" -gmt y] } proc fill_calendar {month year} { variable firstOfMonth variable holydays variable weekDayAbbr variable monthNames variable weekday variable holydaysStamp global CONFIGDIR if {[file exist $CONFIGDIR/holydays]&& (![info exist holydaysStamp]|| [file mtime $CONFIGDIR/holydays]>$holydaysStamp)} { read_holydays } set month [string trimleft $month 0] set firstOfMonth [clock scan "$month/01/$year" -gmt y] set t $firstOfMonth set y 1 set x 25 set color red .calendar.m delete all foreach w $weekDayAbbr { #<=List of abbreviated weekdays here .calendar.m create text $x $y -anchor ne -text $w -fill $color \ -font [option get .calendar.m boldFont BoldFont] set color black incr x 19 } incr y 18 .calendar.title configure -text "[lindex $monthNames($month) 1] $year" for {set t $firstOfMonth} {[string trimleft \ [clock format $t -format "%m"] 0]==$month} {incr t 86400} { set day [clock format $t -format "%e" -gmt y] set wd [clock format $t -format "%w" -gmt y] set x [expr $wd*19+25] if {!$wd&&$day>1} { incr y 18 } if [info exist holydays([string trimleft $day]/$month)] { set color $holydays([string trimleft $day]/$month) } else { set color [lindex $weekday($wd) 1] } .calendar.m create text $x $y -anchor ne -text $day -fill $color \ -font [option get .calendar.m dateFont DateFont] -tags [list date d[string trimleft $day]] } if {"[string trimleft [clock format [clock seconds] -format "%m-%Y"] 0]" == "$month-$year"} { set box [.calendar.m bbox\ "d[string trimleft [clock format [clock seconds] -format "%d"] 0]" ] if [llength $box] { eval .calendar.m create rectangle $box -fill green -outline green -tags today .calendar.m lower today } } } proc getCalendarDate {x y} { variable firstOfMonth set dateId [.calendar.m find closest $x $y] set day [.calendar.m itemcget $dateId -text] return "[clock format $firstOfMonth -format %m]/$day/[clock format $firstOfMonth -format %y] [clock format [clock seconds] -format "%H:%M"]" } proc read_holydays {} { variable holydays variable holydaysStamp global CONFIGDIR if {![catch {open $CONFIGDIR/holydays} f]} { array set holydays [read $f] close $f } else { set holydaysStamp 0 exit } set holydaysStamp [file mtime $CONFIGDIR/holydays] } proc showtime {seconds} { variable TimeVar set TimeVar [clock format $seconds -format "%H:%M"] balloonhelp .clock [clock format $seconds] } proc showEvents {date} { if {![winfo exists .events]} { toplevel .events -class Calendar label .events.l -width 20 pack .events.l button .events.ok -text Ok -command {wm withdraw .events} pack .events.ok wm protocol .events WM_DELETE_WINDOW {wm withdraw .events} } .events.l configure -text $date } # # Setup # calendar catch {destroy .clock} catch {destroy .events} button .clock -textvar ::clock::TimeVar -width 7 -bd 1 -relief sunken\ -command {::clock::currentMonth show_popup .calendar .clock} balloonhelp .clock "Click to view calendar" pack .clock -side right -padx 5 showtime [clock seconds] notifier ::clock::showtime }