line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gtk2::Ex::CalendarButton; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
33743
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
7
|
1
|
|
|
1
|
|
420
|
use Gtk2 '-init'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Glib qw /TRUE FALSE/; |
9
|
|
|
|
|
|
|
use Data::Dumper; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
|
|
|
|
|
|
my ($class, $date) = @_; |
13
|
|
|
|
|
|
|
my $self = {}; |
14
|
|
|
|
|
|
|
bless ($self, $class); |
15
|
|
|
|
|
|
|
$self->{button} = Gtk2::Button->new; |
16
|
|
|
|
|
|
|
$self->{calendar} = Gtk2::Calendar->new; |
17
|
|
|
|
|
|
|
$self->{date} = undef; |
18
|
|
|
|
|
|
|
if ($date) { |
19
|
|
|
|
|
|
|
$self->set_date($date); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
|
|
|
|
|
|
$self->_update_button_label; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
my $calwindow = $self->_create_calendar_window(); |
25
|
|
|
|
|
|
|
$self->{button}->signal_connect('clicked' => |
26
|
|
|
|
|
|
|
sub { |
27
|
|
|
|
|
|
|
my ($self, $event) = @_; |
28
|
|
|
|
|
|
|
$calwindow->set_position('mouse'); |
29
|
|
|
|
|
|
|
$calwindow->show_all; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub signal_connect { |
36
|
|
|
|
|
|
|
my ($self, $signal, $callback) = @_; |
37
|
|
|
|
|
|
|
$self->{$signal} = $callback; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_button { |
41
|
|
|
|
|
|
|
my ($self) = @_; |
42
|
|
|
|
|
|
|
return $self->{button}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_calendar { |
46
|
|
|
|
|
|
|
my ($self) = @_; |
47
|
|
|
|
|
|
|
return $self->{calendar}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_date { |
51
|
|
|
|
|
|
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
return $self->{date}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub set_date { |
56
|
|
|
|
|
|
|
my ($self, $date) = @_; |
57
|
|
|
|
|
|
|
$self->{date} = $date; |
58
|
|
|
|
|
|
|
my ($year, $month, $day) = @$date; |
59
|
|
|
|
|
|
|
my $cal = $self->{calendar}; |
60
|
|
|
|
|
|
|
$cal->select_month($month, $year); |
61
|
|
|
|
|
|
|
$cal->select_day($day); |
62
|
|
|
|
|
|
|
$self->_update_button_label; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _update_button_label { |
66
|
|
|
|
|
|
|
my ($self) = @_; |
67
|
|
|
|
|
|
|
my ($year, $month, $day) = $self->{calendar}->get_date; |
68
|
|
|
|
|
|
|
$self->{date} = [$year, $month, $day]; |
69
|
|
|
|
|
|
|
$month = _month()->[$month]; |
70
|
|
|
|
|
|
|
$self->{button}->set_label("$month $day\, $year"); |
71
|
|
|
|
|
|
|
&{$self->{'date-changed'}}($self) if $self->{'date-changed'}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _create_calendar_window { |
75
|
|
|
|
|
|
|
my ($self) = @_; |
76
|
|
|
|
|
|
|
my $vbox = Gtk2::VBox->new; |
77
|
|
|
|
|
|
|
my $ok = Gtk2::Button->new_from_stock('gtk-ok'); |
78
|
|
|
|
|
|
|
my $cancel= Gtk2::Button->new_from_stock('gtk-cancel'); |
79
|
|
|
|
|
|
|
my $hbox = Gtk2::HBox->new; |
80
|
|
|
|
|
|
|
$hbox->pack_start($ok, TRUE, TRUE, 0); |
81
|
|
|
|
|
|
|
$hbox->pack_start($cancel, TRUE, TRUE, 0); |
82
|
|
|
|
|
|
|
$vbox->pack_start($self->{calendar}, TRUE, TRUE, 0); |
83
|
|
|
|
|
|
|
$vbox->pack_start($hbox, TRUE, TRUE, 0); |
84
|
|
|
|
|
|
|
my $calwindow = Gtk2::Window->new('popup'); |
85
|
|
|
|
|
|
|
$calwindow->add($vbox); |
86
|
|
|
|
|
|
|
$ok->signal_connect('clicked' => |
87
|
|
|
|
|
|
|
sub { |
88
|
|
|
|
|
|
|
my ($okself, $event) = @_; |
89
|
|
|
|
|
|
|
$self->_update_button_label; |
90
|
|
|
|
|
|
|
$calwindow->hide; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
$cancel->signal_connect('clicked' => |
94
|
|
|
|
|
|
|
sub { |
95
|
|
|
|
|
|
|
my ($self, $event) = @_; |
96
|
|
|
|
|
|
|
$calwindow->hide; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
return $calwindow; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _month { |
103
|
|
|
|
|
|
|
return [ |
104
|
|
|
|
|
|
|
'Jan', |
105
|
|
|
|
|
|
|
'Feb', |
106
|
|
|
|
|
|
|
'Mar', |
107
|
|
|
|
|
|
|
'Apr', |
108
|
|
|
|
|
|
|
'May', |
109
|
|
|
|
|
|
|
'Jun', |
110
|
|
|
|
|
|
|
'Jul', |
111
|
|
|
|
|
|
|
'Aug', |
112
|
|
|
|
|
|
|
'Sep', |
113
|
|
|
|
|
|
|
'Oct', |
114
|
|
|
|
|
|
|
'Nov', |
115
|
|
|
|
|
|
|
'Dec', |
116
|
|
|
|
|
|
|
]; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 NAME |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Gtk2::Ex::CalendarButton - I realized that I was constantly re-creating a simple widget that will pop-up |
122
|
|
|
|
|
|
|
and Gtk2::Calendar when clicked. Just like the datetime display on your desktop taskbar. This package is |
123
|
|
|
|
|
|
|
my attempt to extract the portion of code required to create a button-click-calender. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $calbutton = Gtk2::Ex::CalendarButton->new([2007,3,14]); |
128
|
|
|
|
|
|
|
my $window = Gtk2::Window->new; |
129
|
|
|
|
|
|
|
$window->signal_connect(destroy => sub { Gtk2->main_quit; }); |
130
|
|
|
|
|
|
|
$window->add($calbutton->get_button); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 EXPORT |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
A list of functions that can be exported. You can delete this section |
135
|
|
|
|
|
|
|
if you don't export anything, such as for a purely object-oriented module. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 FUNCTIONS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 get_button |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 get_calendar |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 get_date |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 set_date |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Ofey Aikon, C<< >> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Copyright 2007 Ofey Aikon, all rights reserved. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
156
|
|
|
|
|
|
|
under the same terms as Perl itself. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; # End of Gtk2::Ex::CalendarButton |