It is currently April 25th, 2024, 8:01 am

Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Get help with creating, editing & fixing problems with skins
User avatar
imaquietkid
Posts: 5
Joined: February 13th, 2020, 3:54 pm

Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by imaquietkid »

edit: I needed to use magic quotes (triple quotes), thank you everyone for the help !

Hello everyone,

I am currently working on a skin that pulls headlines from some news websites. I have made 4, they're all identical but I want them to be independently customizable. So in my UserSettings.inc file I have 8 Variables, News1Link, News1RegExp, News2Link, News2RegExp, etc. for the 4 different skins. This is working as intended.

I also have a settings skin from which people will be able to choose which website the headlines are pulled from. This is where things don't work. I can change the link no problem, but I can't seem to change the RegExp. Here is what my variables look like

Code: Select all

[Variables]
@include=#@#UserSettings.inc
CurrntSkinIndex=1
LinkJT=https://www.japantimes.co.jp/feed/topstories/
RegExpJT=(?siU)<title>(.*)</title>.*<link>(.*)</link>.*<title>(.*)</title>.*<link>(.*)</link>.*<description>.*\[CDATA\[(.*)\].*</description>.*<title>(.*)</title>.*<link>(.*)</link>.*<description>.*\[CDATA\[(.*)\].*</description>.*<title>(.*)</title>.*<link>(.*)</link>.*<description>.*\[CDATA\[(.*)\].*</description>
the CurrntSkinIndex variable determines which of the 4 skins the user is customizing.
And this is the action that I've got in my meter :

Code: Select all

LeftMouseUpAction=[!WriteKeyValue Variables News#CurrntSkinIndex#Link "#LinkJT#" "#@#UserSettings.inc"][!WriteKeyValue Variables News#CurrntSkinIndex#RegExp "#RegExpJT#" "#@#UserSettings.inc"][!Refresh]
The first bang changes the link and works just fine.
The second one doesn't work. It doesn't trigger an error, at least nothing that appears in the log. It just stops there, and doesn't refresh. Any idea why that is ?

thanks in advance!
Last edited by imaquietkid on June 12th, 2020, 7:11 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by jsmorley »

I'm not sure. It works for me.

Make sure that there is actually a file UserSettings.inc located in the @Resources folder of the root config for the skin, and that it currently has a [Variables] section in it.

If I create this test skin:

Code: Select all

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

[Variables]
CurrntSkinIndex=1
News1RegExp=Hello
RegExpJT=World

[MeterOne]
Meter=String
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Click Me
LeftMouseUpAction=[!WriteKeyValue Variables News#CurrntSkinIndex#RegExp "#RegExpJT#" "#@#Test.inc"]

I end up with this in #@#Test.inc when I click it:

Code: Select all

[Variables]

News1RegExp=World
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by balala »

imaquietkid wrote: June 12th, 2020, 11:55 am Hello everyone,

I am currently working on a skin that pulls headlines from some news websites. I have made 4, they're all identical but I want them to be independently customizable. So in my UserSettings.inc file I have 8 Variables, News1Link, News1RegExp, News2Link, News2RegExp, etc. for the 4 different skins. This is working as intended.

I also have a settings skin from which people will be able to choose which website the headlines are pulled from. This is where things don't work. I can change the link no problem, but I can't seem to change the RegExp. Here is what my variables look like

Code: Select all

[Variables]
@include=#@#UserSettings.inc
CurrntSkinIndex=1
LinkJT=https://www.japantimes.co.jp/feed/topstories/
RegExpJT=(?siU)<title>(.*)</title>.*<link>(.*)</link>.*<title>(.*)</title>.*<link>(.*)</link>.*<description>.*\[CDATA\[(.*)\].*</description>.*<title>(.*)</title>.*<link>(.*)</link>.*<description>.*\[CDATA\[(.*)\].*</description>.*<title>(.*)</title>.*<link>(.*)</link>.*<description>.*\[CDATA\[(.*)\].*</description>
the CurrntSkinIndex variable determines which of the 4 skins the user is customizing.
And this is the action that I've got in my meter :

Code: Select all

LeftMouseUpAction=[!WriteKeyValue Variables News#CurrntSkinIndex#Link "#LinkJT#" "#@#UserSettings.inc"][!WriteKeyValue Variables News#CurrntSkinIndex#RegExp "#RegExpJT#" "#@#UserSettings.inc"][!Refresh]
The first bang changes the link and works just fine.
The second one doesn't work. It doesn't trigger an error, at least nothing that appears in the log. It just stops there, and doesn't refresh. Any idea why that is ?

thanks in advance!
Please pack the whole config you have and upload the package here, in order to can examine it.
User avatar
imaquietkid
Posts: 5
Joined: February 13th, 2020, 3:54 pm

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by imaquietkid »

jsmorley wrote: June 12th, 2020, 12:11 pm I'm not sure. It works for me.

Make sure that there is actually a file UserSettings.inc located in the @Resources folder of the root config for the skin, and that it currently has a [Variables] section in it.

If I create this test skin:

Code: Select all

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

[Variables]
CurrntSkinIndex=1
News1RegExp=Hello
RegExpJT=World

[MeterOne]
Meter=String
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Click Me
LeftMouseUpAction=[!WriteKeyValue Variables News#CurrntSkinIndex#RegExp "#RegExpJT#" "#@#Test.inc"]

I end up with this in #@#Test.inc when I click it:

Code: Select all

[Variables]

News1RegExp=World
I have tried this as well (I made it write "hello world") and it worked, it only stops working when I set the variable to be the Regular Expression.
balala wrote: June 12th, 2020, 12:22 pm Please pack the whole config you have and upload the package here, in order to can examine it.
I've attached the whole skin but it's a pretty big project so just in case : the settings skin is /settings/news.ini. The bang is in [source6].
Sorry if the code is a mess, I've been working on this for a while and I never took the time to clean it up, I'll do it when I have time.

Thanks guys
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by balala »

imaquietkid wrote: June 12th, 2020, 11:55 am The first bang changes the link and works just fine.
The second one doesn't work. It doesn't trigger an error, at least nothing that appears in the log. It just stops there, and doesn't refresh. Any idea why that is ?
Ok, finally I figured it out what's going on, but have no explanation.
The RegExpJT variable is not written because it has brackets ([). The expressions containing this symbol, along with its pair (]) are not written, all other symbols (at least as far as I can tell) are. In fact neither a simple WriteKeyValue=[!WriteKeyValue Variables MyVar "["] doesn't work, nothing is written.
I have to say this seems to be a bug. I'm asking the developers to check. Thanks...
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by jsmorley »

balala wrote: June 12th, 2020, 5:56 pm Ok, finally I figured it out what's going on, but have no explanation.
The RegExpJT variable is not written because it has brackets ([). The expressions containing this symbol, along with its pair (]) are not written, all other symbols (at least as far as I can tell) are. In fact neither a simple WriteKeyValue=[!WriteKeyValue Variables MyVar "["] doesn't work, nothing is written.
I have to say this seems to be a bug. I'm asking the developers to check. Thanks...
You need to use Magic Quotes on that.

Code: Select all

LeftMouseUpAction=[!WriteKeyValue Variables TestVar """[""" "#@#Test.inc"]
https://docs.rainmeter.net/manual/skins/option-types/#MagicQuotes

The [ character is evaluated as the start of a [SectionVariable] otherwise, and it gets confused.
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by balala »

jsmorley wrote: June 12th, 2020, 6:06 pm You need to use Magic Quotes on that.
Yep, right! Didn't realize this, but yeah, now it makes sense.
Thanks.
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by balala »

imaquietkid wrote: June 12th, 2020, 11:55 am The first bang changes the link and works just fine.
The second one doesn't work. It doesn't trigger an error, at least nothing that appears in the log. It just stops there, and doesn't refresh. Any idea why that is ?
So finally based on jsmorley's above reply, here is the solution: instead of the [!WriteKeyValue Variables News#CurrntSkinIndex#RegExp "#RegExpJT#" "#@#UserSettings.inc"] bang, use [!WriteKeyValue Variables News#CurrntSkinIndex#RegExp """#RegExpJT#""" "#@#UserSettings.inc"].
Take care, I'm not the author of this solution, it definitely belongs to jsmorley.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by jsmorley »

Yes, everything between """Magic Quotes""" is treated as a literal, and no evaluation of section variables, variables, character variables, formulas, or any of that is attempted.

RegExp in particular can be run through with all kinds of weird characters. It's not a bad idea to force that as entirely literal when passing it as a string to a bang like !WriteKeyValue that will evaluate and resolve variables in it.
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using [!WriteKeyValue] to change a RegExp stored in a variable doesn't seem to work

Post by balala »

jsmorley wrote: June 12th, 2020, 6:22 pm Yes, everything between """Magic Quotes""" is treated as a literal, and no evaluation of section variables, variables, character variables, formulas, or any of that is attempted.

RegExp in particular can be run through with all kinds of weird characters. It's not a bad idea to force that as entirely literal when passing it as a string.