It is currently April 16th, 2024, 6:22 pm

Want to change the picture depend of a string

Get help with creating, editing & fixing problems with skins
chrdh
Posts: 2
Joined: May 12th, 2023, 2:10 pm

Want to change the picture depend of a string

Post by chrdh »

Hello, to start sorry for my english and sorry i'm starting coding with rainmeter.

I explain my problem, so, i get a wireless logitech stuff, and i get a soft who create an local website to get some information about this stuff in a xml file. i do a skin to get a view on this informations (the battery pourcent). so it's not a problem for the battery pourcet, i get with WebParser the information and it show in the skin.

But another information is important it's if the stuff is in charging mode or not. if i plug my stuff the xml will return a "True" if it dont plug it it will return "False", so i can grab this information with WebParser too, so i get a string with "False" or "True", but the problem is in my skin i get a icon to show if it's a headset, a keyboard or a mouse, and this icon is show by a "Meter=Image ImageName=#@#I\mouse.png" and i would like this image change if the the WebParser return True or False.
i have two option but i dont know how to do,

1st option is to do a condition (i dont know if it's possible) but something like this : if it's true it's ImageName=#@#I\mouse.png and if it's false it's ImageName=#@#I\mouse2.png
2nd option is (i dont know if it's possible but) : ImageName=#@#I\[STRING TRUE OR FALSE].png. i try this one but dosnt work.

i show you my code can you help me please ?
[Variables]
Interval=1
;=========================================================================================================================================
[Rainmeter]
Update=1000
DynamicWindowSize=1
OnRefreshAction=[!Delay (#Interval#*60000)][!Refresh]
Blur=1
BlurRegion=1,0,25,200,75
;==============BATTERY===========================================================================================================================
[XMLBATTERY]
Measure=WebParser
;=====REPLACE URL BY THE URL BY NAME OF YOUR DEVICE
URL=http://127.0.0.1:12321/device/Wireless%20Mouse%20MX%20Master
RegExp=(?siU)<battery_percent>(.*)</battery_percent>
UpdateRate=1000
DynamicVariables=1
[DEVICEBATTERY]
Measure=WebParser
URL=[XMLBATTERY]
StringIndex=1
DynamicVariables=1
[DEVICESTRING]
Measure=calc
Formula=(DEVICEBATTERY)
;====================GUI=====================================================================================================================
[Background]
Meter=Image
SolidColor=108,122,137,100
X=0
Y=25
W=200
H=50
AntiAlias=1

[Icon]
Meter=Image
ImageName=#@#I\mouse.png
X=15
Y=0
W=50
H=50
AntiAlias=1
;====================VALUE=====================================================================================================================
[Battery]
Meter=String
MeasureName=DEVICESTRING
NumOfDecimals=0
X=190
Y=25
W=125
H=25
FontSize=16
FontColor=255,255,255,255
FontFace=Museo 300
StringAlign=Right
AntiAlias=1
AutoScale=1
ClipString=1
Text="%1%"
DynamicVariables=1
[Name]
Meter=String
MeasureName=
X=190
Y=55
W=180
H=20
FontSize=11
FontColor=255,255,255,255
FontFace=Museo 300
StringAlign=Right
AntiAlias=1
AutoScale=1
ClipString=1
;===========REPLACE "TEXT=" by your device NAME
Text="Souris MXMASTER Wireless"
Image
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Want to change the picture depend of a string

Post by balala »

chrdh wrote: May 12th, 2023, 2:21 pm But another information is important it's if the stuff is in charging mode or not. if i plug my stuff the xml will return a "True" if it dont plug it it will return "False", so i can grab this information with WebParser too, so i get a string with "False" or "True", but the problem is in my skin i get a icon to show if it's a headset, a keyboard or a mouse, and this icon is show by a "Meter=Image ImageName=#@#I\mouse.png" and i would like this image change if the the WebParser return True or False.
First let's clarify a few things: I assume the measure returning true or false is [DEVICEBATTERY]. Is this correct?
If it is, [DEVICESTRING] doesn't work, it can't handle strings (true and / or false). A Calc measure only works with numeric values. But this measure, at least from the point of view of the posted code, isn't even necessary.
Now if the above assumption is correct, here are the solution (both your "options" are possible):
chrdh wrote: May 12th, 2023, 2:21 pm 1st option is to do a condition (i dont know if it's possible) but something like this : if it's true it's ImageName=#@#I\mouse.png and if it's false it's ImageName=#@#I\mouse2.png
Do the followings:

Code: Select all

[DEVICEBATTERY]
Measure=WebParser
URL=[XMLBATTERY]
StringIndex=1
IfMatch=true
IfMatchAction=[!setOption Icon ImageName "#@#I\mouse.png"][!UpdateMeter "Icon"][!Redraw]
IfNotMatchAction=[!setOption Icon ImageName "#@#I\mouse.2png"][!UpdateMeter "Icon"][!Redraw]
If the value returned by the [DEVICEBATTERY] measure is true, IfMatchAction is executed. The !SetOption bang sets to the ImageName option the #@#I\mouse.png image. If the measure doesn't match true, IfNotMatchAction is executed and accordingly the image is set to #@#I\mouse.2png. Note an important thing here: this image setting (mouse2.png) is executed every time the measure doesn't match true. So for false for instance, but same way for any other value returned by the measure, excepting true.
chrdh wrote: May 12th, 2023, 2:21 pm 2nd option is (i dont know if it's possible but) : ImageName=#@#I\[STRING TRUE OR FALSE].png. i try this one but dosnt work.
Add the following Substitute option to the [DEVICEBATTERY] measure: Substitute="false":"2","true":"". Change the ImageName option of the [Icon] meter to: ImageName=#@#I\mouse[DEVICEBATTERY].png. Along with this, also add a DynamicVariables=1 option to the [Icon] meter. Make sure not to forget this last option, without it the meter won't show the correct image.

Please check any of the above solution and let me know is does work. Also let me know if I misunderstood your explanation (if for instance not the [DEVICEBATTERY] measure is the one returning true or false).
chrdh
Posts: 2
Joined: May 12th, 2023, 2:10 pm

Re: Want to change the picture depend of a string

Post by chrdh »

Hello sir thank you the first thing work very well ! thank you so much !
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Want to change the picture depend of a string

Post by balala »

chrdh wrote: May 12th, 2023, 5:43 pm Hello sir thank you the first thing work very well ! thank you so much !
Glad to help.