It is currently April 26th, 2024, 4:33 am

Help in Escaping Measure Names in !WriteKeyValue

Get help with creating, editing & fixing problems with skins
User avatar
Innocent_Zero
Posts: 9
Joined: May 4th, 2022, 10:08 am

Help in Escaping Measure Names in !WriteKeyValue

Post by Innocent_Zero »

The command is

Code: Select all

ContextAction=[!WriteKeyValue Header[MeasureHeaderCount] Meter Image][!WriteKeyValue Header[MeasureHeaderCount] X 0r][!WriteKeyValue Header[MeasureHeaderCount] Y 5R][!WriteKeyValue Header[MeasureHeaderCount] SolidColor #*color1*#][!WriteKeyValue Header[MeasureHeaderCount] W "#*Width*#"][!WriteKeyValue Header[MeasureHeaderCount] H 10][!WriteKeyValue Header[MeasureHeaderCount] LeftMouseUpAction "[!WriteKeyValue Header1 SolidColor [*MeasureHighlightColor*]][!WriteKeyValue MeasureColor Formula ([*MeasureColor*]+1) \"#@#Measures.inc\"][!UpdateMeasure [*MeasureHighlightColor*]][!Refresh]"][!WriteKeyValue Meter[MeasureHeaderCount] Meter String][!WriteKeyValue Meter[MeasureHeaderCount] MeterStyle StyleText][!WriteKeyValue Meter[MeasureHeaderCount] X 0r][!WriteKeyValue Meter[MeasureHeaderCount] Y 0R][!WriteKeyValue Meter[MeasureHeaderCount] Text "Fillthis"][!WriteKeyValue Meter[MeasureHeaderCount] LeftMouseUpAction "[!CommandMeasure MeasureInput "ExecuteBatch [MeasureHeaderCount]"]"][!WriteKeyValue MeasureInput Command[MeasureHeaderCount] "[!WriteKeyValue Meter[MeasureHeaderCount] Text \"$UserInput$\"]"][!WriteKeyValue MeasureHeaders Formula [[*MeasureHeaders*]+1)]][!Update][!Redraw][!Delay 16][!Refresh]
The expected output was:

Code: Select all

[Header1]
Meter=Image
X=0
Y=5
MeterStyle=HeaderStyle
SolidColor=#color1#
LeftMouseUpAction=[!WriteKeyValue Header1 SolidColor [MeasureHighlightColor]][!WriteKeyValue MeasureColor Formula ([MeasureColor]+1) "#@#Measures.inc"][!UpdateMeasure MeasureHighlightColor][!Refresh]
for the headers

and

Code: Select all

[Meter1]
Meter=String
MeterStyle=StyleText
X=0r
Y=0R
Text=Fillthis
LeftMouseUpAction=!CommandMeasure "MeasureInput" "ExecuteBatch 1"
for the Meter. However there is no LeftMouseUpAction in both and the MeasureInput is also not updating. I thought I had escaped all the variables but I cannot find where I'm going wrong.
N0Syst3m15s@fe. Quite unfortunately, not even this one.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help in Escaping Measure Names in !WriteKeyValue

Post by balala »

Innocent_Zero wrote: May 8th, 2022, 2:13 pm However there is no LeftMouseUpAction in both and the MeasureInput is also not updating. I thought I had escaped all the variables but I cannot find where I'm going wrong.
All this is caused by the missing quotes. Even if in many cases the quotes are not mandatory, in some cases they are. For instance dividing the ContexAction option into bangs (to see them better) these are your bangs:
  1. [!WriteKeyValue Header[MeasureHeaderCount] Meter Image]
  2. [!WriteKeyValue Header[MeasureHeaderCount] X 0r]
  3. [!WriteKeyValue Header[MeasureHeaderCount] Y 5R]
  4. [!WriteKeyValue Header[MeasureHeaderCount] SolidColor #*color1*#]
  5. [!WriteKeyValue Header[MeasureHeaderCount] W "#*Width*#"]
  6. [!WriteKeyValue Header[MeasureHeaderCount] H 10]
  7. [!WriteKeyValue Header[MeasureHeaderCount] LeftMouseUpAction "[!WriteKeyValue Header1 SolidColor [*MeasureHighlightColor*]][!WriteKeyValue MeasureColor Formula ([*MeasureColor*]+1) \"#@#Measures.inc\"][!UpdateMeasure [*MeasureHighlightColor*]][!Refresh]"]
  8. [!WriteKeyValue Meter[MeasureHeaderCount] Meter String]
  9. [!WriteKeyValue Meter[MeasureHeaderCount] MeterStyle StyleText]
  10. [!WriteKeyValue Meter[MeasureHeaderCount] X 0r]
  11. [!WriteKeyValue Meter[MeasureHeaderCount] Y 0R]
  12. [!WriteKeyValue Meter[MeasureHeaderCount] Text "Fillthis"]
  13. [!WriteKeyValue Meter[MeasureHeaderCount] LeftMouseUpAction "[!CommandMeasure MeasureInput "ExecuteBatch [MeasureHeaderCount]"]"]
  14. [!WriteKeyValue MeasureInput Command[MeasureHeaderCount] "[!WriteKeyValue Meter[MeasureHeaderCount] Text \"$UserInput$\"]"]
  15. [!WriteKeyValue MeasureHeaders Formula [[*MeasureHeaders*]+1)]]
  16. [!Update]
  17. [!Redraw]
  18. [!Delay 16]
  19. [!Refresh]
Having these bangs this way it's easier to see what's the problem:
  • In the 7. !WriteKeyValue you're quoting what the LeftMouseUpActioln option should set, however you're using quotations into this expression as well. This confuses Rainmeter. This is why the Magic Quotes has been introduced: to can quote something which itself contains quotes. With this the option will look this way: [!WriteKeyValue Header[MeasureHeaderCount] LeftMouseUpAction """[!WriteKeyValue Header1 SolidColor [*MeasureHighlightColor*]][!WriteKeyValue MeasureColor Formula ([*MeasureColor*]+1) \"#@#Measures.inc\"][!UpdateMeasure [*MeasureHighlightColor*]][!Refresh]"""]. This way Rainmeter knows where the quotation is beginning and where it ends. The "simple" quotes are the let's say "included" quotes, the triple quotes (the magic quotes) delimite what should be set with the bang.
  • Same thing for bang no 13: [!WriteKeyValue Meter[MeasureHeaderCount] LeftMouseUpAction """[!CommandMeasure MeasureInput "ExecuteBatch [MeasureHeaderCount]"]"""]
  • And for bang 14: [!WriteKeyValue MeasureInput Command[MeasureHeaderCount] """[!WriteKeyValue Meter[MeasureHeaderCount] Text \"$UserInput$\"]"""]
Above this I recommend to get used to always use the quotes. For instance instead of the first bang ([!WriteKeyValue Header[MeasureHeaderCount] Meter Image]), I'd use [!WriteKeyValue Header[MeasureHeaderCount] Meter "Image"]. Even if these quotes are not mandatory at all, is a good idea to get used to use them in any condition. Doesn't hurt, however can save you a lot of headaches.

Additional tip: if you refresh the skin (last [!Refresh] bang), it's completely useless to update it before (with the [!Update] bang). And even if you want to do such an update, if you added the [!Update] bang, a [!Redraw] is again useless. When the skin is updated (doesn't matter if it is in the normal update cycle, controlled by the Update option of the [Rainmeter] section, or by an [!Update] bang), a redraw is made as well. Duplicating this operation doesn't worth, because the redraw is quite expensive operation, loading uselessly the CPU. That's why I recommend to remove the [!Update], the [!Redraw] and the [!Delay 16] bangs.
User avatar
Innocent_Zero
Posts: 9
Joined: May 4th, 2022, 10:08 am

Re: Help in Escaping Measure Names in !WriteKeyValue

Post by Innocent_Zero »

Thanks a lot! It works now. Also, there were a lot of stray brackets and slashes in the code due to I testing different ways to make this work as I did not find anything in the documentation. I'll leave the finalized code here for others.

Code: Select all

ContextAction=[!WriteKeyValue Header[MeasureHeaderCount] Meter Image]
[!WriteKeyValue Header[MeasureHeaderCount] X 0r]
[!WriteKeyValue Header[MeasureHeaderCount] Y 5R]
[!WriteKeyValue Header[MeasureHeaderCount] SolidColor "#*color1*#"]
[!WriteKeyValue Header[MeasureHeaderCount] MeterStyle HeaderStyle]
[!WriteKeyValue Header[MeasureHeaderCount] LeftMouseUpAction """[!WriteKeyValue Header[MeasureHeaderCount] SolidColor [*MeasureHighlightColor*]][!WriteKeyValue MeasureColor Formula ([*MeasureColor*]+1) "#*@*#Measures.inc"][!UpdateMeasure [*MeasureHighlightColor*]][!Refresh]"""]
[!WriteKeyValue Meter[MeasureHeaderCount] Meter String]
[!WriteKeyValue Meter[MeasureHeaderCount] MeterStyle StyleText]
[!WriteKeyValue Meter[MeasureHeaderCount] X 0r]
[!WriteKeyValue Meter[MeasureHeaderCount] Y 0R]
[!WriteKeyValue Meter[MeasureHeaderCount] Text "Fill This"]
[!WriteKeyValue Meter[MeasureHeaderCount] LeftMouseUpAction """[!CommandMeasure MeasureInput "ExecuteBatch [MeasureHeaderCount]"]"""]
[!WriteKeyValue MeasureInput Command[MeasureHeaderCount] """[!WriteKeyValue Meter[MeasureHeaderCount] Text "$UserInput$"][!Delay 16][!Refresh]"""]
[!WriteKeyValue MeasureHeaders Formula ([MeasureHeaders]+1)]
[!Delay 16]
[!Refresh]
This proved to be a good lesson in escaping variables, measure names and quotations as well as the use of !WriteKeyValue and !SetOption.

As for the

Code: Select all

!Delay 16 
and

Code: Select all

!Refresh
bangs, I had set them up that way so that the changes would be visible immediately. Otherwise I had to manually refresh it since I believe Rainmeter executes all bangs at once. And the !Update and !Redraw was because I had seen them in a lot of skins and thought that they were some good coding customs lol. Anyways, this taught me a lot about optimizations and good coding practices which are always helpful in the long run.

Thank you @balala and @eclectic-tech for helping me in both the posts I had made regarding this small project of mine.
:bow:
N0Syst3m15s@fe. Quite unfortunately, not even this one.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help in Escaping Measure Names in !WriteKeyValue

Post by balala »

Innocent_Zero wrote: May 9th, 2022, 5:03 am Thanks a lot! It works now. Also, there were a lot of stray brackets and slashes in the code due to I testing different ways to make this work as I did not find anything in the documentation. I'll leave the finalized code here for others.
Actually one thing I talked about is to get used to always add the quotes in every bang you're writing. This way a good practice will form and you'll never forget them again. Here is what am I talking about:

Code: Select all

ContextAction=
[!WriteKeyValue Header[MeasureHeaderCount] Meter "Image"]
[!WriteKeyValue Header[MeasureHeaderCount] X "0r"]
[!WriteKeyValue Header[MeasureHeaderCount] Y "5R"]
[!WriteKeyValue Header[MeasureHeaderCount] SolidColor "#*color1*#"]
[!WriteKeyValue Header[MeasureHeaderCount] MeterStyle "HeaderStyle"]
[!WriteKeyValue Header[MeasureHeaderCount] LeftMouseUpAction """[!WriteKeyValue Header[MeasureHeaderCount] SolidColor [*MeasureHighlightColor*]][!WriteKeyValue MeasureColor Formula ([*MeasureColor*]+1) "#*@*#Measures.inc"][!UpdateMeasure [*MeasureHighlightColor*]][!Refresh]"""]
[!WriteKeyValue Meter[MeasureHeaderCount] Meter "String"]
[!WriteKeyValue Meter[MeasureHeaderCount] MeterStyle "StyleText"]
[!WriteKeyValue Meter[MeasureHeaderCount] X "0r"]
[!WriteKeyValue Meter[MeasureHeaderCount] Y "0R"]
[!WriteKeyValue Meter[MeasureHeaderCount] Text "Fill This"]
[!WriteKeyValue Meter[MeasureHeaderCount] LeftMouseUpAction """[!CommandMeasure MeasureInput "ExecuteBatch [MeasureHeaderCount]"]"""]
[!WriteKeyValue MeasureInput Command[MeasureHeaderCount] """[!WriteKeyValue Meter[MeasureHeaderCount] Text "$UserInput$"][!Delay 16][!Refresh]"""]
[!WriteKeyValue MeasureHeaders Formula "([MeasureHeaders]+1)"]
[!Delay "16"]
[!Refresh]
See the added quotes in many bangs. The newly added such quotes are definitely not mandatory, but seem to be a good practice.
Innocent_Zero wrote: May 9th, 2022, 5:03 am As for the

Code: Select all

!Delay 16 
and

Code: Select all

!Refresh
bangs, I had set them up that way so that the changes would be visible immediately. Otherwise I had to manually refresh it since I believe Rainmeter executes all bangs at once.
I'm extremely surprised. I'd try to keep the [!Refresh], but remove the [!Delay "16"] bang. I can't believe you have to manually refresh the skin when you execute such an option.