It is currently March 29th, 2024, 8:11 am

A Quote a Day

Get help with creating, editing & fixing problems with skins
User avatar
Harkeerat16
Posts: 15
Joined: June 10th, 2017, 10:54 am
Location: India

A Quote a Day

Post by Harkeerat16 »

Hi, everyone!
So, I've created a Quote a day skin and set the Update Divider to 86400 so it updates in 24 hours, except the skin updates every time on reboot as well, changing the quote meant for that particular day. Is there any way to avoid it from doing so? Please let me know! Thanks.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A Quote a Day

Post by balala »

Harkeerat16 wrote:So, I've created a Quote a day skin and set the Update Divider to 86400 so it updates in 24 hours, except the skin updates every time on reboot as well, changing the quote meant for that particular day. Is there any way to avoid it from doing so?
No, probably there is not, because on reboot, the skin is not update, but loaded and in such cases the Quote plugin every time generates a new random value. Same happens not just on reboot, but even if you're refreshing the skin.
But post please your code. I'd like to take a look and will try to figure out something. If there is needed any included file, please post that as well.
User avatar
Harkeerat16
Posts: 15
Joined: June 10th, 2017, 10:54 am
Location: India

Re: A Quote a Day

Post by Harkeerat16 »

Thank you!
Here's the code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeterBackground]
Meter=Image
ImageName=#@#\quote_bg.png
DynamicVariables=1

[MeasureQuote]
Measure=Plugin
Plugin=QuotePlugin
PathName=#@#/quote-list.txt
UpdateDivider=86400

[MeterQuote]
Meter=String
MeasureName=MeasureQuote
Meter=String
ClipStringW=1200
ClipString=1
FontFace=JohnDoe
FontColor=0,0,0
FontSize=11
AntiAlias=1
H=229
W=228
X=85
Y=82
DynamicVariables=1
And I'm using this image as a background for the quotes: https://imgur.com/EkQPxfo
Also, I just had an idea that maybe we could measure the time and use it in an if condition? Like, if the time is greater than 12 a.m update the skin or else don't? Would that work?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A Quote a Day

Post by balala »

Harkeerat16 wrote:Also, I just had an idea that maybe we could measure the time and use it in an if condition? Like, if the time is greater than 12 a.m update the skin or else don't? Would that work?
No, it wouldn't. At least not as you'd like. Because with this solution, when you reboot the computer, when the skin is loaded, it generates a new quotation. If you don't shut down the computer it'd work, but if you do...
So we need another approach. Here is one:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
CurrentQuote=Anything

[MeasureDay]
Measure=Time
Format=%d
OnChangeAction=[!EnableMeasure "MeasureQuote"][!UpdateMeasure "MeasureQuote"]

[MeterBackground]
Meter=Image
ImageName=#@#quote_bg.png
DynamicVariables=1
UpdateDivider=-1

[MeasureQuote]
Measure=Plugin
Plugin=QuotePlugin
PathName=#@#quote-list.txt
UpdateDivider=-1
Disabled=1
OnUpdateAction=[!WriteKeyValue Variables CurrentQuote "[MeasureQuote]"][!SetVariable CurrentQuote "[MeasureQuote]"][!UpdateMeter "MeterQuote"][!Redraw]

[MeterQuote]
Meter=String
Meter=String
ClipStringW=1200
ClipString=1
FontFace=JohnDoe
FontColor=0,0,0
FontSize=11
AntiAlias=1
H=229
W=228
X=85
Y=82
Text=#CurrentQuote#
DynamicVariables=1
UpdateDivider=-1
Now a few words about this code:
First I introduced a CurrentQuote variable (into the [Variables] section). This will keep the last generated quotation. Later we'll modify its value (see below).
In the very first moment, the [MeasureQuote] measure (which generates the random quote) is disabled (with the Disabled=1 option). So, we'll need to enable it in the right moment. We had to disable it, to avoid it to generate a new value when the skin is loaded. The same QuotePlugin measure also has set the UpdateDivider value to -1, which means that even enabled, it is never updated (just when a !UpdateDivider bang is used).
I added a Time measure ([MeasureDay]), which returns the value of the current day. When its value is changing, means that a new day had came, so we have to update the quotation (here is a limitation of the skin, see below). In this moment the OnChangeAction option enables and updates the [MeasureQuote] measure. Due to these operation, it generates a new random quote. It being updated, its OnUpdateAction option writes the newly generated value into the [Variables] section (as the CurrentQuote variable) and also dynamically sets this new value for the variable, along with updating the [MeterQuote] string meter (I also added an UpdateDivider=-1 option to this meter, to avoid its repetated update - it has to be updated once per day). This dynamically set new value will be seen into the String meter.
If you refresh the skin (or reboot the computer) the String meter will show the last set quotation. The Quote Plugin doesn't generates a new value, being disabled. When the day changes, a new quote is generated (as described above).
And here is the limitation of the code: it generates a new quotation when the day is changing (at midnight). I think a bit more complicated solution could be used to generate the new quotation in any moment of the day, but first I'd like to know if this is enough for you (to change the quotation at midnight). Is it?
User avatar
Harkeerat16
Posts: 15
Joined: June 10th, 2017, 10:54 am
Location: India

Re: A Quote a Day

Post by Harkeerat16 »

balala wrote: And here is the limitation of the code: it generates a new quotation when the day is changing (at midnight). I think a bit more complicated solution could be used to generate the new quotation in any moment of the day, but first I'd like to know if this is enough for you (to change the quotation at midnight). Is it?
Yep, I'd like the quote to change at midnight and not at a particular time in a day, so this is enough!

And I'm glad you could think of this logic, it works brilliantly. Thank you! :rofl:
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A Quote a Day

Post by balala »

Glad to help.

Just an observation about your initial code. For example in the [MeasureQuote] measure you've set the PathName as PathName=#@#[color=#FF0000]/[/color]quote-list.txt, respectively in the [MeterBackground] meter, the ImageName is set as ImageName=#@#[color=#FF0000]\[/color]quote_bg.png. In none of this cases the slash or backslash isn't needed at all, because the #@# variable contains a backslash at its end. Any of these possibilities works and even work if add further backslashes, eg the following form also works: ImageName=#@#\\\\\quote_bg.png. But those characters are not needed. Read the PS here: https://forum.rainmeter.net/viewtopic.php?p=111157#p111157.
Jcee
Posts: 8
Joined: December 11th, 2017, 8:21 am

Re: A Quote a Day

Post by Jcee »

just store the date, and compare the current date, on refresh with the stored date.
If its newer; refresh the quote, and overwrite the stored date

This way your computer doesn't need to be on exactly at midnight for the quote to be refreshed
[EDIT: It appears that's what you did :oops: Maybe I should read the code, instead of just the text, next time}
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A Quote a Day

Post by balala »

Jcee wrote:[EDIT: It appears that's what you did :oops: Maybe I should read the code, instead of just the text, next time}
Not exactly. I didn't store the date, just the quote.
As usually, there're more ways to achieve something. You can write your own code, post it, then Harkeerat16 will choose which one wants he to use.
User avatar
Harkeerat16
Posts: 15
Joined: June 10th, 2017, 10:54 am
Location: India

Re: A Quote a Day

Post by Harkeerat16 »

balala wrote:Glad to help.

Just an observation about your initial code. For example in the [MeasureQuote] measure you've set the PathName as PathName=#@#[color=#FF0000]/[/color]quote-list.txt, respectively in the [MeterBackground] meter, the ImageName is set as ImageName=#@#[color=#FF0000]\[/color]quote_bg.png. In none of this cases the slash or backslash isn't needed at all, because the #@# variable contains a backslash at its end. Any of these possibilities works and even work if add further backslashes, eg the following form also works: ImageName=#@#\\\\\quote_bg.png. But those characters are not needed. Read the PS here: https://forum.rainmeter.net/viewtopic.php?p=111157#p111157.
Ah, I had no clue that rainmeter just ignores those slashes! Thanks for informing me about that. :D
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A Quote a Day

Post by balala »

Harkeerat16 wrote:Ah, I had no clue that rainmeter just ignores those slashes! Thanks for informing me about that. :D
As always, I'm glad to help.