Hi Enlightened Ones
I have written a routine to generate a calender using TkxTable. The problem is that the inner tables only display the date sequence for the last month processed for all months displayed. If you adjust the 'for' loop which runs through the months the previous months get attributed with that last months sequence
Not sure what I have got wrong but there seems limited information on the www and the man pages don't seem to cover this scenario
Any help appreciated
use Tkx;
Tkx::package_require("Tktable");
use Date::Calc qw(Today
Month_to_Text
Decode_Month
Delta_Days
Add_Delta_Days
Day_of_Week
Days_in_Month
);
sub calc_month($$$);
my @month_name;
my $year = "2015";
my @mf;
my @mt;
my @test;
my @tmo;
my $mw = Tkx::widget->new(".");
my %hash1 =
(
'0,0' => ''
);
my %hash =
( # data to display
'0,0' => 'M',
'0,1' => 'T',
'0,2' => 'W',
'0,3' => 'T',
'0,4' => 'F',
'0,5' => 'S',
'0,6' => 'S',
);
# Year Frame
(my $yf = $mw->new_ttk__frame(-padding => "5 5 5 5",))->g_pack;
$mw->g_wm_minsize(750,730);
#Year Table
my $yt = $yf->new_table
(
-rows =>4,
-cols =>3,
-rowheight=>11,
-colwidth=>40,
-maxheight=>700,
-maxwidth=>700,
-variable => \%hash1,
);
for (my $m = 1; $m <=12; $m++)
{
$mf[$m] = $yt->new_ttk__frame(-padding => "5 5 5 5");
$mt[$m] = $mf[$m]->new_table
(
-rows => 7,
-cols => 7,
-colwidth=>4,
-variable => \%hash,
);
$month_name[$m] = Month_to_Text($m);
$tmp[$m] = $mf[$m]->new_label(-textvariable => \$month_name[$m]);
$tmp[$m]->g_pack;
calc_month($year,$m,$mt[$m]);
$mt[$m]->g_pack;
my $x = $m -1;
$x = int $x /3;
my $y = ($m - 1) % 3;
print "$x, $y \n";
$test[$m] = $yt->window_configure("$x,$y", -window=>$mf[$m]);
};
my $tmp = $yf->new_label(-textvariable => \$year);
$tmp->g_pack;
$yt->g_pack;
Tkx::MainLoop();
sub calc_month($$$)
{
my $year = shift;
my $month = shift;
my $t = shift;
my $start_day = Day_of_Week($year,$month,1);
$start_day =$start_day - 1; #brings it back to cols in tables
my $days = Days_in_Month($year,$month);
$month_name = Month_to_Text($month);
print "$start_day , $days, $month_name, $t\n";
my $x = 1;
my $fday; # formatted day
for (my $r = 1; $r <=6; $r++)
{
for (my $c = 0; $c <= 6; $c++)
{
if (($x > $start_day)&&($x <= ($days + $start_day)))
{
$fday = sprintf "% 2d",$x - $start_day;
}
else
{
$fday = "";
}
$t->set("$r,$c",$fday);
$x++;
}
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.