It is currently December 6th, 2022, 1:45 pm

return an image when weather doesn't get a value in CurrentIcon

Get help with creating, editing & fixing problems with skins
User avatar
Rafamear
Posts: 98
Joined: November 15th, 2021, 1:47 am
Location: Brazil

return an image when weather doesn't get a value in CurrentIcon

Post by Rafamear »

I was using the eclectic-tech tutorial to test some things and wanted to know how do I make [MeterConditionIcon] return an image when I can't get a value for the image, like for example when it's offline

getting the information and showing it here
Image

and so when it does not receive any information
Image
Last edited by Rafamear on November 8th, 2022, 12:16 am, edited 1 time in total.
;===========================================Rafamear=================================================
;=============== :welcome: ========== https://www.deviantart.com/rafamear ========== :Whistle ==================
User avatar
SilverAzide
Rainmeter Sage
Posts: 2178
Joined: March 23rd, 2015, 5:26 pm

Re: return an image when weather doesn't get a value in CurrentIcon

Post by SilverAzide »

Rafamear wrote: November 5th, 2022, 9:47 pm I was using the eclectic-tech tutorial to test some things and wanted to know how do I make [MeterConditionIcon] return an image when I can't get a value for the image, like for example when it's offline
This can be done fairly easily. To do it, you need to create a measure to "override" the built-in template measure. If it was not clear in electic-tech's tutorial, you should never alter the template include files. These need to stay in untouched condition so they can easily be swapped out in case of a change to the weather.com API.

The template measure that grabs the icon is [@CurrentIcon]. Normally this is a number, but as you noticed it can be blank. Important to note, it will also be blank while the data is initially being fetched from the website. I mention this because after making this change, you may notice your "no value found" image appearing unless you take some precautions to prevent this (which I will show you).

So, first you create a measure to "wrap" the template measure. This measure goes in YOUR skin, not the template include file, and should appear after the lines that "@Include" the template files.

Code: Select all

[MeasureCurrentIcon]
Measure=String
String=@CurrentIcon
Group=Parents
RegExpSubstitute=1
Substitute="^$":"na"
Disabled=1
Some things to notice:

First, notice that the measure is disabled. This is done to prevent your "no value found" image from appearing briefly when the skin first loads, and before any data is retrieved. After the data is fetched from the website, the master template include WebParser measure will fire off a !Bang that will enable all measures in the "Parents" group. The line Group=Parents will allow the template WebParser measure to enable your custom measure here.

Second, what this measure does is do a string replace and change a blank icon value with the string "na" (short for "not applicable"). So all you need to do at this point is create your "no value found" weather icon and give it the name "na.png". Many icon packs you may find already have this icon defined.

Finally, you alter your existing MeterConditionIcon like so:

Code: Select all

[MeterConditionIcon]
...
MeasureName=MeasureCurrentIcon
...
Gadgets Wiki GitHub More Gadgets...
User avatar
Rafamear
Posts: 98
Joined: November 15th, 2021, 1:47 am
Location: Brazil

Re: return an image when weather doesn't get a value in CurrentIcon

Post by Rafamear »

SilverAzide wrote: November 6th, 2022, 12:49 am This can be done fairly easily. To do it, you need to create a measure to "override" the built-in template measure. If it was not clear in electic-tech's tutorial, you should never alter the template include files. These need to stay in untouched condition so they can easily be swapped out in case of a change to the weather.com API.

The template measure that grabs the icon is [@CurrentIcon]. Normally this is a number, but as you noticed it can be blank. Important to note, it will also be blank while the data is initially being fetched from the website. I mention this because after making this change, you may notice your "no value found" image appearing unless you take some precautions to prevent this (which I will show you).

So, first you create a measure to "wrap" the template measure. This measure goes in YOUR skin, not the template include file, and should appear after the lines that "@Include" the template files.

Code: Select all

[MeasureCurrentIcon]
Measure=String
String=@CurrentIcon
Group=Parents
RegExpSubstitute=1
Substitute="^$":"na"
Disabled=1
Some things to notice:

First, notice that the measure is disabled. This is done to prevent your "no value found" image from appearing briefly when the skin first loads, and before any data is retrieved. After the data is fetched from the website, the master template include WebParser measure will fire off a !Bang that will enable all measures in the "Parents" group. The line Group=Parents will allow the template WebParser measure to enable your custom measure here.

Second, what this measure does is do a string replace and change a blank icon value with the string "na" (short for "not applicable"). So all you need to do at this point is create your "no value found" weather icon and give it the name "na.png". Many icon packs you may find already have this icon defined.

Finally, you alter your existing MeterConditionIcon like so:

Code: Select all

[MeterConditionIcon]
...
MeasureName=MeasureCurrentIcon
...
I did as you said and it even worked but when I went to test if it changed the icon was just blank and nothing appeared as if there was no instruction to change it

here is my code

Code: Select all

[MeterConditionIcon]
Meter=Image
MeasureName=[MeasureCurrentIcon]
DynamicVariables=1
ImageName=#@#WeatherIcons\%1.png
ImageTint=#COLOR1#
X=15
Y=15
W=96
H=96

[MeasureCurrentIcon]
Measure=String
String=@CurrentIcon
Group=Parents
RegExpSubstitute=1
Substitute="^$":"na"
Disabled=1
;===========================================Rafamear=================================================
;=============== :welcome: ========== https://www.deviantart.com/rafamear ========== :Whistle ==================
User avatar
SilverAzide
Rainmeter Sage
Posts: 2178
Joined: March 23rd, 2015, 5:26 pm

Re: return an image when weather doesn't get a value in CurrentIcon

Post by SilverAzide »

Rafamear wrote: November 6th, 2022, 2:42 am I did as you said and it even worked but when I went to test if it changed the icon was just blank and nothing appeared as if there was no instruction to change it
:confused: Not sure what you mean by "when I went to test if it changed". You're going to need to post the whole skin, or at least a working example that demonstrates the problem.
Gadgets Wiki GitHub More Gadgets...
User avatar
Rafamear
Posts: 98
Joined: November 15th, 2021, 1:47 am
Location: Brazil

Re: return an image when weather doesn't get a value in CurrentIcon

Post by Rafamear »

SilverAzide wrote: November 6th, 2022, 5:18 am :confused: Not sure what you mean by "when I went to test if it changed". You're going to need to post the whole skin, or at least a working example that demonstrates the problem.
sorry if you didn't understand, i meant that i went to test it to see if it worked but it didn't work so here is my whole skin

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Metadata]
Name=DotsAndSquares
Author=Rafamear
Version=1.0
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

[Variables]
@include=#@#Variables.inc
@includeVariables=#@#WeatherComJSONVariables.inc
@IncludeLanguageVariables="#@#WeatherComJSONLanguage.inc"
@IncludeMeasures=#@#WeatherComJSONMeasures3Day.inc

;======================Measures=====================
;===================================================
[FrostedGlass]
Measure=Plugin
Plugin=FrostedGlass
Type=Blur
Border=Left

[MeasureCurrentIcon]
Measure=String
String=@CurrentIcon
Group=Parents
RegExpSubstitute=1
Substitute="^$":"na"
Disabled=1

;=======================Shapes======================
;===================================================
[RoundedCorner]
Meter=Shape
Shape=Path MyPath | StrokeWidth 10 | Stroke Color 30,30,30 | StrokeStartCap Round | StrokeEndCap Round | StrokeLineJoin Round
MyPath=25,115 | LineTo 0,115 | LineTo 0,0 | LineTo 115,0 | LineTo 115,115 | LineTo 55,115
X=5
Y=5

[Circle]
Meter=Shape
Shape=Ellipse 0,0,5,5 | Extend HolderFill | Extend HolderStroke
HolderFill=Fill Color 30,30,30 
HolderStroke=Stroke Color 0,0,0,1
LeftMouseUpAction=[!ToggleConfig "windows11" "Search.ini"]
MouseOverAction=[!SetOption Circle HolderFill "Fill Color 245,30,30"][!SetOption Circle Shape "Ellipse 0,0,7,7 | Extend HolderFill | Extend HolderStroke"][!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption Circle HolderFill "Fill Color 30,30,30"][!SetOption Circle Shape "Ellipse 0,0,5,5 | Extend HolderFill | Extend HolderStroke"][!UpdateMeter *][!Redraw]
X=45
Y=120

[MouseOverTemp]
Meter=Shape
Shape=Rectangle 0,0,99,99,4 | Extend HolderFill | Extend HolderStroke
HolderFill=Fill Color 0,0,0,1 
HolderStroke=Stroke Color 0,0,0,1
MouseOverAction=[!HideMeter MeterConditionIcon][!ShowMeter MouseOverTemp][!ShowMeter MeterHumidity💧][!UpdateMeter *][!Redraw]
MouseLeaveAction=[!HideMeter MouseOverTemp][!HideMeter MeterHumidity💧][!ShowMeter MeterConditionIcon][!UpdateMeter *][!Redraw]
X=13
Y=13


;=======================Images======================
;===================================================
[MeterConditionIcon]
Meter=Image
MeasureName=[MeasureCurrentIcon]
DynamicVariables=1
ImageName=#@#WeatherIcons\%1.png
ImageTint=#COLOR1#
X=15
Y=15
W=96
H=96

[MeterCurrentTemperature]
Meter=String
MeasureName=@CurrentTemperature
MeasureName2=@LocationName
Text="%1°[@UnitsTemperature]"
StringAlign=Center
fontFace=#FONT#
FontSize=25
FontColor=#COLOR1#
AntiAlias=1
DynamicVariables=1
Hidden=1
X=62
Y=10

[MeterHumidity💧]
Meter=String
MeasureName=@CurrentHumidity
Text=💧 %1%
StringAlign=Center
fontFace=#FONT#
FontSize=15
FontColor=#COLOR1#
AntiAlias=1
Hidden=1
X=62
Y=50
;===========================================Rafamear=================================================
;=============== :welcome: ========== https://www.deviantart.com/rafamear ========== :Whistle ==================
User avatar
ikarus1969
Posts: 527
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: return an image when weather doesn't get a value in CurrentIcon

Post by ikarus1969 »

In your meter MeterConditionIcon you have a MeasureName-Property. In this property you should only give the name of the measure without the brackets. So delete the brackets like in this code:

Code: Select all

[MeterConditionIcon]
Meter=Image
MeasureName=MeasureCurrentIcon
DynamicVariables=1
ImageName=#@#WeatherIcons\%1.png
ImageTint=#COLOR1#
X=15
Y=15
W=96
H=96
User avatar
Rafamear
Posts: 98
Joined: November 15th, 2021, 1:47 am
Location: Brazil

Re: return an image when weather doesn't get a value in CurrentIcon

Post by Rafamear »

ikarus1969 wrote: November 6th, 2022, 8:21 am In your meter MeterConditionIcon you have a MeasureName-Property. In this property you should only give the name of the measure without the brackets. So delete the brackets like in this code:

Code: Select all

[MeterConditionIcon]
Meter=Image
MeasureName=MeasureCurrentIcon
DynamicVariables=1
ImageName=#@#WeatherIcons\%1.png
ImageTint=#COLOR1#
X=15
Y=15
W=96
H=96
I left them there because just when I take them out, nothing else appears. :confused:
;===========================================Rafamear=================================================
;=============== :welcome: ========== https://www.deviantart.com/rafamear ========== :Whistle ==================
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4885
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: return an image when weather doesn't get a value in CurrentIcon

Post by eclectic-tech »

Rafamear wrote: November 7th, 2022, 9:05 pm I left them there because just when I take them out, nothing else appears. :confused:
To get your code working, a few changes are needed:
Add brackets to the STRING= value; String=[@CurrentIcon] in [MeasureCurrentIcon] section
Add DynamicVariables=1 to [MeasureCurrentIcon] section

In [MouseOverTemp] section, correct the name of your Temp meter in the MouseOver/MouseLeave actions; MouseOverTemp to MeterCurrentTemperature

In [MeterCurrentIcon] section:
Remove brackets from MeasureName=[MeasureCurrentIcon] so it is MeasureName=MeasureCurrentIcon
Remove InageName=#@#WeatherIcons\%1.png
Add ImagePath=#@#WeatherIcons\

In your Circle shape meter, remove the 2nd EXTEND parameters and combine the Stroke Color and Fill Color parameters into 1 EXTEND parameter.

Working Code (shows na.png until current icon number is returned by [@currentIcon] measure):

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Metadata]
Name=DotsAndSquares
Author=Rafamear
Version=1.0
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

[Variables]
@include=#@#Variables.inc
@includeVariables=#@#WeatherComJSONVariables.inc
@IncludeLanguageVariables="#@#WeatherComJSONLanguage.inc"
@IncludeMeasures=#@#WeatherComJSONMeasures3Day.inc

;======================Measures=====================
;===================================================
[FrostedGlass]
Measure=Plugin
Plugin=FrostedGlass
Type=Blur
Border=Left

[MeasureCurrentIcon]
Measure=String
String=[@CurrentIcon]
Group=Parents
RegExpSubstitute=1
Substitute="^$":"na"
DynamicVariables=1
Disabled=1

;=======================Shapes======================
;===================================================
[RoundedCorner]
Meter=Shape
Shape=Path MyPath | StrokeWidth 10 | Stroke Color 30,30,30 | StrokeStartCap Round | StrokeEndCap Round | StrokeLineJoin Round
MyPath=25,115 | LineTo 0,115 | LineTo 0,0 | LineTo 115,0 | LineTo 115,115 | LineTo 55,115
X=5
Y=5

[Circle]
Meter=Shape
Shape=Ellipse 0,0,5,5 | Extend HolderFill
HolderFill=Fill Color 30,30,30 | Stroke Color 0,0,0,1
LeftMouseUpAction=[!ToggleConfig "windows11" "Search.ini"]
MouseOverAction=[!SetOption Circle HolderFill "Fill Color 245,30,30 | Stroke Color 0,0,0,1"][!SetOption Circle Shape "Ellipse 0,0,7,7 | Extend HolderFill"][!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption Circle HolderFill "Fill Color 30,30,30 | Stroke Color 0,0,0,1"][!SetOption Circle Shape "Ellipse 0,0,5,5 | Extend HolderFill"][!UpdateMeter *][!Redraw]
X=45
Y=120

[MouseOverTemp]
Meter=Shape
Shape=Rectangle 0,0,99,99,4 | Extend HolderFill
HolderFill=Fill Color 0,0,0,1 | Stroke Color 0,0,0,1
MouseOverAction=[!HideMeter MeterConditionIcon][!ShowMeter MeterCurrentTemperature][!ShowMeter MeterHumidity💧][!UpdateMeter *][!Redraw]
MouseLeaveAction=[!HideMeter MeterCurrentTemperature][!HideMeter MeterHumidity💧][!ShowMeter MeterConditionIcon][!UpdateMeter *][!Redraw]
X=13
Y=13


;=======================Images======================
;===================================================
[MeterConditionIcon]
Meter=Image
MeasureName=MeasureCurrentIcon
DynamicVariables=1
ImagePath=#@#WeatherIcons\
ImageTint=#COLOR1#
X=15
Y=15
W=96
H=96

[MeterCurrentTemperature]
Meter=String
MeasureName=@CurrentTemperature
MeasureName2=@LocationName
Text="%1°[@UnitsTemperature]"
StringAlign=Center
fontFace=#FONT#
FontSize=25
FontColor=#COLOR1#
AntiAlias=1
DynamicVariables=1
Hidden=1
X=62
Y=10

[MeterHumidity💧]
Meter=String
MeasureName=@CurrentHumidity
Text=💧 %1%
StringAlign=Center
fontFace=#FONT#
FontSize=15
FontColor=#COLOR1#
AntiAlias=1
Hidden=1
X=62
Y=50
User avatar
SilverAzide
Rainmeter Sage
Posts: 2178
Joined: March 23rd, 2015, 5:26 pm

Re: return an image when weather doesn't get a value in CurrentIcon

Post by SilverAzide »

Yep, E-T beat me to it...
wx.png
You do not have the required permissions to view the files attached to this post.
Gadgets Wiki GitHub More Gadgets...
User avatar
Rafamear
Posts: 98
Joined: November 15th, 2021, 1:47 am
Location: Brazil

Re: return an image when weather doesn't get a value in CurrentIcon

Post by Rafamear »

SilverAzide wrote: November 7th, 2022, 10:18 pm Yep, E-T beat me to it...

wx.png
yes... it works perfectly :thumbup:
;===========================================Rafamear=================================================
;=============== :welcome: ========== https://www.deviantart.com/rafamear ========== :Whistle ==================