My popup "Date Entry" widget with msgcat

Hi, this piece of code is a part of my software. Its a little "date picker" or "date entry" widget, Im not sure about a name :), so lets say its simple popup "Date Entry" I used to use great An i15d date chooser widget, but I wanted some extra stuff, so I came up with this one. In the future I want to add some extra stuff like in Date Picker - jQuery (unfortunately I cant do it right now, too busy looking for work :()

So what you can do with it:

  • you can use it (of course :))
  • you can configure personalized colors, font size and fonts type (to fit outlook of your own software)
  • you can use msgcat package to translate it (no need if you want it in English, Im posting Portuguese translation file, if you want to use it create folder lang copy it inside under name pt.msg)
  • you can set start of the week (Monday or Sunday, see code)

In the future, you should be able to see 3 months, 1 year calendar, select period of time. (If you can do it, please post a copy, so i can include in my software :))

How to use it:

  1. Create your entry widget
  2. Create your button
  3. Call ::DATE::my_popup_Cal name_of_your_entry_widget proc from -command (see code)

You can send a configuration dictionary to ::DATE::my_popup_Cal proc, possible keys are:

result_format - Any format groups recognized by the clock format command. (see code) week_start - Possible values are: Monday and Sunday (default is Monday)

That is all!

#!/bin/sh
# main.tcl \
exec tclsh "$0" ${1+"[email protected]"}

package require Tk




namespace eval DATE {

#######################################################################################################
#  Set variables. Configure your stuff here
#######################################################################################################

set ::DATE::back_weekdays #00b70d                                        ;# Background color of day of the week

set ::DATE::back_days grey80                                                ;# Background color of days in the month
set ::DATE::back_pointer grey90                                                ;# Color of background highlighting

set ::DATE::fontcol_today blue                                                ;# Font color of today
set ::DATE::fontcol_year blue                                                ;# Font color of year
set ::DATE::fontcol_month blue                                                ;# Font color of month
set ::DATE::fontcol_days grey40                                                ;# Font color of normal days
set ::DATE::fontcol_sunday #ff0099                                        ;# Font color of sunday
set ::DATE::fontcol_saturday #ff1239                                        ;# Font color of saturday

set ::DATE::font_year {Helvetica 14}                                        ;# Font type and size of year frame
set ::DATE::font_month {Helvetica 10}                                        ;# Font type and size of month frame
set ::DATE::font_days {Helvetica 9}                                        ;# Font type and size of dyas frame


set ::DATE::sel_month [clock format [clock scan now] -format "%m"]
set ::DATE::sel_year [clock format [clock scan now] -format "%Y"]
set ::DATE::months [dict create 1 January 2 February 3 March 4 April 5 May 6 June 7 July 8 August 9 September 10 October 11 November 12 December]

set ::DATE::sundayWeek {"Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"}
set ::DATE::mondayWeek {"Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"}
#######################################################################################################
#  Images
#######################################################################################################

set left [image create photo -data {
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlw
SFlzAAAK8AAACvABQqw0mAAAABh0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzT7MfTgAA
AuNJREFUSIntVU1IVFEYPd+kUjZpE1pg2a+LssBJStqYkk1lq1yXFo2TVpCQLazGhNKVtHBU
hIpQCgINrCnHWlXODEFhYxZl0QTVM8taSL6ZnHnv3q+F8xORQaEQ1IUD9913+c45953vXWJm
zOQwzGj1/wTTRpBrXr+SiFL/iIGZp8TateuyBgYed4TD2piiDA9UHana+Kv9P8PPF4HZ3d3X
jqqqOjo09ILt9lP8yOdjv/917+8SJPzoyH6y1qIow6eTk+dsam/vQFfXVXz+/Anp6Wk4YLOt
bnI0ly1auFCTQhiklBQ9BYDIMItw787doXMXzj+M1qNoo2VkLF7mdDrt2dlrrG6Ph9pa26AM
DyM1JQXBYBDFO4tRWVmBiVAILCMKEVcqJcNABJPJFO7v72/bts1SzcyCmBmHDx0222trnePq
eKajqRkejwdz5yYjKSkJYIDBICIYyABQTBuA+F+AGRBCR25uLmqO1+B27y1r2d6yi7OICBUH
K1v8fv+m/fv2Q1HeYZ7RCCKCkBJSSrCUEEJA0zTouh7B93MdQtMhJcPne4TMzKUoKCxMtNls
VxIAIBQKBxKTEiF0HVIQNE2LyEJMMTODJccdfPcu7okQDoWh6zqIyKCqKgx1dXWwnzhRv2L5
Cn/n1S7k5OTg44cPCAaC0IU+qTqiXAgBGYWUkEJGnicdhkIT2GqxYPuOHXC73d0ul4tjH3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hRJOSpk6gzJzoFFKYVlWIkQSElpWHCMrCwB3rhtvSwubajfx7q73KCws
5CGPh5kzb6fhrbeIxWLY7XaUtFBa35gDIWTS88ynabPR/dMZjh8/wYXz54lGImxcv4E2bytr
nngCgBeee56vv/qKnOzs9D6tVDoHZlKemM1mIxqJoPLyUsc2ToeDUz+eZO2TT+JwOMh1uwkE
AtTX1eF0OonHYgghcOfmYlkWQohEP2iNMAyRn59vmQCnfzzV5anw1BSXlNDX24vdbifTNJpo
JHLd3GQSPNUjAJZlkX9HAUuXLuVcf/+JkZERJbTWCCFyurt/bp0+Y8byw+3thEMhDCOtHul4
U6WRMZVZhXa7jUeXLCXLMLofW7as8jf/4JhIySGEyG1ta3tx4cIHVhhZRl6ifG781eo0euZd
IemkobWO9PX2Hq2sfKxJaz0GkCZImUjEfb1G/94srbW8Du//vrb8Cfk3BWpw3nPLAAAAAElF
TkSuQmCC}]

#######################################################################################################
#  Procedures
#######################################################################################################


proc ::DATE::check_config {{userDict 0}} {
        set ::DATE::default_config_values [dict create result_format "%d-%m-%Y" calendars "1" start_date [clock scan now] week_start Monday]
        if {$userDict == 0} {
                foreach j [dict keys $::DATE::default_config_values] i [dict values $::DATE::default_config_values] {
                        set ::DATE::$j $i
                }
        } else {
                foreach j [dict keys $::DATE::default_config_values] {
                        if {[dict exists $userDict $j] == 1} {
                                set ::DATE::$j [dict get $userDict $j]
                        } else {
                                set ::DATE::$j [dict get $::DATE::default_config_values $j]
                        }
                }
        }
}

proc ::DATE::close {} {
        destroy $::DATE::w
}

proc ::DATE::get_monthname {months num} {
        set trimmed [string trimleft $num 0]
        return [dict get $months $num]
}

proc ::DATE::plus {} {
        set ::DATE::sel_month "[expr $::DATE::sel_month + 1]"
        if {$::DATE::sel_month == 13} {
                set ::DATE::sel_month 1
                set ::DATE::sel_year [expr $::DATE::sel_year + 1]
        }
        ::DATE::update_month
        ::DATE::update_year
        ::DATE::update_days
}

proc ::DATE::minus {} {
        set ::DATE::sel_month "[expr $::DATE::sel_month - 1]"
        if {$::DATE::sel_month == 0} {
                set ::DATE::sel_month 12
                set ::DATE::sel_year [expr $::DATE::sel_year - 1]
        }
        ::DATE::update_month
        ::DATE::update_year
        ::DATE::update_days
}

proc ::DATE::plus_year {} {
        set ::DATE::sel_year [expr $::DATE::sel_year + 1]
        ::DATE::update_year
        ::DATE::update_days
}

proc ::DATE::minus_year {} {
        set ::DATE::sel_year [expr $::DATE::sel_year - 1]
        ::DATE::update_year
        ::DATE::update_days
}
 
proc ::DATE::update_month {} {
        $::DATE::a configure -text "[::msgcat::mc "[get_monthname $::DATE::months $::DATE::sel_month]"]"
}

proc ::DATE::update_year {} {
        global b
        $::DATE::b configure -text "$::DATE::sel_year"
}

proc ::DATE::days_in_month {month year} {
        if {$month==12} {set month 1; incr year}
        return [clock format [clock scan "[incr month]/1/$year  1 day ago"] -format %d]
}

proc ::DATE::day_weekday {day month year} {
        return [clock format [clock scan $month/$day/$year] -format %u]
}

proc ::DATE::today_color {day month year} {
        if {[string trimleft [clock format [clock scan now] -format "%d"] 0] == $day} {
                return $::DATE::fontcol_today
        } elseif {[clock format [clock scan $month/$day/$year] -format "%u"] == 7} {
                return $::DATE::fontcol_sunday
        } elseif {[clock format [clock scan $month/$day/$year] -format "%u"] == 6} {
                return $::DATE::fontcol_saturday
        } else {
                return $::DATE::fontcol_days
        }
}

proc ::DATE::hightlight {widget} {
        bind $widget <Any-Enter> {
                %W configure -background $::DATE::back_pointer
                update
        }
                
        bind $widget <Any-Leave> {
                %W configure -background $::DATE::back_days
                update
        } 
}

proc ::DATE::update_days {} {
        destroy $::DATE::days
        set days [frame $::DATE::main.days -background $::DATE::back_days]
        grid $::DATE::days -column 0 -row 2
        if {$::DATE::week_start == "Sunday"} {
                set startcol [expr [day_weekday 1 $::DATE::sel_month $::DATE::sel_year] + 1]
                if {$startcol == 8} {set startcol 1}
        } else {
                set startcol [day_weekday 1 $::DATE::sel_month $::DATE::sel_year]
        }
        set startrow 1
                for {set x 1} {$x <= [days_in_month $::DATE::sel_month $::DATE::sel_year]} {incr x} {
                        set a [label $::DATE::days.day$x -text "$x" -width 1 -justify center -anchor center -width 4 -font $::DATE::font_days -foreground [today_color $x $::DATE::sel_month $::DATE::sel_year] -textvariable "$x $::DATE::sel_month $::DATE::sel_year" -background $::DATE::back_days ]
                        grid $::DATE::days.day$x -column $startcol -row $startrow
                        ::DATE::hightlight $::DATE::days.day$x
                        incr startcol
                        if {$startcol == 8} {set startcol 1; incr startrow}
                }
}

proc ::DATE::format_result {sent} {
        set tmp [clock scan $sent -format {%d %m %Y}]
        set result [clock format $tmp -format $::DATE::result_format]
        ::DATE::update_entry $result
}

proc update_entry {result} {
        global userEntry
        $userEntry delete 0 end
        $userEntry insert 0 $result
}

proc ::DATE::my_popup_Cal {userEntry {userDict 0}} {
        set ::userEntry $userEntry
        ::DATE::check_config $userDict
        if {[winfo exists .d] == "1"} {::DATE::close}
        set ::DATE::w [toplevel .d]
        wm overrideredirect $::DATE::w 1
        lassign [winfo pointerxy .] x y
        wm geometry $::DATE::w "+${x}+${y}"

        grid [set ::DATE::main [frame $::DATE::w.f -borderwidth 1 -relief solid -takefocus 1]] -column 0 -row 0

        set ::DATE::month [frame $::DATE::main.month]
        set ::DATE::weekday [frame $::DATE::main.weekday]
        set ::DATE::days [frame $::DATE::main.days -background $::DATE::back_days]
        set ::DATE::year [frame $::DATE::main.year]

        grid $::DATE::month -column 0 -row 0
        grid $::DATE::weekday -column 0 -row 1
        grid $::DATE::days -column 0 -row 2
        grid $::DATE::year -column 0 -row 3


        button $::DATE::month.p -text "<" -relief flat -width 1 -command "::DATE::minus" -image $::DATE::left -width 18
        button $::DATE::month.n -text ">" -relief flat -width 1 -command "::DATE::plus" -image $::DATE::right -width 18
        set ::DATE::a [ttk::label $::DATE::month.month_name -text "[::msgcat::mc "[get_monthname $::DATE::months $::DATE::sel_month]"]" -width 20 -justify center -anchor center -font $::DATE::font_month -foreground $::DATE::fontcol_month]

        if {$::DATE::week_start == "Sunday"} {
                set weekday_list $::DATE::sundayWeek
        } else {
                set weekday_list $::DATE::mondayWeek

        }

        foreach j $weekday_list i {1 2 3 4 5 6 7} {
                ttk::label $::DATE::weekday.wday$i -text "[::msgcat::mc "$j"]" -width 4 -justify center -anchor center -background $::DATE::back_weekdays -font $::DATE::font_days
                grid $::DATE::weekday.wday$i -column $i -row 1
        }

        button $::DATE::year.p -text "<<" -relief flat -width 1 -command "::DATE::minus_year" -image $::DATE::down -width 14
        button $::DATE::year.n -text ">>" -relief flat -width 1 -command "::DATE::plus_year" -image  $::DATE::up -width 14
        set ::DATE::b [ttk::label $::DATE::year.year_name -text "$::DATE::sel_year" -width 10 -justify center -anchor center -font $::DATE::font_year -foreground $::DATE::fontcol_year]



        grid $::DATE::month.p -column 0 -row 0
        grid $::DATE::month.month_name -column 1 -row 0 -columnspan 5
        grid $::DATE::month.n -column 6 -row 0

        grid $::DATE::year.p -column 0 -row 5
        grid $::DATE::year.year_name -column 1 -row 5 -columnspan 5
        grid $::DATE::year.n -column 6 -row 5

        update_days

        bind $::DATE::w <ButtonRelease> {
                grab release [grab current]
                set what [winfo containing %X %Y]
                winfo class [winfo containing %X %Y]
                if {[winfo class [winfo containing %X %Y]] == "Label"} {
                        ::DATE::format_result [$what cget -textvariable]
                        ::DATE::close
                }
        }

}

}


#######################################################################################################
#  Example 
#######################################################################################################




#######################################################################################################
#  Load Translations
#######################################################################################################
# msgcat::mclocale pt
# msgcat::mcload [file join [file dirname [info script]] lang]




pack [frame .m]
pack [ttk::label .m.l -text "Chose a day:"] -side left
pack [ttk::entry .m.datae] -padx 10 -side left
pack [ttk::button .m.button -image $::DATE::calendar -command {::DATE::my_popup_Cal .m.datae}] -padx 5 -side right


pack [frame .n]
pack [ttk::label .n.l -text "Chose a day:"] -side left
pack [ttk::entry .n.datae] -padx 10 -side left
set config [dict create result_format "%Y/%m/%d, %A" week_start Sunday]
pack [ttk::button .n.button -image $::DATE::calendar -command {::DATE::my_popup_Cal .n.datae $config}] -padx 5 -side right



Siqsuruq - 2011-10-09 16:57:47

I forgot screenshots :) https://sites.google.com/a/msysc.org/intranet/1.png https://sites.google.com/a/msysc.org/intranet/2.png

  use clock for local month and weekday names

HaO 2013-09-27: Even if this page is called "Using msgcat", one may use the clock package to get localized day and month names:

Abreviated weekday name:

clock format [clock scan $dayCur -format %w] -format "%a" -locale [msgcat::mclocale]

Month name:

clock format [clock scan ${monthCur}-1 -format %m-%d] -format "%B" -locale [msgcat::mclocale]

Great widget!

  Addition to [tG²]

SeS 29th Oct 2015

Hi, I have included this widget as a plugin wrapper to tG², user is able to pick and place this widget with the Layout Editor interface, set the label & entry as visible or not, set the font and some more parameters, easy as 1, 2, 3. Custom defined "plugin wrapper" is a new concept & implementation for tG², not yet released.

Thank you, and obviously, referred in the plugin wrapper to this wiki page and author.

  Found bug in proc ::DATE::get_monthname

SeS 9th Feb 2016

The following I have observed using a wish console created with tcl/tk v8.4.19 with package dict v8.5.3.1. When I activate the date picker with the icon, I get the following error:

  key "02" not known in dictionary
  key "02" not known in dictionary
      while executing
  "dict get $months $num"
      (procedure "get_monthname" line 3)
      invoked from within
  "get_monthname $::DATE::months $::DATE::sel_month"
      (procedure "::DATE::my_popup_Cal" line 26)

It seems, the '0' preceding the '2' (reference to current month, February) is the cause of the error. The way I fixed this is as following:

  proc ::DATE::get_monthname {months num} {
    set trimmed [string trimleft $num 0]
    return [dict get $months [string trimleft $num 0]]
  }

Happy with the solution, didn't bother to check if error is maybe depending on the specific combination of tcl/tk & dict versions that I use...