Gtk2 Simple Calendar/ Date Selector
zentara
created: 2006-02-01 18:11:38
This just is just a useful little utility to find the day/date/week number etc. for any date. It is all included in the Gtk2::Calendar widget. It scrolls thru months, and years. I havn't tested it's limits, but it goes ahead many centuries, and will go to B.C. as negative years. Handy for archeologists. :-)
#!/usr/bin/perl 
use warnings;
use strict;
use Gtk2 -init;

#if you want to adjust colors, otherwise comment out
Gtk2::Rc->parse_string(<<__);
style "calendar"
{
bg[NORMAL] = "#aadddd"  #background of header bar
bg[SELECTED] = "#ff0000" #color of weekday bg when window is moved
bg[PRELIGHT] = "#ccffff" #color of bg of selector-scroller triangles for month/year

fg[NORMAL] = "#000000"   #text for days(active) and header
fg[PRELIGHT] = "#ff0000" #color of fg of selector-scroller triangles for month/year

# For the selected item 
base[NORMAL]    = "#ffffff"  #background  of dates display
base[SELECTED]  = "#99aaaa"  #background of weekday names and days
base[ACTIVE]    = "#999999"  #selected color when active
base[PRELIGHT]  = "#0000ff"  #selected color when active

}class "*Calendar*" style "calendar"
__
##############################################################
#adjust font
my $font = Gtk2::Pango::FontDescription->from_string("Sans Bold 24");

my $window = Gtk2::Window -> new("toplevel");
$window -> set_title ("Simple Calendar");
$window -> signal_connect (delete_event => sub { Gtk2 -> main_quit(); });

my $calendar = Gtk2::Calendar -> new();

$calendar->signal_connect( 'day_selected_double_click' => sub {
	     my ($year, $month, $day) = $calendar->get_date; 
             printf("%02d/%d/%d\n", $month+1, $day, $year);
	     });

#will show headings and day names by default, but must
#declare them manually if adding week numbers
$calendar->set_display_options(['show-week-numbers','show-heading','show-day-names'] );
$calendar->modify_font($font);

$window -> add($calendar);
$window -> show_all();
Gtk2 -> main();

perlmonks.org content © perlmonks.org and zentara

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03