It is currently April 27th, 2024, 5:18 pm

Dynamic text color

Get help with creating, editing & fixing problems with skins
User avatar
Lauda
Posts: 15
Joined: December 17th, 2011, 11:44 pm

Dynamic text color

Post by Lauda »

Hi all,
I'm pretty much new to the rainmeter and I've been working on a custom meter that checks servers status (Online/Offline)
I've managed to parse an XML file and get the proper values and now I'm wondering if there is a way to change the text color, for example: If it's online it will display it in green color and if it's offline it will display it in red color.

I've tried to do some stuff with IfAboveValue checks but I doubt that can compare strings?

Thanks! :)
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Dynamic text color

Post by jsmorley »

There is no way to directly compare strings (without resorting to a Lua script), but you can use the Substitute statement to change strings into numbers, and then the IfxxxxValue statements can do comparisons on numbers.

Here is one approach:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureCheckServer]
Measure=Plugin
Plugin=WebParser.dll
URL=http://rainmeter.net/WebParserTest.html
RegExp="(?siU)<Status>(.*)</Status>"
StringIndex=1
Substitute="Online":"1","Offline":"0","":"0"

[MeasureStatus]
Measure=Calc
Formula=[MeasureCheckServer]
IfEqualValue=1
IfEqualAction=!SetOption MeterOne FontColor 0,255,0,255
IfBelowValue=1
IfBelowAction=!SetOption MeterOne FontColor 255,0,0,255]
DynamicVariables=1

[MeterOne]
Meter=String
FontSize=12
StringStyle=Bold
Antialias=1
Text=Server Status
Based on your explanation, I am checking for "Online" or "Offline" and also throwing in "" (null) in case you can't get to the xml file at all.
User avatar
Lauda
Posts: 15
Joined: December 17th, 2011, 11:44 pm

Re: Dynamic text color

Post by Lauda »

Thanks a lot! :D
It works now! :)
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Dynamic text color

Post by jsmorley »

Glad to help.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Dynamic text color

Post by smurfier »

If you have to substitute, why not substitute the color values in and then just use dynamic variables?

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureCheckServer]
Measure=Plugin
Plugin=WebParser.dll
URL=http://rainmeter.net/WebParserTest.html
RegExp="(?siU)<Status>(.*)</Status>"
StringIndex=1
Substitute="Online":"0,255,0,255","Offline":"255,0,0,255","":"255,0,0,255"

[MeterOne]
Meter=String
FontSize=12
StringStyle=Bold
Antialias=1
Text=Server Status
FontColor=[MeasureCheckServer]
DynamicVariables=1
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Dynamic text color

Post by jsmorley »

An decent (and simpler) variant on the idea, however I went with the Calc for a reason. It opens up the opportunity to do many things based on the answer, not just one. You could set the FontColor, change the Text, hide or unhide meter(s), any number of things that could be caused by the single fact that the server is "Offline".