It is currently March 28th, 2024, 5:09 pm

!WriteOptionGroup

Report bugs with the Rainmeter application and suggest features.
Post Reply
User avatar
rm_lion
Posts: 93
Joined: December 27th, 2013, 4:04 pm
Location: Switzerland

!WriteOptionGroup

Post by rm_lion »

I have some cases where it would be useful if I was able to !WriteOptionGroup instead just !SetOptionGroup.
For example I have a Skin with two different states which includes several Meters that are shown or hidden and several Measures that are enabled or disabled.
I know that I can use [!WriteKeyValue SomeMeter Hidden "0"] and [!WriteKeyValue SomeMeasure Disabled "0"].
But it would extremely shorten up things if I could use [!WriteOptionGroup SomeMeterGroup Hidden "0"] and [!WriteOptionGroup SomeMeasureGroup Disabled "0"].
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana
Contact:

Re: !WriteOptionGroup

Post by VasTex »

It might be easier if you just create a Style for your meters with the Hidden=0 option and then use the !WriteKeyValue bang to change the value of Hidden on the Style and refresh the skin. If I'm not mistaken this should work just fine for meters.

However, with measures it would be a little more involved since there's no such thing a 'MeasureStyle' in Rainmeter. Because of this I think your best option would be to use a variable in place of the value of Disabled for your measures in any particular group and then use the !WriteKeyValue bang to change that variable and refresh the skin that way.

For example:

Code: Select all

;===  Variables  ===;

[Variables]
mDisabled_Group1=0

;===  Measures  ===;

[Measure1]
Measure=Calc
.
.
.
Disabled=#mDisabled_Group1#
Group=mGroup1

[Measure2]
Measure=String
.
.
.
Disabled=#mDisabled_Group1#
Group=mGroup1

;===  Styles  ===;

[sMeterStyle]
.
.
.
Hidden=0

;===  Meters  ===;

[MeterShowMeasure1]
Meter=String
MeterStyle=sMeterStyle
MeasureName=Measure1
.
.
.

[MeterShowMeasure2]
Meter=String
MeterStyle=sMeterStyle
MeasureName=Measure2
.
.
.

[MeterHideShow]
Meter=String
.
.
.
LeftMouseUpAction=[!WriteKeyValue "Variables" "mDisabled_Group1" "1" "#CURRENTPATH##CURRENTFILE#"][!WriteKeyValue "sMeterStyle" "Hidden" "1" "#CURRENTPATH##CURRENTFILE#"][!Refresh]
RightMouseUpAction=[!WriteKeyValue "Variables" "mDisabled_Group1" "0" "#CURRENTPATH##CURRENTFILE#"][!WriteKeyValue "sMeterStyle" "Hidden" "0" "#CURRENTPATH##CURRENTFILE#"][!Refresh]
*Note the bang used in the last meter. I haven't tested this code at all, but I use something very similar in my suite. Also, in case you're unsure the #CURRENTPATH##CURRENTFILE# section of the bangs uses two built-in variables to define the location of the current skin file regardless of where it is (ie: you could copy and paste this skin into a new folder and it would still work). The #CurrentPath# Variable simply defines the folder path containing the current skin. The #CurrentFile# variable simply represents the file name of the current skin. That way, when placed side by side, you get the full path to your skin which would look something like:

C:\Users\YourName\Documents\Rainmeter\Skins\YourSuiteName\YourSkinName\YourFile.ini

This should, at the very least, get you pointed in the right direction.
User avatar
killall-q
Posts: 305
Joined: August 14th, 2009, 8:04 am

Re: !WriteOptionGroup

Post by killall-q »

I think the design of Rainmeter tries to discourage directly writing to skin .ini's as part of the normal operation of the skin. Firstly, this requires rereading the skin from the file to apply the changes, and secondly, writing requires parsing, and as the skin grows in size, writing (one parse to find the option) and refreshing (another parse to reread the file) will introduce an increasingly perceivable lag. It's better to use !ShowMeter, !HideMeter, and variables plus a small separate settings file.

Learn to think of your skin as having an initial state (the way it is the first time it's loaded), a persistent state (initial state modified by settings in the settings file), and a running state (the in-memory state where non-persistent changes have occured).
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana
Contact:

Re: !WriteOptionGroup

Post by VasTex »

@KillAll-Q

Yes,

Normally I would suggest writing settings to an .inc file instead of directly to a skin. Writing to a skin directly requires a refresh of the skin which, you're right, would cause some noticeable lag, however, if it's only done once in a while by the user it wouldn't be an issue. However, writing to the skin automatically or especially in a loop would cause things to slow down to a point where they're most likely not usable.

That being said, even if you were to write to an .inc file rather than the skin itself you would still need to refresh the skin to grab those new values anyway. Either way you're going to induce some amount of lag depending on how often you need to write and thus refresh the skin. I see no reason why this wouldn't be a perfectly viable option in the event that it's only needed per the users request and not via a loop or some frequent, automatic update.

Using a simple !Hide/!ShowMeter bang would work to an extent, but it wouldn't fix the issue he's trying to correct. You can hide a meter and you can hide a group of meters, but without writing to a file of some kind this state of Hidden or Shown will be lost when the skin refreshes or the system restarts. You could do a combination of the two where you set the meters to hidden using the !HideMeter bang and also write to a settings file to change the value respectively, thus allowing the value to carry through a refresh.

However, what he's asking can't really be solved entirely with those bangs. If he wants to enable or disable a large group of Measures you can't do that using a single bang. You would need to use multiple bangs per measure or create some sort of dynamic bang to go through and disable each one in turn, but like the last issue, this won't hold through a refresh. You need to write the change to a file somewhere (even if it's the calling skin) in order for that change to stick through any sort of refresh.

You are correct in the sense that this should be done sparingly, but I don't think that there is a reason to 'never' write to the calling skin if you're aware of what you're asking the skin to do. If the user is aware that they're changing a setting or putting a skin into a 'sleep' mode of sorts (which seems like what Rm-Lion is asking for) then a needed refresh of the skin would be permissible and it would only occur once. There is no reason that the method wouldn't work and although it's 'discouraged' to write to the calling skin due to the need of a refresh it is certain possible.

Long story short, the !WriteKeyValue bang is still a good way to go, but again, you're correct in the sense that the writing should be done to an .inc file while temporary changes should be made to the skin itself which mirror the written information. This would allow the skin to display the changes without needing to be refreshed, but would still hold on to that information should a refresh occur in which case the temporary changes to the skin would be lost.
User avatar
rm_lion
Posts: 93
Joined: December 27th, 2013, 4:04 pm
Location: Switzerland

Re: !WriteOptionGroup

Post by rm_lion »

Thanks a lot for your help VasTex you helped me a lot to solve my problem!
I simply didn't know that I can use Hidden=0/1 in a Style.
But I should have had the idea with the Variable for the Measures by myself.

I have a clock Skin and when I click on 6 o'clock the clock Skin gets closed and the Spotify Skin opens. Now the Spotify Skin has three Variants and I can choose via the Context Menu - Custom Skin Actions which one I want to use.
All of them use the AudioLevelPlugin. Variant 1 Shows only RMS and Peak Measures. Variant 2 Shows all of Variant 1 and FFT Sum Measures. Variant 3 Shows all of Variant 1 and FFT Measures for the Left and the Right Channel.
I doen't change the variant very often. So I don't have to think about performance. But when I Close the Spotify Skin via a Button in it to open my Clock Skin I want that the Spotify Skin uses the same Variant that I used when I did close it the last time. It is very important to me that I don't have to refresh the Skin to make this work because Rainmeter crashes with the actual Version of the Spotify plugin whenever I refresh the Skin.


Here my solution with the help of VasTex
In the "ContextAction="-part of the Skin under the Rainmeter Section I use a mix of [!DisableMeasureGroup...], [!EnableMeasureGroup...] and [!SetOption...] and [!ShowMeterGroup...], [!HideMeterGroup...] and for all of them I also use a [!WriteKeyValue...] then I finish the Action with [!UpdateMeter *][!Redraw]. Like that I don't have to refresh the Skin and everything works smooth and perfect and when I Close the Skin and re-open it, it uses the same Variant that I used before.

Under the [RainMeter] Section:

Code: Select all

[RainMeter]
.
.
.
DynamicWindowSize=1
Group=Lions
ContextTitle=Enable Spectrum Sum
ContextAction=[!DisableMeasureGroup "Spectrum_LR_Measures"][!EnableMeasureGroup "Spectrum_Sum_Measures"][!WriteKeyValue Style_LR_Hidden Hidden "1"][!WriteKeyValue Style_Sum_Hidden Hidden "0"][!WriteKeyValue Variables Spectrum_LR_Disabled_0_1 "1"][!WriteKeyValue Variables Spectrum_Sum_Disabled_0_1 "0"][!SetOption Background H "330"][!WriteKeyValue Background H "330"][!SetOption MeterBackgroundImage ImageName "#@#Background2.png"][!WriteKeyValue MeterBackgroundImage ImageName "#@#Background2.png"][!HideMeterGroup "Spectrum_LR_Meters"][!ShowMeterGroup "Spectrum_Sum_Meters"][!UpdateMeter *][!Redraw]
ContextTitle2=Enable Spectrum L+R
ContextAction2=[!DisableMeasureGroup "Spectrum_Sum_Measures"][!EnableMeasureGroup "Spectrum_LR_Measures"][!WriteKeyValue Style_Sum_Hidden Hidden "1"][!WriteKeyValue Style_LR_Hidden Hidden "0"][!WriteKeyValue Variables Spectrum_Sum_Disabled_0_1 "1"][!WriteKeyValue Variables Spectrum_LR_Disabled_0_1 "0"][!SetOption Background H "480"][!WriteKeyValue Background H "480"][!SetOption MeterBackgroundImage ImageName "#@#Background3.png"][!WriteKeyValue MeterBackgroundImage ImageName "#@#Background3.png"][!HideMeterGroup "Spectrum_Sum_Meters"][!ShowMeterGroup "Spectrum_LR_Meters"][!UpdateMeter *][!Redraw]
ContextTitle3=Disable Spectrum
ContextAction3=[!DisableMeasureGroup "Spectrum_Sum_Measures"][!DisableMeasureGroup "Spectrum_LR_Measures"][!WriteKeyValue Style_Sum_Hidden Hidden "1"][!WriteKeyValue Style_LR_Hidden Hidden "1"][!WriteKeyValue Variables Spectrum_Sum_Disabled_0_1 "1"][!WriteKeyValue Variables Spectrum_LR_Disabled_0_1 "1"][!SetOption Background H "180"][!WriteKeyValue Background H "180"][!SetOption MeterBackgroundImage ImageName "#@#Background.png"][!WriteKeyValue MeterBackgroundImage ImageName "#@#Background.png"][!HideMeterGroup "Spectrum_Sum_Meters"][!HideMeterGroup "Spectrum_LR_Meters"][!UpdateMeter *][!Redraw]
.
.
.
...Under [Variables]

Code: Select all

[Variables]
.
.
.
Spectrum_LR_Disabled_0_1=0
Spectrum_Sum_Disabled_0_1=1
.
.
.
...Under [Styles]

Code: Select all

[Style_LR_Hidden]
Hidden=0

[Style_Sum_Hidden]
Hidden=1
.
.
.
...
Under [Measures]

Code: Select all

.
.
.
;-------------------------Sum------------------------
[MeasureAudioOut_FFT_00]
Group=Spectrum_Sum_Measures
Measure=Plugin
Plugin=AudioLevel
Parent=MeasureAudioRaw_Out
Channel=Sum
Type=Band
BandIdx=0
Disabled=#Spectrum_Sum_Disabled_0_1#
DynamicVariables=1
.
.
.
...
;-------------------------Left Channel------------------------
[MeasureAudioOut_Left_FFT_00]
Group=Spectrum_LR_Measures
Measure=Plugin
Plugin=AudioLevel
Parent=MeasureAudioRaw_Out
Channel=L
Type=Band
BandIdx=0
Disabled=#Spectrum_LR_Disabled_0_1#
DynamicVariables=1
.
.
.
...
;-------------------------Right Channel------------------------
[MeasureAudioOut_Right_FFT_00]
Group=Spectrum_LR_Measures
Measure=Plugin
Plugin=AudioLevel
Parent=MeasureAudioRaw_Out
Channel=R
Type=Band
BandIdx=0
Disabled=#Spectrum_LR_Disabled_0_1#
DynamicVariables=1
.
.
.
...
under [Meters]

Code: Select all

[Background]
X=0
Y=0
Meter=Image
W=460
H=480
SolidColor=0,0,0,10
SolidColor2=100,0,100,50

[MeterBackgroundImage]
Meter=IMAGE
ImageName=C:\Users\Claudio\Documents\Rainmeter\Skins\Spotify\@Resources\Background3.png
ImageAlpha=150
X=0
Y=0
.
.
.
...
;----------Sum-------------------------
[MeterOutFFT_00]
Group=Spectrum_Sum_Meters
Meter=BAR
MeterStyle=Style_Sum_Hidden
BarOrientation=Vertical
MeasureName=MeasureAudioOut_FFT_00
BarImage=#@#SpecBar.png
X=4
Y=191
.
.
.
...
;-------------------------Left Channel------------------------
[MeterOutFFT_Left_00]
Group=Spectrum_LR_Meters
Meter=BAR
MeterStyle=Style_LR_Hidden
BarOrientation=Vertical
MeasureName=MeasureAudioOut_Left_FFT_00
BarImage=#@#SpecBar.png
X=4
Y=191
.
.
.
...
;-------------------------Right Channel------------------------
[MeterOutFFT_Right_00]
Group=Spectrum_LR_Meters
Meter=BAR
MeterStyle=Style_LR_Hidden
BarOrientation=Vertical
Flip=1
MeasureName=MeasureAudioOut_Right_FFT_00
BarImage=#@#SpecBarR.png
X=4
Y=333
.
.
.
...
I'm so happy! :D
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana
Contact:

Re: !WriteOptionGroup

Post by VasTex »

Looks like you've gotten it to work though!

I personally use a combination of !SetVariable / !SetOption in addition to !WriteKeyValue in many different areas as i find it to be the best option when you need to write a value to hold through a full refresh, but don't want to refresh the skin right away. Using these options it's very easy to display the changes using temporary variables while changing the stored, written versions to hold and show information without much effort.

It's always a little tricky to do exactly what you want, but when you get the hang out if it ends up being very effective.

Nice work by the way.
User avatar
rm_lion
Posts: 93
Joined: December 27th, 2013, 4:04 pm
Location: Switzerland

Re: !WriteOptionGroup

Post by rm_lion »

Thanks for your compliment and thanks again for your help. I was Close but you gave me the final hint otherwise I would have ended up with muuuuuuch more code.
User avatar
VasTex
Posts: 407
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana
Contact:

Re: !WriteOptionGroup

Post by VasTex »

Glad I could help.
Post Reply