It is currently March 29th, 2024, 12:58 pm

OnRefreshAction

Discussions about the documentation, main Rainmeter site and forums.
User avatar
Jtmzac
Posts: 26
Joined: January 24th, 2016, 9:11 am
Location: Sydney, Australia

OnRefreshAction

Post by Jtmzac »

After quite a while of being stumped I've worked out that if something is hidden by OnRefreshAction it can't be shown again until after the first update cycle is complete even when it's used with !UpdateMeter/Measure/!Redraw.

I not sure why this happens but I'm guessing either the bangs are performed twice (first when the line is read and secondly when the first update cycle is complete). Or anything changed by OnRefreshAction is "locked" from any changes until the first update cycle is complete.

The manual does talk about actions taking place at the end of the first cycle:
Note: The action(s) defined will take place at the very end of the first update cycle. Changes made will generally not be visible until the next update, unless bangs are used to update desired measures and meters and redraw the skin.
But to me it doesn't really explain that even if the changes are made immediate using !UpdateMeter/Measure/!Redraw you can't change them again until after the first update cycle if complete.

It could just be me but I found this confusing. If anyone else thinks the same perhaps it would help to clarify the documentation a bit.

If you want to see this behaviour here is the little test I used:

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!HideMeter "test_string"][!Redraw]

[test_measure]
Measure=Calc
Formula=1
IfCondition=1=1
IfTrueAction=[!ShowMeter "test_string"]

[test_background]
meter=image
x=0
y=0
w=100
h=24
solidcolor=0,0,0,200

[test_string]
Meter=string
X=4
Y=2
text=test string
fontface=segoe ui
fontsize=10
fontcolor=200,200,200,255
AntiAlias=1
Last edited by Jtmzac on February 11th, 2016, 4:43 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: OnRefreshAction

Post by jsmorley »

I hope I'm following the problem you are describing. It's hard to be sure, since the overall logic of this example is a bit strange... ;-)


First, please fix the IfCondition, since this is invalid and makes no sense:

Formula=1=1
IfCondition=1=1

I assume you mean:

Formula=1
IfCondition=test_measure=1

So if we have this:

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!HideMeter "test_string"]

[test_measure]
Measure=Calc
Formula=1
IfCondition=test_measure=1
IfTrueAction=[!ShowMeter "test_string"]
What will happen is:

1) The meter will be initially shown, both because it has no Hidden=1 on it, and (entirely redundantly) because of the IfTrueAction.
2) At the end of the first update cycle, the meter will be set to hidden by the OnRefreshAction. However...
3) Since any OnRefreshAction takes place LAST in the update cycle, after the redraw even, you won't see the visible change until the next redraw, which will be at the end of the NEXT update cycle.
Result - Meter will be visible for one update (one second in this case) and then hidden.

If we change to this:

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!HideMeter "test_string"][!Redraw]

[test_measure]
Measure=Calc
Formula=1
IfCondition=test_measure=1
IfTrueAction=[!ShowMeter "test_string"]
What will happen is:

1) The meter will be initially shown, both because it has no Hidden=1 on it, and because of the IfTrueAction.
2) At the end of the first update cycle, the meter will be set to hidden by the OnRefreshAction.
3) Any OnRefreshAction takes place LAST in the update cycle, after the redraw even, and you won't see the visible change until the next redraw. However...
4) The !Redaw will force a second - extra redraw of the skin at the very end of the cycle. So in effect it will be show > redraw > hide > redraw all in the context of the first update.
Result - Meter will for all intents and purposes be hidden from the start.

I think the only slightly confusing bit is that OnRefreshAction, which by its nature comes first in the skin code, happens AFTER the first complete Update cycle is done, including after the first time the skin is "drawn". However, explaining that is the point of this note:
Note: The action(s) defined will take place at the very end of the first update cycle. Changes made will generally not be visible until the next update, unless bangs are used to update desired measures and meters and redraw the skin.
Could that be written more clearly? I'm open to suggestion.


The long and the short of it is that when a skin is loaded or refreshed it does:

Update measures
Update meters
Draw skin
Execute OnRefreshAction

followed by an endless loop of:

Wait Update millisconds
Update measures
Update meters
Draw skin
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: OnRefreshAction

Post by balala »

jsmorley wrote:I hope I'm following the problem you are describing. It's hard to be sure, since the overall logic of this example is a bit strange... ;-)


First, please fix the IfCondition, since this is invalid and makes no sense:

Formula=1=1
IfCondition=1=1

I assume you mean:

Formula=1
IfCondition=test_measure=1
I think Jtmzac's logic was a bit different:
On the Formula=1=1 option, the formula is 1=1, which always will be 1, because 1 is always equal with 1, so this is expression is always true, which means it is 1. And yes, the result is the same, but the logic is different.
On the other hand, the IfCondition is always true, for the same reason: 1 is always equal with 1.
Strange, very strange approach, indeed. And the posted code, don't even work for me, I can't see anything else there, just a black rectangle (the [test_background] meter).
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: OnRefreshAction

Post by jsmorley »

balala wrote:I think Jtmzac's logic was a bit different:
On the Formula=1=1 option, the formula is 1=1, which always will be 1, because 1 is always equal with 1, so this is expression is always true, which means it is 1. And yes, the result is the same, but the logic is different.
On the other hand, the IfCondition is always true, for the same reason: 1 is always equal with 1.
Ah, you are right balala, his initial logic for the Calc measure is valid. It just hurt my head a bit, since

Formula=1=1

is more appropriate for a "test" for true and false, and doesn't really make a lot of sense as a mathematical formula, even though it does end up being equal to "true" or "1".

So

[test_measure]
Measure=Calc
Formula=PI
IfCondition=1=1
IfTrueAction=[!ShowMeter "test_string"]

Would work just as well. In this case the IfCondition "test" is always going to be "true" (1 does equal 1) and the Formula is really irrelevant. The Calc measure is just acting as a "host" for the IfCondition.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: OnRefreshAction

Post by balala »

jsmorley wrote:It just hurt my head a bit
I'm not surprised at all. I also looked to the initial code a few times until I understood it. As I said, it's strange, but finally it's correct, I think.
jsmorley wrote:In this case the IfCondition "test" is always going to be "true" (1 does equal 1) and the Formula is really irrelevant. The Calc measure is just acting as a "host" for the IfCondition.
There could be used any formula, as any of them is irrelevant.
Last edited by balala on February 11th, 2016, 3:30 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: OnRefreshAction

Post by jsmorley »

As to the overall logic of the example, whether the intent is that the meter be hidden or shown, I have no idea what he is going for, and assume this example is just meant to demonstrate some confusion with the order that things are done in the update cycle when an OnRefreshAction is involved.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: OnRefreshAction

Post by balala »

jsmorley wrote:As to the overall logic of the example, whether the intent is that the meter be hidden or shown, I have no idea what he is going for, and assume this example is just meant to demonstrate some confusion with the order that things are done in the update cycle when an OnRefreshAction is involved.
As I said, I can't see anything else there, just the [test_background] meter. That code don't really works for me.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: OnRefreshAction

Post by jsmorley »

balala wrote:As I said, I can't see anything else there, just the [test_background] meter. That code don't really works for me.
Right. Well, for whatever reason, he has a meter that is initially "shown" due to not being Hidden=1 and then redundantly setting it "visible" with the IfTrueAction, followed at the end of the cycle with an OnRefreshAction that hides it and redraws the skin. No useful purpose at all, he might as well just leave the meter out of the skin entirely. However I suspect this was just an example to demonstrate something he didn't like or understand about how OnRefreshAction works in the context of the update cycle, and doesn't have any other real purpose. Hopefully my initial explanation makes things more clear.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: OnRefreshAction

Post by balala »

jsmorley wrote:Hopefully my initial explanation makes things more clear.
Surely.
User avatar
Jtmzac
Posts: 26
Joined: January 24th, 2016, 9:11 am
Location: Sydney, Australia

Re: OnRefreshAction

Post by Jtmzac »

My apologies for not being clearer. Rainmeter isn't the easiest thing to explain in text.

The calc measure isn't supposed to do anything. I should have just put formula=1. My brain isn't fully in rainmeter mode today. You were right that it's only there to "host" the ifcondition.

As you worked out the IfCondition is intentionally always true as I was just trying to demonstrate a behaviour.
jsmorley wrote: 4) The !Redraw will force a second - extra redraw of the skin at the very end of the cycle. So in effect it will be show > redraw > hide > redraw all in the context of the first update.
Result - Meter will for all intents and purposes be hidden from the start.
This is definitely the bit that was puzzling me. The visible affect of using the !Redraw is that the !HideMeter is performed at the start of the first cycle instead of at the very end so I had expected the ifcondition to to be run after it since it's further down in the skin.

What confused me was the OnRefreshAction still happening the second time at the very end of the update cycle.

I was hoping this could be made a bit clearer in the documentation but it's hard to word it correctly.

Here's my best attempt:
Note: The action(s) defined will take place at the very end of the update cycle. Changes made will generally not be visible until the next update, unless bangs are used to update desired measures and meters and redraw the skin. If bangs are used to update desired measures and meters and redraw the skin the changes will take place both at the time the bangs are read and at the very end of the update cycle.
I'm not sure about the "bangs are read" bit. I don't think the wording is right for how rainmeter works.

Thanks for all your effort trying to understand me.