It is currently October 13th, 2024, 12:33 am

Limitation of Quotes Plugin

Share and get help with Plugins and Addons
JSchmoe333
Posts: 1
Joined: December 20th, 2011, 4:03 am

Limitation of Quotes Plugin

Post by JSchmoe333 »

I'm presently trying to make a simple quotations skin that will read a random quote from a text file and display. Perfect job for the Quotes plugin right? Well, what I'm trying to do is style two strings differently and it seems the only way to do that is with two different String meters. I took a look at the WebParser plugin but it didn't seem to have a means to cycle through the quotes. (Randomness is not an absolute requirement in this case.)

If it's not possible using the plugins I've mentioned, it seems like it might be worth it to add the RegExp function to the Quotes plugin to be run on each line (or whatever block of text is queried between the separator each time). In other words, add functionality so that the substrings can be referred to as %1, %2, %3, etc. just like with RegExp.

Here's the code that I have so far. I'll also attach a screenshot that shows it as far as I've taken it. Note the —%2 is where I'm trying place the author's name as it's kind of dark.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Quotations
Description=Cycles through a list of quotations from a text file and displays them one at a time.
Version=1.0.0

[Variables]
Seconds=5
Font=Calibri

[MeasureQuotation]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#CURRENTPATH#quotes.txt
UpdateDivider=#Seconds#

[QuotationText]
Meter=String
MeasureName=MeasureQuotation
MeterStyle=QuotationStyle
Text=%1
X=400
Y=400
W=800
H=200

[QuotationAuthor]
Meter=String
MeasureName=MeasureQuotation
MeterStyle=AuthorStyle
Text=%2
X=400
Y=450
W=800
H=200

[QuotationStyle]
FontColor=255,255,255,255
FontSize=30
StringAlign=CENTER
StringEffect=SHADOW
FontEffectColor=255,255,255,128
FontFace=#Font#
Antialias=1
ClipString=1
Prefix="
Postfix="

[AuthorStyle]
FontColor=0,0,0,204
FontSize=15
StringAlign=CENTER
StringStyle=BOLD
StringCase=UPPER
StringEffect=SHADOW
FontEffectColor=255,255,255,128
FontFace=#Font#
Antialias=1
ClipString=1
Prefix=—

The text file I'm drawing from is just three lines for testing.

Code: Select all

This is CNN. -Wolf Blitzer
We're done here. -Cave Johnson
I'm on a horse. -Old Spice Guy
Thanks for any help the experts can give.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22851
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Limitation of Quotes Plugin

Post by jsmorley »

I think the best way is a little Lua script to solve this:

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Quotations
Description=Cycles through a list of quotations from a text file and displays them one at a time.
Version=1.0.0

[Variables]
Seconds=5
Font=Calibri
CurrentLine=0

[MeasureLuaScript]
Measure=Script
ScriptFile=Quotes.lua
QuoteFile=#CURRENTPATH#Quotes.txt
UpdateDivider=#Seconds#

[QuotationText]
Meter=String
MeterStyle=QuotationStyle
X=400
Y=400
W=800
H=200

[QuotationAuthor]
Meter=String
MeterStyle=AuthorStyle
Text=%2
X=400
Y=450
W=800
H=200

[QuotationStyle]
FontColor=255,255,255,255
FontSize=30
StringAlign=CENTER
StringEffect=SHADOW
FontEffectColor=255,255,255,128
FontFace=#Font#
Antialias=1
ClipString=1
Prefix="
Postfix="

[AuthorStyle]
FontColor=0,0,0,204
FontSize=15
StringAlign=CENTER
StringStyle=BOLD
StringCase=UPPER
StringEffect=SHADOW
FontEffectColor=255,255,255,128
FontFace=#Font#
Antialias=1
ClipString=1
Prefix=—
Quotes.lua (in the same folder)

Code: Select all

PROPERTIES =
{
	QuoteFile= "";
}

function Initialize()
	
	tFileLines = {}
	for line in io.lines(PROPERTIES.QuoteFile) do
		table.insert(tFileLines, line)
	end
	
	iTotal = table.maxn(tFileLines)
	
end -- function Initialize

function Update()

	iCurrentLine = SKIN:GetVariable('CurrentLine')
	iNewLine = iCurrentLine + 1
	sText, sAuthor = string.match(tFileLines[iNewLine], '(.*) %-(.*)')
	
	SKIN:Bang('!SetOption QuotationText Text \"'..sText..'\"')
	SKIN:Bang('!SetOption QuotationAuthor Text \"'..sAuthor..'\"')

	if iNewLine == iTotal then iNewLine = 0 end
	SKIN:Bang('!SetVariable CurrentLine '..iNewLine)
	
	return sText..' -'..sAuthor
   
end -- function Update
Quotes.txt (in the same folder)

Code: Select all

This is CNN. -Wolf Blitzer
We're done here. -Cave Johnson
I'm on a horse. -Old Spice Guy
If you just want a random quote instead of sequential, the Lua is even a bit simpler:

Code: Select all

PROPERTIES =
{
	QuoteFile= "";
}

function Initialize()
	
	tFileLines = {}
	for line in io.lines(PROPERTIES.QuoteFile) do
		table.insert(tFileLines, line)
	end
	
	iTotal = table.maxn(tFileLines)
	
end -- function Initialize

function Update()

	iNewLine = math.random(iTotal)
	sText, sAuthor = string.match(tFileLines[iNewLine], '(.*) %-(.*)')
	
	SKIN:Bang('!SetOption QuotationText Text \"'..sText..'\"')
	SKIN:Bang('!SetOption QuotationAuthor Text \"'..sAuthor..'\"')
	
	return sText..' -'..sAuthor
   
end -- function Update
12-20-2011 2-08-52 AM.jpg
Let me know if you have any questions about what this is doing and how...
You do not have the required permissions to view the files attached to this post.
sonny_G
Posts: 2
Joined: December 29th, 2011, 11:50 am

Re: Limitation of Quotes Plugin

Post by sonny_G »

Hello jsmorley,

Your skin works great and is exactly what I was looking for for a long time! :thumbup:
I have only one issue / request with it.

It only works well, if all quotes are similar in length, i.e. when all quotes require only one line of text, or all quotes require two lines of text. But I can't feed the skin with different long quotes.

Is it possible, that the line for the author of the quote fits itself according to the length of the quote?

Thank you very much!

With best regards,
sonny from Germany
User avatar
jsmorley
Developer
Posts: 22851
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Limitation of Quotes Plugin

Post by jsmorley »

An approach like this should do the trick. You will need to play with the [Variables] CharsPerLine and HeightPerLine depending on the FontFace and FontSize you use. There is no reliable way to deal with font metrics in a formula, so it will need to be somewhat trial and error...

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
Seconds=5
Font=Calibri
CharsPerLine=48
HeightPerLine=56
MeterHeight=56

[MeasureLuaScript]
Measure=Script
ScriptFile=Quotes.lua
QuoteFile=#CURRENTPATH#Quotes.txt
UpdateDivider=#Seconds#

[QuotationStyle]
FontColor=255,255,255,255
FontSize=30
StringAlign=Left
FontFace=#Font#
Antialias=1
ClipString=1
Prefix="
Postfix="

[AuthorStyle]
FontColor=0,0,0,204
FontSize=15
StringAlign=Left
StringStyle=BOLD
StringCase=UPPER
StringEffect=SHADOW
FontEffectColor=255,255,255,128
FontFace=#Font#
Antialias=1
Prefix=—

[QuotationText]
Meter=String
MeterStyle=QuotationStyle
X=0
Y=0
W=800
H=#MeterHeight#
DynamicVariables=1

[QuotationAuthor]
Meter=String
MeterStyle=AuthorStyle
X=50
Y=R
Lua:

Code: Select all

PROPERTIES =
{
	QuoteFile= "";
}

function Initialize()
	
	iCharsPerLine = SKIN:GetVariable('CharsPerLine')
	iHeightPerLine = SKIN:GetVariable('HeightPerLine')
	
	tFileLines = {}
	for line in io.lines(PROPERTIES.QuoteFile) do
		table.insert(tFileLines, line)
	end
	
	iTotal = table.maxn(tFileLines)
	
end -- function Initialize

function Update()

	iNewLine = math.random(iTotal)
	sText, sAuthor = string.match(tFileLines[iNewLine], '(.*) %-(.*)')
	
	iLen = string.len(sText) + 2
	iLines = math.ceil(iLen / iCharsPerLine)
	iHeight = iLines * iHeightPerLine
	
	SKIN:Bang('!SetOption QuotationText Text \"'..sText..'\"')
	SKIN:Bang('!SetOption QuotationAuthor Text \"'..sAuthor..'\"')
	SKIN:Bang('!SetVariable MeterHeight '..iHeight)
	
	return sText..' -'..sAuthor
   
end -- function Update
The + 2 on iLen = string.len(sText) + 2 is to account for the quotes being added as Prefix= and PostFix= on the meter.

Quotes.txt:

Code: Select all

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sodales tellus eu magna luctus ac auctor orci malesuada. Cras sem orci, cursus ac tempor sit amet, pharetra et dui. Praesent et imperdiet dolor. Nulla commodo eros convallis dolor tincidunt at varius mi tristique. Aliquam sit amet accumsan turpis. Proin eleifend eros cursus enim sodales volutpat. Pellentesque egestas semper velit ut feugiat. Praesent ipsum dui, tempor eget ultrices eget, commodo at ligula. Sed nec ligula dolor. Vestibulum eu sem nisi. Maecenas tincidunt rutrum purus, quis dapibus nulla semper nec. Nam sed elementum leo. Phasellus semper, tellus ac porttitor malesuada, leo nisl ultricies nisi, id rhoncus nunc mi sed diam. - Author 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Author 2
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sodales tellus eu magna luctus ac auctor orci malesuada. - Author 3
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sodales tellus eu magna luctus ac auctor orci malesuada. Cras sem orci, cursus ac tempor sit amet, pharetra et dui. - Author 4
Lorem ipsum dolor sit amet - Author 5
sonny_G
Posts: 2
Joined: December 29th, 2011, 11:50 am

Re: Limitation of Quotes Plugin

Post by sonny_G »

Hello jsmorley,

It's perfect! :great:

You were right, I had to adjust the Variables but now it works flawlessly!
Thank you very much!

All the best,
sonny_G
visionxkalubowila
Posts: 9
Joined: November 8th, 2013, 6:43 am

Re: Limitation of Quotes Plugin

Post by visionxkalubowila »

thanx! is there a way to modify the script so that can support unicode texts aswell?
User avatar
jsmorley
Developer
Posts: 22851
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Limitation of Quotes Plugin

Post by jsmorley »

visionxkalubowila wrote:thanx! is there a way to modify the script so that can support unicode texts aswell?
Take a look at this, particularly the section about Unicode in Lua at the bottom.

http://docs.rainmeter.net/tips/unicode-in-rainmeter
valentine1
Posts: 13
Joined: May 29th, 2012, 10:54 pm

Re: Limitation of Quotes Plugin

Post by valentine1 »

Hi, sorry to necro such an old thread, but this is skin + lua is working fantastically for me, save for one thing I was hoping someone may be able to provide help with.

Without any change to the lua above (being the one that jsmorley posted on Fri Dec 30, 2011 12:21 am) I'm trying to get the [QuotationAuthor] not to move around so much.

Depending on how many lines there are, sometimes the Author's name appears right under the quote, but if it's a long quote, then the author's name appears much lower. I think this has to do with the Y=R positioning of the QuotationText Meter, so when lines are added, the MeterHeight increases. As jsmorley above suggested, using each font is a bit of trial and error and I've got all my length quotes to work with the settings below.

I want the Author's name to be in the same position at the bottom of the text each time, so think there may be a way of counting how many lines are used, then factoring that into Y=R of the QuotationText Meter. Just can't figure out how to do it...

Thanking you in advance.

Details below:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Quotations
Description=Cycles through a list of quotations from a text file and displays them one at a time.
Author= jsmorley via https://forum.rainmeter.net/viewtopic.php?t=10715
Version 1.1
; amended by valentine1 20 May 2022

[Variables]
Seconds=3600
Font=Bahnschrift Light
CharsPerLine=48
HeightPerLine=60
MeterHeight=10

;original settings prior to amending
;CharsPerLine=48
;HeightPerLine=56
;MeterHeight=56

Q1=D:\Dropbox\My Documents\Data\quotes1.txt
Q2=D:\Dropbox\My Documents\Data\quotes2.txt
; quotes1: leadership quotes
; quotes2: motivational quotes

[MeasureLuaScript]
Measure=Script
ScriptFile=quotes.lua
QuoteFile=#Q1#
UpdateDivider=#Seconds#

[QuotationStyle]
FontColor=255,255,255,255
FontSize=25
StringAlign=Left
FontFace=#Font#
Antialias=1
ClipString=1
Prefix="
Postfix="

[AuthorStyle]
FontColor=255,255,255,255
FontSize=15
StringAlign=Left
;StringStyle=BOLD
;StringCase=UPPER
;StringEffect=SHADOW
;FontEffectColor=200,200,200,200
FontFace=#Font#
Antialias=1
Prefix=-

[QuotationText]
Meter=String
MeterStyle=QuotationStyle
X=0
Y=0
W=700
H=#MeterHeight#
DynamicVariables=1

[QuotationAuthor]
Meter=String
MeterStyle=AuthorStyle
X=75
Y=R
so the quotes as an example, using Q1 quotes1.txt

Code: Select all

It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; ...who at best knows in the end the triumph of high achievement, and who at worst, if he fails, at least fails while daring greatly. -Theodore Roosevelt 
Don't wait for extraordinary opportunities. Seize common occasions and make them great. Weak men wait for opportunities; strong men make them. -Orison Swett Marden
Begin. To begin is half the work, let half still remain; again begin this, and thou wilt have finished. -Marcus Aurelius
Teddy's name appears much lower under the quote than Aurelius'. How can we fix this?

I note that I'm using the Bahnschrift font, and it's freeware and is available:

Code: Select all

https://www.dafontfree.io/bahnschrift-font/
User avatar
ikarus1969
Posts: 591
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Limitation of Quotes Plugin

Post by ikarus1969 »

I adapted the lua and the ini a little bit. Could you see if it's working as you want it to?

lua:

Code: Select all

function Initialize()

	tFileLines = {}

	for line in io.lines(PROPERTIES.QuoteFile) do
		table.insert(tFileLines, line)
	end
	
	iTotal = table.maxn(tFileLines)

end -- function Initialize

function Update()

	iNewLine = math.random(iTotal)
	sText, sAuthor = string.match(tFileLines[iNewLine], '(.*) %-(.*)')

	SKIN:Bang('!SetOption QuotationText Text \"'..sText..'\"')
	SKIN:Bang('!SetOption QuotationAuthor Text \"'..sAuthor..'\"')

	return sText..' -'..sAuthor
   
end -- function Update
ini:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Quotations
Description=Cycles through a list of quotations from a text file and displays them one at a time.
Author= jsmorley via https://forum.rainmeter.net/viewtopic.php?t=10715
Version 1.1
; amended by valentine1 20 May 2022

[Variables]
Seconds=3600
Font=Bahnschrift Light
Q1=D:\Dropbox\My Documents\Data\quotes1.txt
Q2=D:\Dropbox\My Documents\Data\quotes2.txt
; quotes1: leadership quotes
; quotes2: motivational quotes

[MeasureLuaScript]
Measure=Script
ScriptFile=quotes.lua
QuoteFile=#Q1#
UpdateDivider=#Seconds#

[QuotationText]
Meter=String
Prefix="
Postfix="
X=0
Y=0
ClipStringW=700
ClipString=2
InlineSetting= Face  | #Font#
InlineSetting2=Size  | 25
InlineSetting3=Color | 255,255,255,255
Antialias=1
DynamicVariables=1

[QuotationAuthor]
Meter=String
Prefix=-
X=75
Y=0R
InlineSetting= Face  | #Font#
InlineSetting2=Size  | 15
InlineSetting3=Color | 255,255,255,255
Antialias=1
DynamicVariables=1
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5540
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Limitation of Quotes Plugin

Post by eclectic-tech »

ikarus1969 beat me...

Here is another possible solution.
Set the author Y to the section variable position and height of the quote; Y=[QuotationText:YH].
You have to add DynamiVariables=1 to that meter.

Code: Select all

[QuotationAuthor]
Meter=String
MeterStyle=QuotationText
X=75
Y=[QuotationText:YH]
DynamicVariables=1