It is currently April 19th, 2024, 7:15 am

Help with Quotes Skin

Get help with creating, editing & fixing problems with skins
Tomato
Posts: 4
Joined: May 14th, 2012, 9:04 pm

Help with Quotes Skin

Post by Tomato »

Hi Rainmeter forums! This is an amazing desktop tool and an amazing community for it. Currently running Serenity.

I'm trying to create a little skin plugin that will display random quotes from a text file I have. The topic has been addressed in the past. I grabbed the files from this topic and loaded everything, put things in their correct places, but it does not seem to be working for me. Here is a screenshot of the error that pops up. I tried editing the code prior to this (since I was getting even more errors than this) to fix it, so here is what I have so far.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
Minutes=2

[MeasureQuote]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#C:\Users\Tomato\My Documents\Rainmeter\Skins\QuotesRead#Listofquotes.txt
UpdateDivider=(#Minutes# * 60)

[MeterQuote]
Meter=String
MeasureName=MeasureQuote

; ------------------------------------------------------------------------------------------------
; SCREEN LABELS


[QuoteText]
MeasureName=QuoteSource
Meter=String
X=7
Y=40
W=660
H=300
StringStyle=Normal
FontColor=255,255,255,255
FontSize=14
FontFace="Times New Roman"
AntiAlias=1
ClipString=1
Any help anyone could provide would be HUGELY appreciated. Thanks!
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with Quotes Skin

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
Minutes=2

[MeasureQuote]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
;PathName=#C:\Users\Tomato\My Documents\Rainmeter\Skins\QuotesRead#Listofquotes.txt
PathName=#ROOTCONFIGPATH#Listofquotes.txt
UpdateDivider=(#Minutes# * 60)

[QuoteText]
;MeasureName=QuoteSource
MeasureName=MeasureQuote
Meter=String
X=7
Y=40
W=660
H=300
StringStyle=Normal
FontColor=255,255,255,255
FontSize=14
FontFace="Times New Roman"
AntiAlias=1
ClipString=1
So the first thing is that the PathName= you are using on the Quote plugin isn't correct. First, you should not have the "#" characters on it, as it is not either a built-in or user defined variable. So #C:\Users\Tomato\My Documents\Rainmeter\Skins\QuotesRead# won't resolve to anything. Instead, I used the built-in variable #ROOTCONFIGPATH#, which will point to the folder under \Skins\ that is the highest level one where your skin lives. So in this instance the text file would be in:

C:\Users\Tomato\My Documents\Rainmeter\Skins\QuotesRead\Listofquotes.txt and you access it using PathName=#ROOTCONFIGPATH#Listofquotes.txt.

http://rainmeter.net/cms/Settings-BuiltInVariables_beta?hl=ROOTCONFIGPATH

Second, you have an extra meter there, [MeterQuote], that doesn't seem to have any formatting and looks like it might have been left over from something.

Then you have a meter [QuoteText], that seems to be the one you want to use. The problem is, it is referencing a measure in MeasureName= that doesn't exist. So I fixed that.

With those changes, it works for me.
Tomato
Posts: 4
Joined: May 14th, 2012, 9:04 pm

Re: Help with Quotes Skin

Post by Tomato »

Amazing!! Didn't expect a response that quickly, especially not one that successful. Thanks a lot! One other thing I am interested in is having the quotation followed by the author name, but smaller than the quote, such as in this example. The author name doesn't have to be on a separate line. I'd just like it to be smaller. I'd be willing to format my quotation document any which way in order to make this possible. Any suggestions or help on this? Thanks in advance.

edit: If it's too difficult or not possible, no worries. This looks great as it is.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with Quotes Skin

Post by jsmorley »

Tomato wrote:Amazing!! Didn't expect a response that quickly, especially not one that successful. Thanks a lot! One other thing I am interested in is having the quotation followed by the author name, but smaller than the quote, such as in this example. The author name doesn't have to be on a separate line. I'd just like it to be smaller. I'd be willing to format my quotation document any which way in order to make this possible. Any suggestions or help on this? Thanks in advance.
That is an entirely different kettle of fish I"m afraid. The way Quote plugin works is that it returns one random "item" from a text file, where you can define what constitutes an "item" by using Separator= as an option to the plugin. The default is a new line, so normally each update of the measure would return one random line from the file. If you put for instance the quote and the author each on its own line, then you can tell Quote to use some "string" as the separator, for example you might have the quote file formatted as:

Getting older is no problem. You just have to live long enough.
Groucho Marx</end>
I don't care to belong to a club that accepts people like me as members.
Groucho Marx</end>

Then you would use Separator="</end>" on the Quote measure, and it would return both the quote and the author as the value of the measure, with the newline between them embedded.

However... That doesn't really help you with your specific need. Since a single value is returned, you can't really put the result in two meters, which is what is required to have different text formatting for the quote vs. the author.

In order to have both the random nature of Quote plugin, along with the ability to get both the quote and the author in two different measures, while keeping them logically connected, we are going to have to take a different approach.

We could use WebParser to get all the quotes and the authors into measures, using formatting of the text file to make it easy to parse. Then we could use a trick with a Calc measure returning a random number to force the string meter(s) to display a random "set" of quote and author. The trouble with this is that:

1) You would need a TON of WebParser measures to get all the quote and author lines into StringIndexes you could use. You can't tell WebParser to get a random line from a file, and since WebParser can't have a dynamic RegExp= line, you can't trick that by formatting the text file with embedded line numbers or something. You would just have to create a whole bunch of WebParser measures.

2) You would effectively be limited to 49 quotes. WebParser can only return 99 StringIndexes, and since you would need two for each set of quote and author, that would be the limit.

So I hate the WebParser approach. Instead I think the best thing is some Lua code.

First off, be sure that you have the latest beta version of Rainmeter from http://rainmeter.net.

Now, format your Listofquotes.txt text file like this:

Code: Select all

<quote>Any sufficiently advanced incompetence is indistinguishable from malice.
<author>Jane One
<quote>I just thought of the best hyperbole.
This is the second line of the quote.
<author>Jane Two
<quote>For Sale: Parachute. Only used once, never opened, small stain.
<author>Jane Three
<quote>A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and Tequila.
<author>Jane Four
<quote>A ship in the harbor is safe, but that is not what ships were made for.
<author>Jane Five
<quote>Never do your best card tricks for the group you play poker with.
<author>Jane Six
<quote>Age and Treachery Will Always Overcome Youth and Skill
<author>Jane Seven
<quote>If I had known I was going to live this long, I'd have taken better care of myself.
<author>Jane Eight
Now create a skin that looks like this. Make any changes to how the meters are formatted or laid out you like:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
Minutes=2

[MeasureQuote]
Measure=Script
ScriptFile=Test.Lua
UpdateDivider=(#Minutes# * 60)

[MeterQuote]
Meter=String
FontSize=13
FontColor=255,255,255,255
StringStyle=Bold
AntiAlias=1

[MeterAuthor]
Meter=String
Y=2R
FontSize=11
FontColor=255,255,255,255
StringStyle=BoldItalic
AntiAlias=1
Then create a text file, with the extension .lua in the same folder. I used "text.lua" in my example, be sure to change both the name of the file and the ScriptName= setting on the measure to have a name you like. Paste this code into that .lua file.

Code: Select all

function Initialize()

   CURRENTPATH = SKIN:GetVariable('CURRENTPATH')
   Quotes = {}
   Authors = {}
   i = 0

   for line in io.lines(CURRENTPATH..'Listofquotes.txt') do
		if string.sub(line, 1, 7) == '<quote>' then
			i = i + 1
			Quotes[i] = string.sub(line, 8)
		elseif string.sub(line, 1, 8) == '<author>' then
			Authors[i] = string.sub(line, 9)
		else
			Quotes[i] = Quotes[i]..'#CRLF#'..line
		end
	end
   
end -->Initialize

function Update()

   rand = math.random(1, #Quotes)
   SKIN:Bang('!SetOption', 'MeterQuote', 'Text', Quotes[rand])
   SKIN:Bang('!SetOption', 'MeterAuthor', 'Text', Authors[rand])
   
   return 'Quote number: '..rand
   
end -->Update
That's it. A very simple skin, with only one measure and one each of quote and author meters. The Lua script will read in the text file with the quotes, put the quotes and the authors into tables (like an array) and then select one based on a random number. Then it will use !SetOption bangs to set the value of the two meters and you are done.

I'm happy to explain anything you don't understand. The Lua can look daunting if you have not messed with it before, but it's not really hard.

Sorry this got kinda long... :-) I really wanted to explain a bit of why and how I ended up where I did.
Tomato
Posts: 4
Joined: May 14th, 2012, 9:04 pm

Re: Help with Quotes Skin

Post by Tomato »

No apologies!!! :o I really didn't expect any help on that one. You really are amazing for lending all this help for free. Though, I'm a bit clueless on this and I suspect I must have messed something, as the plugin isn't functioning correctly. This is what I did.

I created a folder called QuotesAuthor for all three files.
I created an ini file and posted the following code.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
Minutes=2

[MeasureQuote]
Measure=Script
ScriptFile=Quotes.Lua
UpdateDivider=(#Minutes# * 60)

[MeterQuote]
Meter=String
FontSize=13
FontColor=255,255,255,255
StringStyle=Bold
AntiAlias=1

[MeterAuthor]
Meter=String
Y=2R
FontSize=11
FontColor=255,255,255,255
StringStyle=BoldItalic
AntiAlias=1
Next, I made a text file and pasted the following into it, and then changed the extension to .lua.

Code: Select all

function Initialize()

   CURRENTPATH = SKIN:GetVariable('CURRENTPATH')
   Quotes = {}
   Authors = {}
   i = 0

   for line in io.lines(CURRENTPATH..'Quotes.txt') do
      if string.sub(line, 1, 7) == '<quote>' then
         i = i + 1
         Quotes[i] = string.sub(line, 8)
      elseif string.sub(line, 1, 8) == '<author>' then
         Authors[i] = string.sub(line, 9)
      else
         Quotes[i] = Quotes[i]..'#CRLF#'..line
      end
   end
   
end -->Initialize

function Update()

   rand = math.random(1, #Quotes)
   SKIN:Bang('!SetOption', 'MeterQuote', 'Text', Quotes[rand])
   SKIN:Bang('!SetOption', 'MeterAuthor', 'Text', Authors[rand])
   
   return 'Quote number: '..rand
   
end -->Update
Lastly, I created a file and titled it Quotes.txt with the quotes you used in the sample.
I currently don't see any text though. What am I doing wrong? Thanks so much
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with Quotes Skin

Post by jsmorley »

Be sure the file you created for the Lua is really Quotes.Lua and not Quotes.lua.txt

If you created the file in Notepad and saved it, Notepad stupidly adds .txt to the end, and if you have "hide extensions of known file types" set in Explorer, you won't see it.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with Quotes Skin

Post by jsmorley »

Also, be sure you have the latest beta of Rainmeter from http://rainmeter.net. You should be using 2.3 r1377, as I used a code style in the !SetOption bangs in the Lua that requires it.
Tomato
Posts: 4
Joined: May 14th, 2012, 9:04 pm

Re: Help with Quotes Skin

Post by Tomato »

Works magnificently now! Thanks! Didn't have the beta (was worried about instability). I hope someone else will be able to make use of this fantastically helpful thread. Thanks again, thanks again, thanks again. I owe you...
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with Quotes Skin

Post by jsmorley »

Glad to help. The betas are really pretty reliable, so I wouldn't worry about that.
Ninjaki8
Posts: 2
Joined: October 7th, 2018, 5:14 pm

Re: Help with Quotes Skin

Post by Ninjaki8 »

That code was exactly what i was looking for,
Thank You!!