It is currently March 29th, 2024, 2:49 pm

Cycling Skins

Tips and Tricks from the Rainmeter Community
User avatar
XANCI
Posts: 104
Joined: September 18th, 2011, 6:37 am
Location: Nanjing, China

Cycling Skins

Post by XANCI »

After reading the following topic
http://rainmeter.net/forum/viewtopic.php?f=15&t=6044
i've come up with a better method

Say if you have a skin display HardDrive usage(include Drive DriveLabel FreeSpace TotalSpace etc.)
Most of this kind skins give a fixed number of Drives to display

Now set these to your .inc file

Code: Select all

DriveNow=1
DriveNum=3
Drive1=C
Drive2=D
Drive3=E
...
Note that you can add any number of drives, just make sure that DriveNum matches and DriveNow is within the DriveNum

Then set your skin like this

Code: Select all

[Variables]
@Include=#ROOTCONFIGPATH##YourIncFile#.inc
#VARFILE#=#ROOTCONFIGPATH##YourIncFile#.inc
Drive=#Drive1#

[MeasureDiskLabel]
Measure=FreeDiskSpace
Drive=#Drive#:
Label=1
IgnoreRemovable=0

[MeasureDiskFree]
Measure=FreeDiskSpace
Drive=#Drive#:
IgnoreRemovable=0

[MeasureDiskTotal]
Measure=FreeDiskSpace
Drive=#Drive#:
Total=1
IgnoreRemovable=0

...

[MeterDisk]
Meter=STRING
SomeStyle...
Text="#Drive#"

...
[SomeMeterToClick]
SomeMouseAction=!Execute [!WriteKeyValue Variables DriveNow (#DriveNow#%#DriveNum#+1) #VARFILE#][!WriteKeyValue Variables Drive 
#Drive"#DriveNow#"# #CURRENTPATH##CURRENTFILE#][!Refresh]
Then your skin will cycle your sets of drives each time you click

The advantage of this sets of codes is that you simply need to change your .inc file to set different number of drives and which drive they are, make your skin more customized-friendly

Above method is more powerful with the new NowPlaying Plugin, just replace "Drive" with "Player", and you can have a Player-Switchable skin :D
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Cycling Skins

Post by MerlinTheRed »

Code: Select all

[!WriteKeyValue Variables Drive #Drive"#DriveNow#"# #CURRENTPATH##CURRENTFILE#]
I assume that is the magic part. But I don't quite get it. Can you use double quotes to insert a variable's value into a variable name? That's important for me right now because if this really works, I could avoid using a Lua script for a certain task. Is this feature documented somewhere?
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Cycling Skins

Post by jsmorley »

[!WriteKeyValue Variables Drive #Drive"#DriveNow#"# "#CURRENTPATH##CURRENTFILE#"]

It does work like that, but as far as I know only with !WriteKeyValue - which is just "writing a string" to the file, and Rainmeter replaces the #varname# sequences with the real values as it is writing. It is only replacing #DriveNow# with a real value, as that is the only valid "variable", and literally writing "Drive=#DriveX# to the skin. Where "X" is what #DriveNow# resolves to.

I do not believe it will work that way in a "dynamic" sense, in that:

Text=#Drive"#DriveNow#"#

On a string measure will display:

#Drive"1"#
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Cycling Skins

Post by MerlinTheRed »

So if I have a series of variables like:

Code: Select all

[Variables]
CurrentString=2

String1="SomeTextOne"
String2="SomeTextTwo"
String3="SomeTextThree"
...
And I want to reference these images based on the value of a variable

Code: Select all

[MeterString]
Meter=String
Text=#String"#CurrentString#"#
that won't work. This won't work either:

Code: Select all

[SomeMeasure]
Measure=Calc
Formula=2

[MeterString]
Meter=String
MeasureName=SomeMeasure
Text=#String%1#
Display: SomeTextTwo

And neither will this (or something similar):

Code: Select all

[SomeMeasure]
Measure=Calc
Formula=2

[SomeImage]
Meter=Image
X=0
Y=0
W=20
H=20
ImageName=SomeImage.png
ToolTipText=The current string is #String"[SomeMeasure]"#
DynamicVariables=1
So there is no way of referencing Variables in such a dynamic way? I just want to make this sure so I don't make something too complex when it can be done simpler.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
XANCI
Posts: 104
Joined: September 18th, 2011, 6:37 am
Location: Nanjing, China

Re: Cycling Skins

Post by XANCI »

jsmorley wrote:It does work like that, but as far as I know only with !WriteKeyValue - which is just "writing a string" to the file, and Rainmeter replaces the #varname# sequences with the real values as it is writing.

I do not believe it will work that way in a "dynamic" sense, in that:

Text=#Drive"#DriveNow#"#

On a string measure will display:

#Drive"1"#
actually RM doesn't accept double ## like
#Drive#DriveNow##
since symbol "#" do not have direction like "(" &")"
in this case it will be dynamic var #Drive# plus string "DriveNow##", cuz RM only accept first ##

so if DriveNow=1, after

Code: Select all

[!WriteKeyValue Variables Drive #Drive"#DriveNow#"# #CURRENTPATH##CURRENTFILE#]
the [Variable] section of the .ini file will be

Code: Select all

[Variables]
@Include=#ROOTCONFIGPATH##YourIncFile#.inc
#VARFILE#=#ROOTCONFIGPATH##YourIncFile#.inc
Drive=#Drive1#
Note that var #Drive# is not dynamic, its value only update when refresh, and after refresh #Drive# is set to actual value of #Drive1# : "C"
And that string meter will display "C", since #Drive# leads to "C" instead of #Drive1#

This DO work cuz I tested it
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Cycling Skins

Post by jsmorley »

Correct.

I used this little test skin to be sure that it both works as you say, which it does, and does not work as Merlin is suggesting, which it does not. None of Merlin's test cases will work.

[Rainmeter]
Update=1000

[Variables]
DriveNow=1
Drive1=C

[Meter1]
Meter=String
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
Text=#Drive"#DriveNow#"#
LeftMouseUpAction=!Execute [!WriteKeyValue Variables Drive #Drive"#DriveNow#"# "#CURRENTPATH##CURRENTFILE#"]

A new variable
Drive=#Drive1#

will be written to the file, however after refresh that Text= option will not return C, but rather #Drive"1"#.

If however I make it:
Text=#Drive#

It does of course display "C" which is want is wanted.

So my one and only point is that what you wrote does indeed work fine, but that one needs to be careful not to draw incorrect assumptions from that and think that the same #var1"#var2#"# or #var1#var2## approach will work in other places. It won't.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Cycling Skins

Post by Kaelri »

I think a more "correct" way would be to use escape characters for the containing variable, as in

Code: Select all

LeftMouseUpAction=!Execute [!WriteKeyValue Variables Drive #*Drive#DriveNow#*#]
But !WriteKeyValue doesn't remove the *'s when there's another variable inside, for some reason. You end up with

Code: Select all

Drive=#*Drive1*#
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Cycling Skins

Post by poiru »

MerlinTheRed wrote:

Code: Select all

[!WriteKeyValue Variables Drive #Drive"#DriveNow#"# #CURRENTPATH##CURRENTFILE#]
I assume that is the magic part. But I don't quite get it. Can you use double quotes to insert a variable's value into a variable name? That's important for me right now because if this really works, I could avoid using a Lua script for a certain task. Is this feature documented somewhere?
There's nothing magical about this.

The following snippet...

Code: Select all

#Drive"#DriveNow#"#
... is parsed as follows:

1) Attempt to expand variable #Drive"# (which fails because no such variable exists)
2) Attempt to expand variable #DriveNow# (which succeeds)
3) The last # is unmatched, no action is taken

Now.. Why do the quotes disappear? When Rainmeter finds a parameter for a bang, all double quotes in the parameter are discarded. This happens after the variables have been expanded, which is why this works.

Had you used...

Code: Select all

#Drive#DriveNow##
.. the situation would be:

1) Attempt to expand variable #Drive#, which succeeds (the string would be C#DriveNow## or similar at this point)
2) Attempt to expand variable #DriveNow#, which succeeds (the string would be C1# or similar at this point)
3) The last # is unmatched, no action is taken
MerlinTheRed wrote:So if I have a series of variables like:

Code: Select all

[Variables]
CurrentString=2

String1="SomeTextOne"
String2="SomeTextTwo"
String3="SomeTextThree"
...
And I want to reference these images based on the value of a variable

Code: Select all

[MeterString]
Meter=String
Text=#String"#CurrentString#"#
that won't work.
Let's think about the following snippet:

Code: Select all

#String"#CurrentString#"#
Rainmeter will attempt to expand as follows:
1) #String"# (fails)
2) #CurrentString# (succeeds)
3) The last # is unmatched, no action is taken

So you're left with #String"2"# (and since matching is a left-to-right process, Rainmeter won't be even attempt to expand this). Why are the quotes there? Because they are stripped only in matched bang parameters (that's why bang was in bold).

MerlinTheRed wrote:This won't work either:

Code: Select all

[SomeMeasure]
Measure=Calc
Formula=2

[MeterString]
Meter=String
MeasureName=SomeMeasure
Text=#String%1#
Display: SomeTextTwo
IIRC, Rainmeter will first attempt to expand the variable #String%1# (fails). Then %1 is replaced with the value of the measure. The first step is done the first update (or every update if DynamicVariables=1). The last step is done on every update.
Kaelri wrote:I think a more "correct" way would be to use escape characters for the containing variable, as in

Code: Select all

LeftMouseUpAction=!Execute [!WriteKeyValue Variables Drive #*Drive#DriveNow#*#]
I don't think that will work with how escape is parsed right now:

1) Attempt to expand variable #*Drive# (since the next # is not preceeded with *), which fails
2) Attempt to expand variable #DriveNow#, which succeeds
...

Perhaps it would be better to change the escape routine to find the next *# (not just #) when #* is met.
Asagrim
Posts: 126
Joined: August 12th, 2011, 12:30 pm

Re: Cycling Skins

Post by Asagrim »

I won't pretend to have understood much, so i'm just gonna go ahead and ask:

Can you, or can't you automatically cycle skins displaying hard drives?

I have 6 partitions, and i would like to display the informations of 2 at a time.