From 6f20a7f1343a823e2f76e5d767e6057c6fc9f726 Mon Sep 17 00:00:00 2001 From: betateilchen <> Date: Sun, 15 Feb 2015 17:07:26 +0000 Subject: [PATCH] 55_InfoPanel.pm: updated git-svn-id: https://svn.fhem.de/fhem/trunk@7997 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/55_InfoPanel.pm | 131 +++++++++-------------------- fhem/contrib/InfoPanel/demo.layout | 6 -- 2 files changed, 40 insertions(+), 97 deletions(-) diff --git a/fhem/FHEM/55_InfoPanel.pm b/fhem/FHEM/55_InfoPanel.pm index 0bdc59603..bc37552f9 100644 --- a/fhem/FHEM/55_InfoPanel.pm +++ b/fhem/FHEM/55_InfoPanel.pm @@ -39,9 +39,11 @@ # 2015-02-14 - 7967 - added: item ticker (experimental) # changed: img syntax # 2015-02-15 - 7989 - added: item embed (experimental) -# 7992 - added: xcondition (can be overridden by set) +# 7995 - added: xcondition (can be overridden by set) # set ovClear,ovDisable,ovEnable # get counter, layout, overrides +# 7997 - removed: trashcan due to performance issues +# - added: break condition for includes # ############################################## # $Id: 55_InfoPanel.pm 7990 2015-02-14 22:28:21Z betateilchen $ @@ -88,7 +90,6 @@ sub btIP_itemText; sub btIP_itemTextBox; sub btIP_itemTicker; sub btIP_itemTime; -sub btIP_itemTrash; sub btIP_changeColor; sub btIP_color; @@ -128,7 +129,7 @@ sub InfoPanel_Initialize($) { $hash->{SetFn} = "btIP_Set"; $hash->{GetFn} = "btIP_Get"; $hash->{NotifyFn} = "btIP_Notify"; - $hash->{AttrList} = "autoreread:1,0 bgcolor refresh size title"; + $hash->{AttrList} = "autoreread:1,0 bgcolor refresh size title noscript "; $hash->{AttrList} .= " bgcenter:1,0 bgdir bgopacity tmin" if $useImgTools; return undef; @@ -237,6 +238,7 @@ sub btIP_readLayout { my ($hash)= @_; my $filename= $hash->{LAYOUTFILE}; my $name= $hash->{NAME}; + my $level = 0; my ($err, @layoutfile) = FileRead($filename); if($err) { @@ -244,7 +246,8 @@ sub btIP_readLayout { $hash->{fhem}{layout} = "text ERROR 50 50 \"Error on reading layout!\""; } else { $hash->{fhem}{layout} = join("\n", @layoutfile); - while($hash->{fhem}{layout} =~ m/\@include/ ) { + while($hash->{fhem}{layout} =~ m/\@include/ && $level < 1000) { + $level++; my (@layout2,@include); foreach my $ll (@layoutfile) { if($ll !~ m/^\@include/) { @@ -259,7 +262,8 @@ sub btIP_readLayout { @layout2 = undef; $hash->{fhem}{layout} = join("\n",@layoutfile); } - while($hash->{fhem}{layout} =~ m/\@finclude/ ) { + while($hash->{fhem}{layout} =~ m/\@finclude/ && $level < 1000) { + $level++; my (@layout2,@include); foreach my $ll (@layoutfile) { if($ll !~ m/^\@finclude/) { @@ -274,6 +278,7 @@ sub btIP_readLayout { @layout2 = undef; $hash->{fhem}{layout} = join("\n",@layoutfile); } + $hash->{fhem}{layout} = "text ERROR 50 50 \"Loop detected in includes!\"" if ($level >= 1000); $hash->{fhem}{layout} =~ s/\n\n/\n/g; } return; @@ -680,49 +685,6 @@ sub btIP_itemTime { return btIP_itemText($id,$x,$y,sprintf("%02d:%02d", $hour, $min),%params); } -sub btIP_itemTrash { - return unless $useImgTools; - my ($id,$x,$y,$scale,$fgcolor,$bgcolor,$link,%params)= @_; - $id = ($id eq '-') ? createUniqueId() : $id; - my $target; - ($link,$target) = btIP_findTarget($link); - - my ($counter,$data,$info,$width,$height,$mimetype,$output); - -$data = ''. -''. -''. -''. -' '. -' '. -' '. -' '. -''. -''; - - my ($r,$g,$b,$a) = btIP_color($fgcolor); - $fgcolor = "rgb($r,$g,$b)"; - $data =~ s/fgcolor/$fgcolor/g; - - ($r,$g,$b,$a) = btIP_color($bgcolor); - $bgcolor = "rgb($r,$g,$b)"; - ($width,$height,$mimetype,$data) = _btIP_imgData($data,$scale); - $output = ""; - $output .= "\n" if($link && length($link)); - $output .= "\n"; - $output .= "\n"; - $output .= "\n" if($link && length($link)); - - return $output; -} - ##### Helper sub btIP_changeColor { @@ -796,6 +758,7 @@ sub btIP_xy { return($x,$y); } + ################## # # create SVG content @@ -1061,8 +1024,8 @@ sub btIP_evalLayout { when("group") { ($id,$text,$x,$y) = split("[ \t]+", $def, 4); - $x //= 0; - $y //= 0; + $x //= $params{xx}; + $y //= $params{yy}; ($x,$y)= btIP_xy($x,$y,%params); $params{xx} = $x; $params{yy} = $y; @@ -1234,33 +1197,27 @@ sub btIP_evalLayout { } when("trash") { - ($id,$x,$y,$scale,$fgcolor,$bgcolor,$link)= split("[ \t]+", $def,7); - ($x,$y)= btIP_xy($x,$y,%params); - $fgcolor = AnalyzePerlCommand(undef,$fgcolor); - $bgcolor = AnalyzePerlCommand(undef,$bgcolor); - $link = AnalyzePerlCommand(undef,$link); - $svg .= btIP_itemTrash($id,$x,$y,$scale,$fgcolor,$bgcolor,$link,%params); - $params{xx} = $x; - $params{yy} = $y; + $svg .= "\n\n\n"; + Log3($name, 2, "InfoPanel $name: command 'trash' no longer supported."); } - when("thalign"){ - my $d = AnalyzePerlCommand(undef, $def); - if($d ~~ @valid_halign) { - $params{thalign}= $d; - } else { - Log3($name, 2, "InfoPanel: $name Illegal horizontal alignment $d"); - } - } + when("thalign"){ + my $d = AnalyzePerlCommand(undef, $def); + if($d ~~ @valid_halign) { + $params{thalign}= $d; + } else { + Log3($name, 2, "InfoPanel $name: Illegal horizontal alignment $d"); + } + } - when("tvalign"){ - my $d = AnalyzePerlCommand(undef, $def); - if($d ~~ @valid_valign) { - $params{tvalign}= $d; - } else { - Log3($name, 2, "InfoPanel: $name Illegal vertical alignment $d"); - } - } + when("tvalign"){ + my $d = AnalyzePerlCommand(undef, $def); + if($d ~~ @valid_valign) { + $params{tvalign}= $d; + } else { + Log3($name, 2, "InfoPanel $name: Illegal vertical alignment $d"); + } + } default { Log3($name, 2, "InfoPanel $name: Illegal command $cmd in layout definition."); @@ -1268,11 +1225,12 @@ sub btIP_evalLayout { } # given } # eval -# Debug "after command $line: x= " . $params{xx} . ", y= " . $params{yy}; +#Debug "after command $line: x= " . $params{xx} . ", y= " . $params{yy}; } # foreach return $svg; } + ################## # @@ -1333,6 +1291,7 @@ sub btIP_splitRequest { } } + #################### # # HTML Stuff @@ -1345,7 +1304,7 @@ sub btIP_returnHTML { my $refresh = AttrVal($name, 'refresh', 60); my $title = AttrVal($name, 'title', $name); - my $code = btIP_HTMLHead($title,$refresh); + my $code = btIP_HTMLHead($name,$title,$refresh); $code .= "\n". "
\n". @@ -1357,20 +1316,22 @@ sub btIP_returnHTML { } sub btIP_HTMLHead { - my ($title,$refresh) = @_; + my ($name,$title,$refresh) = @_; my $doctype = ' '."\n". ''."\n"; my $xmlns = ""; my $r = (defined($refresh) && $refresh) ? "\n" : ""; - my $scripts = btIP_getScript(); + my $scripts = btIP_getScript($name); my $meta = "\n"; my $code = "$doctype\n\n\n$title\n$meta$r$scripts\n"; return $code; } sub btIP_getScript { + my ($name) = shift; + return "" if AttrVal($name,'noscript',0); my $scripts= ""; my $jsTemplate = ''; @@ -1395,7 +1356,7 @@ sub btIP_HTMLTail { sub btIP_Overview { my ($name, $url); - my $html= btIP_HTMLHead("InfoPanel Overview", undef) . "\n"; + my $html= btIP_HTMLHead(undef, "InfoPanel Overview", undef) . "\n"; foreach my $def (sort keys %defs) { if($defs{$def}{TYPE} eq "InfoPanel") { $name= $defs{$def}{NAME}; @@ -1827,18 +1788,6 @@ Please read [] []