Hopefully last and final hack to fix the VPOS situation for images.

This commit is contained in:
Bradley M. Kuhn 2013-12-31 16:50:11 -05:00
parent 80583bd631
commit b2a67fcc24

View file

@ -31,9 +31,12 @@ use feature 'unicode_strings';
use Encode qw(encode decode); use Encode qw(encode decode);
use File::Temp qw/tempdir/; use File::Temp qw/tempdir/;
use File::Spec;
chdir("$ENV{HOME}/tmp/.conky-mythtv-weather") my $DIR = File::Spec->catdir("$ENV{HOME}", 'tmp', '.conky-mythtv-weather');
or die "unable to go to $ENV{HOME}/tmp/.conky-mythtv-weather"; my $VOFFSET_FILE = File::Spec->catfile($DIR, 'conky-weather-voffset-last');
chdir($DIR) or die "unable to go to $DIR";
if (@ARGV != 6 and @ARGV != 7) { if (@ARGV != 6 and @ARGV != 7) {
print STDERR "usage: $0 /path/to/mythtv/git/checkout <units> <location> <text_voffset> <img_voffset> <fontsize_pixels> [hour-format]\n"; print STDERR "usage: $0 /path/to/mythtv/git/checkout <units> <location> <text_voffset> <img_voffset> <fontsize_pixels> [hour-format]\n";
@ -41,6 +44,21 @@ if (@ARGV != 6 and @ARGV != 7) {
} }
my($MYTH_PATH, $UNITS, $LOCATION, $VOFFSET_TEXT, $VOFFSET_IMAGE, $FONT_SIZE, $HOUR_FORMAT) = @ARGV; my($MYTH_PATH, $UNITS, $LOCATION, $VOFFSET_TEXT, $VOFFSET_IMAGE, $FONT_SIZE, $HOUR_FORMAT) = @ARGV;
$HOUR_FORMAT = "%a %H:%M" unless defined $HOUR_FORMAT; $HOUR_FORMAT = "%a %H:%M" unless defined $HOUR_FORMAT;
my $TEXT_LINE_OFFSET_VPOS_AMOUNT = 1.59;
my $VOFFSET_TOP_DEFAULT_OFFSET = 11;
if ($VOFFSET_IMAGE eq 'READ') {
open(VOFFSET, "<", $VOFFSET_FILE) or die "unable to read $VOFFSET_FILE: $!";
while (my $line = <VOFFSET>) {
chomp $line;
$VOFFSET_IMAGE = $line if $line =~ /^\s*[\d\.]+\s*$/;
}
close VOFFSET;
die "unable to read voffset from $VOFFSET_FILE: $!"
if ($VOFFSET_IMAGE eq 'READ');
}
$VOFFSET_IMAGE += $VOFFSET_TOP_DEFAULT_OFFSET;
my $degree; my $degree;
if ($UNITS eq "SI") { if ($UNITS eq "SI") {
$degree = encode('utf8', "°C"); $degree = encode('utf8', "°C");
@ -133,7 +151,16 @@ foreach my $ii (qw/0 1 2 3 4 5/) {
} }
} }
my $f = $FONT_SIZE + 5; my $f = $FONT_SIZE + 5;
print '${voffset ', $VOFFSET_TEXT , '} ${font :size=', $f, '}${alignc}Weather:${font}', " $data{current}{'cclocation'}\n";
my($xpos, $vpos) = (340, $VOFFSET_IMAGE);
my $place = $data{current}{'cclocation'};
$place .= " $location2" if ($location1 eq "FORCE_ACCUWEATHER");
print '${voffset ', $VOFFSET_TEXT , '} ${font :size=', $f, '}${alignc}Weather:${font}', " $place\n";
$vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $f);
if (not defined $data{current}{observation_time_rfc822}) { if (not defined $data{current}{observation_time_rfc822}) {
$data{current}{observation_time_rfc822} = $data{current}{observation_time}; $data{current}{observation_time_rfc822} = $data{current}{observation_time};
$data{current}{observation_time_rfc822} =~ s/^\s*(?:Observation\s*of\s*:?|Last\s*Updated\s*(?:on)?)\s*//; $data{current}{observation_time_rfc822} =~ s/^\s*(?:Observation\s*of\s*:?|Last\s*Updated\s*(?:on)?)\s*//;
@ -171,29 +198,33 @@ undef $weatherConditions
$icon = $data{extended}{"icon-0"} $icon = $data{extended}{"icon-0"}
if ($icon =~ /unknown/i and $data{extended}{"date-0"} eq UnixDate($now, "%A")); if ($icon =~ /unknown/i and $data{extended}{"date-0"} eq UnixDate($now, "%A"));
my($xpos, $vpos) = (350, $VOFFSET_IMAGE + 40);
my $smallFontSize = $FONT_SIZE - 5; my $smallFontSize = $FONT_SIZE - 5;
$smallFontSize = 7 if $smallFontSize < 7; $smallFontSize = 7 if $smallFontSize < 7;
(defined $ago) ? (defined $ago) ?
print "\${alignr}\${font :size=${smallFontSize}px}(as of $ago)\n" : print "\${alignr}\${font :size=${smallFontSize}px}(as of $ago)\n" :
print "\n"; print "\n";
$vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $smallFontSize);
print "\${font :size=${FONT_SIZE}px} Current: $temp $degree"; print "\${font :size=${FONT_SIZE}px} Current: $temp $degree";
print " (feels like: $feelsLike $degree)" if defined $feelsLike; print " (feels like: $feelsLike $degree)" if defined $feelsLike;
print "\${image $mythIconPath/$icon -p $xpos,$vpos -s 50x37}" print "\${image $mythIconPath/$icon -p $xpos,$vpos -s 50x37}"
unless $icon =~ /unknown/i; unless $icon =~ /unknown/i;
$vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $FONT_SIZE);
print "\n\${goto 82}Humidity: $humidity\%"; print "\n\${goto 82}Humidity: $humidity\%";
print " Wind: " if defined $windSpeed or defined $windGust; print " Wind: " if defined $windSpeed or defined $windGust;
print "$windSpeed kph" if defined $windSpeed; print "$windSpeed kph" if defined $windSpeed;
print " ($windGust kph)" if defined $windGust; print " ($windGust kph)" if defined $windGust;
print "\n\${goto 82}Conditions: $weatherConditions\n" if defined $weatherConditions; $vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $FONT_SIZE);
if (defined $weatherConditions) {
print "\n\${goto 82}Conditions: $weatherConditions\n";
$vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $FONT_SIZE);
}
$vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $FONT_SIZE);
print "\n"; print "\n";
($xpos, $vpos) = ($FONT_SIZE * (5 + $data{forecast}{maxLength}),
$VOFFSET_IMAGE + 78);
my $cnt = 0; $xpos = $FONT_SIZE * (4 + $data{forecast}{maxLength});
foreach my $ii (qw/0 1 2 3 4 5/) { foreach my $ii (qw/0 1 2 3 4 5/) {
next if not defined $data{forecast}{"time-${ii}"}; next if not defined $data{forecast}{"time-${ii}"};
$cnt++;
my($time, $temp, $pop, $icon) = my($time, $temp, $pop, $icon) =
($data{forecast}{"time-${ii}"}, $data{forecast}{"temp-${ii}"}, ($data{forecast}{"time-${ii}"}, $data{forecast}{"temp-${ii}"},
$data{forecast}{"pop-${ii}"}, $data{forecast}{"18icon-${ii}"}); $data{forecast}{"pop-${ii}"}, $data{forecast}{"18icon-${ii}"});
@ -201,10 +232,10 @@ foreach my $ii (qw/0 1 2 3 4 5/) {
$pop = " $pop" if length($pop) eq 2; $pop = " $pop" if length($pop) eq 2;
$pop = " $pop" if length($pop) eq 3; $pop = " $pop" if length($pop) eq 3;
print "\${font :size=${FONT_SIZE}px} $time:\${goto 120}$temp $degree \${image $mythIconPath/$icon -p $xpos,$vpos -s 20x15} $pop chance\n"; print "\${font :size=${FONT_SIZE}px} $time:\${goto 120}$temp $degree \${image $mythIconPath/$icon -p $xpos,$vpos -s 20x15} $pop chance\n";
$vpos += $FONT_SIZE + 7; $vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $FONT_SIZE);
} }
($xpos, $vpos) = ($FONT_SIZE * 26, $xpos = $FONT_SIZE * 26;
$VOFFSET_IMAGE + 173);
foreach my $ii (qw/0 1 2 3 4 5/) { foreach my $ii (qw/0 1 2 3 4 5/) {
# You can also use "%doneDays" here, as in: # You can also use "%doneDays" here, as in:
# next if defined $doneDays{$data{extended}{"date-${ii}"}}; # next if defined $doneDays{$data{extended}{"date-${ii}"}};
@ -214,9 +245,14 @@ foreach my $ii (qw/0 1 2 3 4 5/) {
($data{extended}{"date-${ii}"}, $data{extended}{"high-${ii}"}, ($data{extended}{"date-${ii}"}, $data{extended}{"high-${ii}"},
$data{extended}{"low-${ii}"}, $data{extended}{"icon-${ii}"}); $data{extended}{"low-${ii}"}, $data{extended}{"icon-${ii}"});
print "\${font :size=${FONT_SIZE}px} $day:\${goto 120}High: $high $degree Low: $low $degree \${image $mythIconPath/$icon -p $xpos,$vpos -s 20x15}\n"; print "\${font :size=${FONT_SIZE}px} $day:\${goto 120}High: $high $degree Low: $low $degree \${image $mythIconPath/$icon -p $xpos,$vpos -s 20x15}\n";
$vpos += $FONT_SIZE + 8; $vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $FONT_SIZE);
} }
print "\$hr\n";
$vpos += ($TEXT_LINE_OFFSET_VPOS_AMOUNT * $FONT_SIZE);
$vpos -= $VOFFSET_TOP_DEFAULT_OFFSET;
open(VOFFSET, ">", $VOFFSET_FILE);
print VOFFSET "$vpos\n";
close VOFFSET;
############################################################################### ###############################################################################
# #
# Local variables: # Local variables: