It is currently May 3rd, 2024, 1:13 pm

IfAboveAction & IfBelowAction Issues (CPU Calc)

Get help with creating, editing & fixing problems with skins
User avatar
Indigo-Glow
Posts: 14
Joined: November 4th, 2011, 4:59 pm
Location: US

IfAboveAction & IfBelowAction Issues (CPU Calc)

Post by Indigo-Glow »

Hello again folks. I have been experimenting with various ways to get my CPU meter to show different images
depending on how much CPU is being used.

I have a sort-of-works solution, but expanding it to my current and later expected needs is bringing me to a halt.

Desired Affect

Right now I have 3 shapes which should display at various stages.

- A small 30 px shape that displays if the CPU activity is below 15%.
- A larger 60 px shape that should display if the CPU activity is between 15% & 30 percent, and also hides the 40 px shape if it was being displayed.
- A final image of 90 px, that should display if the CPU acitivity is above 30%, and hide all other currently shown shapes.


The Problem

My current code only works if I involve 2 images. As soon as I introduce a 3rd image (ie "step" into the [MeasureCPU] Measure, things unravel.

In this example, having a 30 px shape is pointless, as the only way it's ever visible is if it's only turned on (unhidden), because
I can't get it to ever be visible by adding to the [MeasureCPU] Measure.


The Code

Code: Select all


[MeasureCPU]
Measure=CPU
Processor=0
IfAboveValue=30
IfAboveAction=!Execute [!HideMeter Meter60Sphere][!ShowMeter Meter90Sphere]
IfBelowValue=30
IfBelowAction=!Execute [!HideMeter Meter90Sphere][!ShowMeter Meter60Sphere]


[MeasureDelayColor]
Measure=Calc
Formula=MeasureCPU

; CPU Background
[CPUBarBackground]
Meter=Image
ImageName=vertical-background.png
W=150
H=150
ImageFlip=VERTICAL

; 1st Sphere
[Meter30Sphere]
MeasureName=[MeasureDelayColor]
Meter=IMAGE
ImageName=30-percent.png
X=25
Y=25
W=100
H=100
Hidden=0

; 2nd Sphere
[Meter60Sphere]
MeasureName=[MeasureDelayColor]
Meter=IMAGE
ImageName=60-percent.png
X=25
Y=25
W=100
H=100
Hidden=1

; 3rd Sphere
[Meter90Sphere]
MeasureName=[MeasureDelayColor]
Meter=IMAGE
ImageName=90-percent.png
X=25
Y=25
W=100
H=100
Hidden=1

At this point, I don't know if this issue is because of a limitation, or because I am simply not doing something correctly.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfAboveAction & IfBelowAction Issues (CPU Calc)

Post by jsmorley »

Something like this should work. You will need (in this example) to name your images 15.png, 30.png and 100.png

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureCPU]
Measure=CPU
Processor=0

[MeasureSetImage]
Measure=Calc
Formula=[MeasureCPU] < 15 ? 15 : ([MeasureCPU] < 30 ? 30 : 100)
DynamicVariables=1

[MeterImage]
Meter=Image
ImageName=[MeasureSetImage].png
DynamicVariables=1
There should be no need for all the extra meters and all that hiding/showing.
User avatar
Indigo-Glow
Posts: 14
Joined: November 4th, 2011, 4:59 pm
Location: US

Re: IfAboveAction & IfBelowAction Issues (CPU Calc)

Post by Indigo-Glow »

jsmorley wrote:Something like this should work. You will need (in this example) to name your images 15.png, 30.png and 100.png

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureCPU]
Measure=CPU
Processor=0

[MeasureSetImage]
Measure=Calc
Formula=[MeasureCPU] < 15 ? 15 : ([MeasureCPU] < 30 ? 30 : 100)
DynamicVariables=1

[MeterImage]
Meter=Image
ImageName=[MeasureSetImage].png
DynamicVariables=1
There should be no need for all the extra meters and all that hiding/showing.
Indeed, that does work, up to a point. I forgot to mention that the images are different sizes! Sorry! I do not know what in heck is going on here, so I can't even begin to figure out to handle the different image sizes. Sorry for being such a total newb!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfAboveAction & IfBelowAction Issues (CPU Calc)

Post by jsmorley »

You know I don't have any life insurance, so you must be killing me for sport... ;-)

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureCPU]
Measure=CPU
Processor=0

[MeasureSetImage]
Measure=Calc
Formula=[MeasureCPU] < 15 ? 15 : ([MeasureCPU] < 30 ? 30 : 100)
IfBelowValue=16
IfBelowAction=[!SetOption MeterImage ImageName Image1.png][!SetOption MeterImage W 50][!SetOption MeterImage H 50]
IfEqualValue=30
IfEqualAction=[!SetOption MeterImage ImageName Image2.png][!SetOption MeterImage W 75][!SetOption MeterImage H 75]
IfAboveValue=30
IfAboveAction=[!SetOption MeterImage ImageName Image3.png][!SetOption MeterImage W 100][!SetOption MeterImage H 100]
DynamicVariables=1

[MeterImage]
Meter=Image
So what is going on:

First we get the value as a percentage by using the Measure=CPU measure.

Then we are using that value in a formula in a Measure=Calc. The formula is as follows:

Formula=[MeasureCPU] < 15 ? 15 : ([MeasureCPU] < 30 ? 30 : 100)

or

If [MeasureCPU] < 15 then I am 15 else if ([MeasureCPU] < 30 then I am 30 else I am 100)

Note: It doesn't really matter what we set those values to, it could easily be 1, 2 and 3. It is only important that they be set to something that is low / higher / highest.

Now we can use IfActions to set some things. Since we have only three values to test for, we can use IfBelow / IfEqual / IfAbove to test for them. If you had more than three, we would be into something else entirely, probably a little Lua script, as you can only have one each of the three kinds of IFActions in a measure.

So we test for the values with the IfActions, and when the IfxxxxxValue is "true", then it will fire the associated IfxxxxxAction. In this case we are setting the ImageName and W and H of the Meter=Image to the values we want.
User avatar
Indigo-Glow
Posts: 14
Joined: November 4th, 2011, 4:59 pm
Location: US

Re: IfAboveAction & IfBelowAction Issues (CPU Calc)

Post by Indigo-Glow »

After much tweaking, I finally got it to work. Thanks so very much. I also really appreciate the explanation. :D
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfAboveAction & IfBelowAction Issues (CPU Calc)

Post by jsmorley »

Glad to help.
User avatar
Indigo-Glow
Posts: 14
Joined: November 4th, 2011, 4:59 pm
Location: US

Re: IfAboveAction & IfBelowAction Issues (CPU Calc)

Post by Indigo-Glow »

Just thought I'd mention I finished working on this project. I posted a short tidbit about it here: http://rainmeter.net/forum/viewtopic.php?f=27&t=12241&start=10

And who knows, you might get some extra hits to your DA page, as I credit you on my DA Submission post for your help, heh.