It is currently April 19th, 2024, 5:33 am

Some issues with !Refresh

Get help with creating, editing & fixing problems with skins
Wim
Posts: 69
Joined: September 22nd, 2010, 8:30 pm

Some issues with !Refresh

Post by Wim »

I'm building a skin that gets information from a website, but i need to change the regexp it uses from day to day. I have a RunCommand measure write a new one to an .inc file on load. The skin on load however first loads the regexp from yesterday, so i have to manually refresh it in order to get webparser to use the new one.

I want to refresh the skin on load once, so it will update without me having to manually refresh it, so i use the following code

Code: Select all

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=5
IfEqualAction=[!Refresh]
UpdateDivider=-1
It doesn't work. The skin just sits there and nothing changes. If i look in Rainmeters 'about' section i'm seeing the old variables from the include file, but not the updated ones that are actually in that file when i check it. It was my understanding that !Refresh would also update variables from the inc file, but that doesn't seem to be happening.

A weird thing is, that while i was experimenting with the code i ended up with this:

Code: Select all

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=5
IfEqualAction=[!Refresh]
[!CommandMeasure MeasureWebParser Update][!Redraw]
UpdateDivider=-1
It's a pretty loopy sort of code, but it does refresh the skin and updates the variables from the inc file. Problem solved it seems.

Still: I figure there is something essential about !Refresh that i missed, but even after reading the documentation and browsing through the forum i'm none the wiser. And that strange piece of code i found is - in my understanding - not the way it ought to work.

What am i doing wrong here. And I would like to know what the correct way is to get this done. Anyone any advice?
Last edited by Wim on February 27th, 2020, 8:34 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some issues with !Refresh

Post by balala »

Wim wrote: February 27th, 2020, 7:56 pm It doesn't work. The skin just sits there and nothing changes. If i look in Rainmeters 'about' section i'm seeing the old variables from the include file, but not the updated ones that are actually in that file when i check it. It was my understanding that !Refresh would also update variables from the inc file, but that doesn't seem to be happening.
Refreshing a skin indeed refresh the variables, but Counter is not a variable, but a function. In fact it is a quite weird function, which is reseted ONLY if you unload the skin, then load it again. Refresh doesn't reset Counter. Details: https://docs.rainmeter.net/manual/measures/calc/#Formulas
Wim
Posts: 69
Joined: September 22nd, 2010, 8:30 pm

Re: Some issues with !Refresh

Post by Wim »

I got that idea after reading this post:

https://forum.rainmeter.net/viewtopic.php?p=100888#p100888

,so i used this method.

The idea was to update the skin a few seconds after load with the new variables from the inc file. It has to be done only once and not more
The point is the use of !Refresh in this way. I'm seeing no update of the variables from the inc file. Can i use !Refresh in this way?
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some issues with !Refresh

Post by balala »

Wim wrote: February 27th, 2020, 8:33 pm The idea was to update the skin a few seconds after load with the new variables from the inc file. It has to be done only once and not more
The point is the use of !Refresh in this way. I'm seeing no update of the variables from the inc file. Can i use !Refresh in this way?
When you refresh a skin, it rebuilds everything: re-reads the variables, restarts the measures and so on. One single thin git doesn't do: the Counter function isn't restarted. It continues to count, doesn't restart this counting from 0. In order to restart it, you have to unload the skin, then load it again.
So in your case the refresh take place five seconds after the load of the skin. It isn't triggered once again later, because the Counter function doesn't reset. But if you simply refresh the skin, it probably will use the same variable as first time. To change it, you probably have to rewrite it, using for instance a !WriteKeyValue bang.
Not knowing the entire code, it is hard to say something better than this.
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Some issues with !Refresh

Post by Yincognito »

Wim wrote: February 27th, 2020, 7:56 pm I'm building a skin that gets information from a website, but i need to change the regexp it uses from day to day. I have a RunCommand measure write a new one to an .inc file on load. The skin on load however first loads the regexp from yesterday, so i have to manually refresh it in order to get webparser to use the new one.

[...]

A weird thing is, that while i was experimenting with the code i ended up with this:

Code: Select all

[MeasureOnLoad]
Measure=Calc
Formula=Counter
IfEqualValue=5
IfEqualAction=[!Refresh]
[!CommandMeasure MeasureWebParser Update][!Redraw]
UpdateDivider=-1
It's a pretty loopy sort of code, but it does refresh the skin and updates the variables from the inc file. Problem solved it seems.

Still: I figure there is something essential about !Refresh that i missed, but even after reading the documentation and browsing through the forum i'm none the wiser. And that strange piece of code i found is - in my understanding - not the way it ought to work.

What am i doing wrong here. And I would like to know what the correct way is to get this done. Anyone any advice?
Well, that says it all, actually. I believe you don't need any refresh at all to do what you want, probably just command the WebParser measure in your skin to update and redraw the skin. As balala wrote, Counter is a function that doesn't reset when the skin is refreshed, but then, if I'm right and you don't need any refresh, I think you can use it - especially considering you want to do this just one time.

Seeing that you found out a solution, but you want to know why that worked and what did you miss, you could make a backup of your skin (maybe your .inc as well), then try with the same code as the one I quoted above, but without [!Refresh] (and obviously, the WebParser command should be on the same line as IfEqualAction, at least for clarity) - see if that works. If it does, you found the explanation; if it doesn't, you probably have to update the relevant measures/meters in your skin before the [!Redraw] bang.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Some issues with !Refresh

Post by eclectic-tech »

Code: Select all

[MeasureRunOnce]
Measure=Calc
Formula=Counter
IfEqualValue=5
IfEqualAction=[!CommandMeasure MeasureWebParser Update][!UpdateMeter *][!Redraw][!DisableMeasure MeasureRunOnce]
The reason your first attempt did not work, as you found out, is that the Webparser measure uses an internal UpdateRate, so refreshing the skin would not refresh the Webparser.

You correctly need to use [!CommandMeasure MeasureWebparser "Update"] in order to force the measure to re-read the web source.


I added an action to update all meters, then redraw. You could also disabled 'MeasureRunOnce'; although you don't need to do that since the 'counter' will never equal 5 again until the skin is unloaded and re-loaded.

'RunOnce' measures can be very useful, but you need to consider what action bangs are needed as in the case of a Webparser measure update.

EDIT: Removed my inaccurate statement (Thanks balala!) Apparently you have something in your code that requires you to force an update rather than just refresh....
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some issues with !Refresh

Post by balala »

eclectic-tech wrote: February 28th, 2020, 2:50 am so refreshing the skin would not refresh the Webparser.
I'm sorry, but I don't agree with this.
When the skin is loaded or refreshed, the WebParser measure accesses the remote resource (either the web resource, or the file, depending on how is it set). Later a such update is made on each interval equal with UpdateRate x UpdateDivider (don't forget that setting an UpdateDivider on a parent WebParser measure is not impossible, however it's neither recommended).
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Some issues with !Refresh

Post by Yincognito »

Another possibility is that the OP needs to actually update the WebParser twice (not once) to get those "new values" in his .inc file. It's hard to tell from the scarce info we got, but that could also explain why the 2nd code sample he posted worked. Who knows, maybe that's the process in his skin...
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Wim
Posts: 69
Joined: September 22nd, 2010, 8:30 pm

Re: Some issues with !Refresh

Post by Wim »

Yincognito wrote: February 28th, 2020, 10:40 pm It's hard to tell from the scarce info we got,
I understand. Sorry for that. My skin is getting information from a municipial website that is to some extent somewhat privacy sensitive, so i'm not happy with the idea of pasting that all over the internet. I've been working, however, on some basic code to duplicate the problem. This is what i came up with.

Code: Select all

[Rainmeter]
Update=1000

;---------------------------------------------

[Variables]

@include=Test.inc

;------------------------------------

[MeasureOnLoad1]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=[!EnableMeasure MeasureCondition]
UpdateDivider=-1

;------------------------------------

[MeasureCondition]
Measure=String
String=#number#
IfMatch=2
IfMatchAction=[!EnableMeasure MeasureEcho1][!CommandMeasure MeasureEcho1 "Run"]
IfNotMatchAction=[!EnableMeasure MeasureEcho2][!CommandMeasure MeasureEcho2 "Run"]
Disabled=1

;----------------------------------------------

;[MeasureOnLoad2]
;Measure=Calc
;Formula=Counter
;IfEqualValue=5
;IfEqualAction=[!Refresh]
;UpdateDivider=-1

[MeasureOnLoad2]
Measure=Calc
Formula=Counter
IfEqualValue=3
IfEqualAction=[!Refresh]
[!CommandMeasure 12345678 Update][!Redraw]
;[!CommandMeasure MeasureSFISGUGDII Update][!Redraw]
;[!CommandMeasure Measure12345678 Update][!Redraw]
;[!CommandMeasure MeasureWebparser Update][!Redraw]
UpdateDivider=-1

;------------------------------------

[MeasureEcho1]
Measure=Plugin
Plugin=RunCommand
Parameter=echo [Variables] > #CURRENTPATH#Test.inc && echo number=1 >> #CURRENTPATH#Test.inc && echo check=%time% >> #CURRENTPATH#Test.inc
State=Hide
OutputType=ANSI
Disabled=1

[MeasureEcho2]
Measure=Plugin
Plugin=RunCommand
Parameter=echo [Variables] > #CURRENTPATH#Test.inc && echo number=2 >> #CURRENTPATH#Test.inc && echo check=%time% >> #CURRENTPATH#Test.inc
State=Hide
OutputType=ANSI
Disabled=1

;------------------------------------

[Meter1]
;MeasureName=MeasureWebParser
Meter=STRING
X=5
Y=5
FontColor=FFFFFF
FontSize=16
AntiAlias=1
;StringAlign=LEFT
Text= #number#


[Meter2]
Meter=STRING
X=5
Y=31
W=150
H=26
FontColor=FFFFFF
FontSize=16
AntiAlias=1
;StringAlign=LEFT
Text= #check#
You will also need een .inc file (#CURRENTPATH#Test.inc) in the same folder. Here's the basic idea

Code: Select all

[Variables]  
number=1  
check=11:53:42,54 
This code will write a number and a timestamp in your 'local' OS format to the inc file. The goal is that the information in the .inc file should be identical as to that displayed by the skin.

The skin wil on load show the information from the previous session. I want it to reread the inc file and display the information that was written on load of the current session

The action to perform in order to check this, is to simply load and unload the skin. 3 seconds after loading the skin, you'll see it updates the information shown and you can verify that is the same as in the inc file.

---

It's the calc measure MeasureOnLoad2 that is the problem here

The following code works

Code: Select all

[MeasureOnLoad2]
Measure=Calc
Formula=Counter
IfEqualValue=3
IfEqualAction=[!Refresh]
[!CommandMeasure 12345678 Update][!Redraw]
UpdateDivider=-1
The bang

Code: Select all

[!CommandMeasure 12345678 Update][!Redraw]
is not even looking for an existing measure. Any name will do.

In my understanding this is all wrong but it refreshes the skin 3 seconds after loading and will then display the same information as was written to the inc. on load of the current session.

I hope you'll understand what i'm trying to do.

The question is:

What is the correct way of achieving this? What is the correct code for making the reread the inc file and display the updated information.

I appreciate the input you all gave so far and i'm sorry if my question wasn't entirely clear.
Wim
Posts: 69
Joined: September 22nd, 2010, 8:30 pm

Re: [SOLVED] Some issues with !Refresh

Post by Wim »

I found the answer

The code i was using was

Code: Select all

[MeasureOnLoad2]
Measure=Calc
Formula=Counter
IfEqualValue=5
IfEqualAction=[!Refresh]
UpdateDivider=-1
It didn't work. If i looked in the about screen i saw this:
Counter1.PNG
I suddenly realised that the counter on MeasureOnLoad2 always stops at 1 and therefore never goes to the required value of 5, so there's no refresh.

When i used my own 'incorrect' solution:

Code: Select all

[MeasureOnLoad2]
Measure=Calc
Formula=Counter
IfEqualValue=5
IfEqualAction=!Refresh #CURRENTCONFIG#
[!CommandMeasure Update][!Redraw]
UpdateDivider=-1
the counter does move to 5 and so there's a refresh.
Counter2.PNG
I got the idea from een older post (it's from 2014) that gave the code

Code: Select all

[MeasureOnLoad2]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=!Refresh
UpdateDivider=-1
Note that the counter goes to 1 and that it has een UpdateDiver=-1. That UpdateDivider doesn't let it go beyond 1. It was added as an additional safety in the original code i copied but became an obstacle (without me realising it) in my own code when i changed the counter to 5. I completely overlooked this.

I removed the UpdateDivider and then it worked.

I still don't fully understand the reason why it worked with

Code: Select all

[!CommandMeasure Update][!Redraw]
but OK. It probably forcibly updated the Measure beyond the count of 1. Presumably something like

Code: Select all

OnUpdateAction=[!CommandMeasure MeasureOnLoad2 Update]
[!Redraw]
I spend the better part of two weeks trying to figure this out :oops:

The Devil is in the details :twisted:
You do not have the required permissions to view the files attached to this post.