It is currently March 29th, 2024, 7:24 am

What am I doing wrong here? -- Webparser w/ file://

Get help with creating, editing & fixing problems with skins
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

What am I doing wrong here? -- Webparser w/ file://

Post by Virginityrocks »

I'm attempting to divide a RGB value into 3 separate variables using webparser. The below should work, but it isn't. The webparser isn't pulling any data from the file. The regexp is working in RainRegExp. Any advice?

Code: Select all

[Variables]
BGColor1=255,100,155

[Parent]
Measure=WebParser
Url=file://#CURRENTPATH##CURRENTFILE#
RegExp=(?siU)BGColor1=(.*),(.*),(.*)[\r\n | \n]

[Child1]
Measure=WebParser
Url=[Parent]
StringIndex=1

[Child2]
Measure=WebParser
Url=[Parent]
StringIndex=2

[Child3]
Measure=WebParser
Url=[Parent]
StringIndex=3
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: What am I doing wrong here? -- Webparser w/ file://

Post by balala »

Virginityrocks wrote:I'm attempting to divide a RGB value into 3 separate variables using webparser. The below should work, but it isn't. The webparser isn't pulling any data from the file. The regexp is working in RainRegExp. Any advice?
There is no need to use WebParser measures for a such task. Some String measures, with properly created substitutions can do this:

Code: Select all

[Variables]
BGColor1=255,100,155

[Child1]
Measure=String
String=#BGColor1#
RegExpSubstitute=1
Substitute="^(\d{1,3}),(\d{1,3}),(\d{1,3})$":"\1"

[Child2]
Measure=String
String=#BGColor1#
RegExpSubstitute=1
Substitute="^(\d{1,3}),(\d{1,3}),(\d{1,3})$":"\2"

[Child3]
Measure=String
String=#BGColor1#
RegExpSubstitute=1
Substitute="^(\d{1,3}),(\d{1,3}),(\d{1,3})$":"\3"
As you can see there are three String measures, each of them returning one component of the color code. In case it would be needed a fourth similar measure can be added, to get the transparency, too.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: What am I doing wrong here? -- Webparser w/ file://

Post by jsmorley »

While I do not recommend using WebParser to read .ini files in Rainmeter, it can be done if you pay attention to the file encoding. Generally speaking, although not certainly, skin .ini files are encoded as UTF-16 Little Endian, which by default WebParser won't read. WebParser assumes that files are UTF-8, which is the standard for encoding on the web.

If you know a .ini file is encoded as UTF-16, you can use:

CodePage=1200

On the parent WebParser measure.

https://docs.rainmeter.net/manual/measures/webparser/#CodePage
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: What am I doing wrong here? -- Webparser w/ file://

Post by Virginityrocks »

You are both wizards. Thank you. :17nodding I didn't consider using Measure=String.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: What am I doing wrong here? -- Webparser w/ file://

Post by balala »

Virginityrocks wrote:You are both wizards. Thank you. :17nodding I didn't consider using Measure=String.
This method has an advantage as well: it can get the needed numbers even if the color code is set dynamically (for example through a !SetVariable bang). Just have to add a DynamicVariables=1 option to all String measures.
This can't be done if you're working with WebParser measures.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: What am I doing wrong here? -- Webparser w/ file://

Post by jsmorley »

I'd be tempted not to have to create three string measures, and have to do that for every color I might want to split that way. I'd lean toward a simple Lua function, that would only be one extra measure, and would be usable in any number of places.

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
BGColor1=255,100,155

[Lua]
Measure=Script
ScriptFile=SplitColor.lua
Disabled=1

[MeterRed]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=#BGColor1#
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Red is: [Lua:SplitColor('#BGColor1#', 'Red')]

[MeterGreen]
Meter=String
Y=5R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=#BGColor1#
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Green is: [Lua:SplitColor('#BGColor1#', 'Green')]

[MeterBlue]
Meter=String
Y=5R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=#BGColor1#
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Blue is: [Lua:SplitColor('#BGColor1#', 'Blue')]
SplitColor.lua:

Code: Select all

function SplitColor(colorArg, componentArg)

	if string.upper(componentArg) == 'RED' then
		return string.match(colorArg, '^([%d]+)')
	elseif string.upper(componentArg) == 'GREEN' then
		return string.match(colorArg, '^[%d]+,([%d]+)')
	elseif string.upper(componentArg) == 'BLUE' then
		return string.match(colorArg, '^[%d]+,[%d]+,([%d]+)')		
	end

end
1.jpg
This is by its nature dynamic if the desired color code variable changes, and is only updated when the meter(s) is updated, not requiring separate updates of any other measure(s). In fact, as you might note, the [Lau] measure is disabled, as there is no need to ever update it. It is simply a static "host" for the SplitColor() function, which is called on demand.

I would note that while pattern matching in Lua is very similar to PCRE in regular expression, it is not identical, and there are some differences in syntax that need to be considered.

Glad to explain the string.match function or Inline Lua if you need help.
You do not have the required permissions to view the files attached to this post.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: What am I doing wrong here? -- Webparser w/ file://

Post by kyriakos876 »

I once wanted to do that too for a reason, if your reason is same as mine, check this:

https://forum.rainmeter.net/viewtopic.php?f=5&t=28115&p=146113&hilit=pixel#p146123