It is currently March 28th, 2024, 12:06 pm

Keep the skin state after restart/refresh

Get help with creating, editing & fixing problems with skins
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Keep the skin state after restart/refresh

Post by pul53dr1v3r »

Hi. Added some more options to the skin and wonder how to keep the skin state of the numer "2" on the pic, so that it doesn't change after system restart-rainmeter refresh. The best way would be to collapse and expand it only by pressing the buttons (circled with blue on the pic). Default skin state is from number 1 on the pic.

Code: Select all

[Rainmeter]
; This section contains general settings that can be used to change how Rainmeter behaves.
Background=#@#Background.png
BackgroundMode=3
BackgroundMargins=0,34,0,14
Update=1000

[Metadata]
; Contains basic information of the skin.
Description=Displays disk usage.

[Variables]
; Variables declared here can be used later on between two # characters (e.g. #MyVariable#).
fontName=Trebuchet MS
textSize=8
colorBar=255,140,0,200
ColorR=255,140,0,200
colorText=255,255,255,205
EmptyBarColor=255,255,255,25
HD1=F:
; UpdateInterval is set to divide update time of Disk Drive Label, Used and Total space
UpdateInterval=10

; ----------------------------------
; MEASURES return some kind of value
; ----------------------------------

[measureTotalHD1]
; This measure returns the total disk space
Measure=FreeDiskSpace
Drive=#HD1#
Total=1
IgnoreRemovable=0
UpdateDivider=#UpdateInterval#

[measureUsedHD1]
; Returns inverted value of free disk space (i.e. used disk space)
Measure=FreeDiskSpace
Drive=#HD1#
InvertMeasure=1
IgnoreRemovable=0
IfCondition=measureUsedHD1=0
IfTrueAction=[!HideMeter "meterBarHD1"][!ShowMeter "meterBarEmptyHD1"]
IfFalseAction=[!ShowMeter "meterBarHD1"][!HideMeter "meterBarEmptyHD1"]
UpdateDivider=#UpdateInterval#

; ----------------------------------
; STYLES are used to "centralize" options
; ----------------------------------

[styleTitle]
StringAlign=Center
;StringCase=UPPER
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontColor=#colorText#
FontFace=#fontName#
FontSize=10
AntiAlias=1
ClipString=1

[styleLeftText]
StringAlign=LEFT
StringCase=NONE
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleRightText]
StringAlign=RIGHT
StringCase=NONE
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

; ----------------------------------
; METERS display images, text, bars, etc.
; ----------------------------------

[meterTitle]
Meter=STRING
MeterStyle=styleTitle
MeasureName=MeasureDiskLabel
X=104
Y=12
W=159
H=40
Text=%1(#HD1#)
LeftMouseUpAction=[#HD1#]
MouseOverAction= [!SetOption "meterTitle" "FontColor" "#ColorR#"][!SetOption "meterTitle" "Text" "OPEN"] [!UpdateMeter "meterTitle"][!Redraw]
MouseLeaveAction= [!SetOption "meterTitle" "FontColor" "#colorText#"][!SetOption "meterTitle" "Text"  "%1(#HD1#)"] [!UpdateMeter "meterTitle"][!Redraw]
DynamicVariables=1

;ToolTipText=Open The Disk
; Even though the text is set to Disks, Rainmeter will display
; it as DISKS, because styleTitle contains StringCase=UPPER.

[meterLabelHD1]
Meter=STRING
MeterStyle=styleLeftText
MeasureName=MeasureDiskLabel
MeasureName2=measureUsedHD1
X=10
Y=40
W=90
H=14
Text="Used: %2B"
Hidden=0
NumOfDecimals=1
Autoscale=1

[MeasureDiskLabel]
Measure=FreeDiskSpace
Drive=#HD1#
Label=1
IgnoreRemovable=0
UpdateDivider=#UpdateInterval#

[meterValueHD1]
Meter=STRING
MeterStyle=styleRightText
MeasureName=measureUsedHD1
MeasureName2=measureTotalHD1
X=200
Y=0r
H=14
Text="Total: %2B"
NumOfDecimals=1
AutoScale=1

;"""""""""""""""""""""""""""""""""""""""""""""""Bar
[meterBarHD1]
Meter=BAR
MeasureName=measureUsedHD1
BarColor=[BarWarn]
SolidColor=255,255,255,25
X=10
Y=52
W=190
H=1
BarOrientation=HORIZONTAL
DynamicVariables=1

[meterBarEmptyHD1]
Meter=Image
SolidColor=#EmptyBarColor#
X=0r
Y=0r
W=190
H=1
Hidden=1

[BarWarn]
Measure=Calc
Formula=DriveUsagePercent> 75 ? -1 : -2
Substitute="-1":"220,20,60,200","-2":"#colorBar#"

[DriveUsagePercent]
Measure=Calc
Formula=( measureUsedHD1 * 100 / ( measureTotalHD1 + 0.000001 ))
MinValue=0
MaxValue=100

;"""""""""""""""""""""""""""""""""""""""""""""""Reads

;For the graph
[MeasureHD1DiskReads]
Measure=Plugin
Plugin=PerfMon
PerfMonObject=LogicalDisk
PerfMonCounter="Disk Reads/sec"
PerfMonInstance="#HD1#"
PerfMonDifference=1
Interface=#Interface#
IfEqualValue=0
IfEqualAction=[!SetOption meterReadCircle1 ImageTint 255,255,255,100][!SetOption meterReadCircle2 ImageTint 255,255,255,100]
IfAboveValue=0
IfAboveAction=[!SetOption meterReadCircle1 ImageTint 204,0,0,255][!SetOption meterReadCircle2 ImageTint 204,0,0,255]

;for the string
[MeasureHD1DiskReadsSec]
Measure=Plugin
Plugin=PerfMon
PerfMonObject=LogicalDisk
PerfMonCounter="Disk Read Bytes/sec"
PerfMonInstance=#HD1#

[MeterHD1ReadSpeedLabel]
Meter=String
MeterStyle=styleLeftText
FontColor=255,255,255,50
X=35
Y=58
Text="Read:"

[MeterHD1ReadSpeed]
Meter=String
MeasureName=MeasureHD1DiskReadsSec
MeterStyle=styleRightText
FontColor=255,255,255,50
X=199
Y=r
Autoscale=1

[MeterReadLine]
Meter=Histogram
MeasureName=MeasureHD1DiskReads
GraphStart=Left
X=37
Y=60
W=160
H=25
Autoscale=1
Antialias=1
Flip=0
PrimaryColor=176,196,222,150
SolidColor=255,255,255,15
Group=Graph

;"""""""""""""""""""""""""""""""""""""""""""""""Writes
;For the graph
[MeasureHD1DiskWrites]
Measure=Plugin
Plugin=PerfMon
PerfMonObject=LogicalDisk
PerfMonCounter="Disk Writes/sec"
PerfMonInstance="#HD1#"
PerfMonDifference=1
Interface=#Interface#
IfEqualValue=0
IfEqualAction=[!SetOption meterWriteCircle1 ImageTint 255,255,255,100][!SetOption meterWriteCircle2 ImageTint 255,255,255,100]
IfAboveValue=0
IfAboveAction=[!SetOption meterWriteCircle1 ImageTint 204,0,0,255][!SetOption meterWriteCircle2 ImageTint 255,0,0,255]

;for the string
[MeasureHD1DiskWritesSec]
Measure=Plugin
Plugin=PerfMon
PerfMonObject=LogicalDisk
PerfMonCounter="Disk Write Bytes/sec"
PerfMonInstance=#HD1#

[MeterHD1WritesSpeedLabel]
Meter=String
X=35
Y=84
MeterStyle=styleLeftText
FontColor=255,255,255,50
Text="Write:"

[MeterHD1WritesSpeed]
Meter=String
MeasureName=MeasureHD1DiskWritesSec
MeterStyle=styleRightText
FontColor=255,255,255,50
X=199
Y=r
Autoscale=1

[MeterWriteLine]
Meter=Histogram
MeasureName=MeasureHD1DiskWrites
GraphStart=Left
LineWidth=1
X=37
Y=86
W=160
H=25
Flip=0
Autoscale=1
Antialias=1
PrimaryColor=176,196,222,150
SolidColor=255,255,255,15
Group=Graph

;"""""""""""""""""""""""""""""""""""""""""""""""Indicators

[meterReadCircle1]
Meter=image
ImageName=#@#Images\Arrow.png
X=16
Y=67
Group=Graph

[meterWriteCircle1]
Meter=image
ImageName=#@#Images\Arrow.png
X=r
Y=21r
ImageFlip=VERTICAL
Group=Graph

;"""""""""""""""""""""""""""""""""""""""""""""""Collapse

[meterHideGraphs]
Meter=Button
ButtonImage=#@#Images\left.png
X=185
Y=15
ImageTint=255,255,255,150
LeftMouseUpAction=[!HideMeterGroup "Graph"][!ShowMeter "meterShowGraphs"][!HideMeter "meterHideGraphs"][!SetOption "MeterHD1ReadSpeedLabel" "X" "10"][!SetOption "MeterHD1WritesSpeedLabel" "X" "10"][!SetOption "MeterHD1WritesSpeedLabel" "Y" "73"][!Update][!Redraw]
TooltipText=Hide graph

[meterShowGraphs]
Meter=Button
ButtonImage=#@#Images\right.png
X=r
Y=r
ImageTint=255,255,255,150
LeftMouseUpAction=[!ShowMeterGroup "Graph"][!HideMeter "meterShowGraphs"][!ShowMeter "meterHideGraphs"][!SetOption "MeterHD1ReadSpeedLabel" "X" "35"][!SetOption "MeterHD1WritesSpeedLabel" "X" "35"][!SetOption "MeterHD1WritesSpeedLabel" "Y" "84"][!Update][!Redraw]
TooltipText=Show graph
Hidden=1
Image
Last edited by pul53dr1v3r on October 21st, 2017, 9:44 am, edited 1 time in total.
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Keep the skin state after restart/refresh

Post by StArL0rd84 »

Without looking too much into your code i think this is what you need:

Code: Select all

[Variables]
 SkinState=1

[mSkinState]
 Measure=Calc
 Formula=#SkinState#
 DynamicVariables=1
 IfEqualValue=0
 IfEqualAction=[!SetVariable SkinState 0][!WriteKeyValue Variables SkinState "0" #Variables#"]
 IfAboveValue=0
 IfAboveAction=[!SetVariable SkinState 1][!WriteKeyValue Variables SkinState "1" #Variables#"]
 UpdateDivider=-1
 
[Switch]
 Meter=Image
 ImageName=#@#Images\Switch.png
 LeftMouseUpAction=[!SetVariable SkinState "(1-#SkinState#)"][!WriteKeyValue Variables SkinState "(1-#SkinState#)" "#Variables#"][!UpdateMeasure mSkinState][!UpdateMeter *][!Redraw]
 AntiAlias=1
With this, the skin should now "remember" the last state from the SkinState variable.
And you can use the measure to hide/show the contents of the skin.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Keep the skin state after restart/refresh

Post by pul53dr1v3r »

StArL0rd84 wrote:
Here is what I've done. It changes the SkinState in the skin every time I click on the buttons (+/-) but the skin still can't remember the state.

Code: Select all

[meterHideGraphs]
Meter=Button
ButtonImage=#@#Images\left.png
X=185
Y=15
ImageTint=255,255,255,150
LeftMouseUpAction=[!HideMeterGroup "Graph"][!ShowMeter "meterShowGraphs"][!HideMeter "meterHideGraphs"][!SetOption "MeterHD1ReadSpeedLabel" "X" "10"][!SetOption "MeterHD1WritesSpeedLabel" "X" "10"][!SetOption "MeterHD1WritesSpeedLabel" "Y" "73"][!SetVariable SkinState "(1-#SkinState#)"][!WriteKeyValue Variables SkinState "(1-#SkinState#)" "FDisk.ini"][!UpdateMeasure mSkinState][!UpdateMeter *][!Update][!Redraw]
TooltipText=Hide graph

[meterShowGraphs]
Meter=Button
ButtonImage=#@#Images\right.png
X=r
Y=r
ImageTint=255,255,255,150
LeftMouseUpAction=[!ShowMeterGroup "Graph"][!HideMeter "meterShowGraphs"][!ShowMeter "meterHideGraphs"][!SetOption "MeterHD1ReadSpeedLabel" "X" "35"][!SetOption "MeterHD1WritesSpeedLabel" "X" "35"][!SetOption "MeterHD1WritesSpeedLabel" "Y" "84"][!SetVariable SkinState "(1+#SkinState#)"][!WriteKeyValue Variables SkinState "(1+#SkinState#)" "FDisk.ini"][!UpdateMeasure mSkinState][!UpdateMeter *][!Update][!Redraw]
TooltipText=Show graph
Hidden=1


[mSkinState]
 Measure=Calc
 Formula=#SkinState#
 DynamicVariables=1
 IfEqualValue=0
 IfEqualAction=[!SetVariable SkinState 0][!WriteKeyValue Variables SkinState "0" FDisk.ini"]
 IfAboveValue=0
 IfAboveAction=[!SetVariable SkinState 1][!WriteKeyValue Variables SkinState "1" FDisk.ini"]
 UpdateDivider=-1
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Keep the skin state after restart/refresh

Post by pul53dr1v3r »

ah yes, but result is the same. Thx anyway.
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Keep the skin state after restart/refresh

Post by StArL0rd84 »

Are you writing to the same skin or an external ini/inc file?
If you are writing to the same skin then you can delete the "FDisk.ini" in [!WriteKeyValue Variables SkinState "(1-#SkinState#)" "FDisk.ini"]
Doube check and see if the variable really changes when you click the switch.
Don't know what text editor you are using, but you might have to restart it to see the change.

And in the future when you use !WriteKeyValue and write to an external file you have to call out the full path to the file.
C:\Users\*USERNAME*\Documents\Rainmeter\Skins\*SKINNAME*\@Resources\Variables\Variables.inc
Or shorten it to: #@#Variables\Variables.inc

But in this case just delete it and it should auto write to the skin itself.
Last edited by StArL0rd84 on October 20th, 2017, 7:52 pm, edited 3 times in total.
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Keep the skin state after restart/refresh

Post by StArL0rd84 »

dvo wrote:[mSkinState]
Measure=Calc
Formula=#SkinState#
DynamicVariables=1
IfEqualValue=0
IfEqualAction=[!SetVariable SkinState 0][!WriteKeyValue Variables SkinState "0" "#Variables#"]
IfAboveValue=0
IfAboveAction=[!SetVariable SkinState 1][!WriteKeyValue Variables SkinState "1" "#Variables#"]
UpdateDivider=-1

i think your missing those... :oops:
whoops, missed those :D
tnx
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Keep the skin state after restart/refresh

Post by balala »

dvo's observation about the missing quotation is very good, it indeed is missing, however I don't think this would fix the initial problem.
So, here is my approach about fixing it:
First add the SkinState variable to the [Variables] section, because later you'll have to use it. If you don't add from start there, at the first refresh, you'll get an error message in the log:

Code: Select all

[Variables]
...
SkinState=0
(obviously you have to keep the existing variables, don't remove any of them).
Then you don't have to show / hide the appropriate meters / meter groups with the [meterHideGraphs] and [meterShowGraphs] buttons. These buttons will be used just to change the value of the SkinState variable and a properly created Calc measure will show / hide the meters / meter groups. So, replace the LeftMouseUpActions of those two Button meters, as it follows:

Code: Select all

[meterHideGraphs]
...
LeftMouseUpAction=[!SetVariable SkinState "0"][!WriteKeyValue Variables SkinState "0"][!UpdateMeasure "MeasureSkinState"]

[meterShowGraphs]
...
LeftMouseUpAction=[!SetVariable SkinState "1"][!WriteKeyValue Variables SkinState "1"][!UpdateMeasure "MeasureSkinState"]
See that every time you click on any of those buttons, the value of the SkinState variable is dynamically updated AND written to the [Variables] section. This last action is needed to can keep the state of the skin (to make it to remember its state on a refresh).
Now add the following measure to your code:

Code: Select all

[MeasureSkinState]
Measure=Calc
Formula=#SkinState#
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!HideMeterGroup "Graph"][!ShowMeter "meterShowGraphs"][!HideMeter "meterHideGraphs"][!SetOption "MeterHD1ReadSpeedLabel" "X" "10"][!SetOption "MeterHD1WritesSpeedLabel" "X" "10"][!SetOption "MeterHD1WritesSpeedLabel" "Y" "73"][!Update]
IfFalseAction=[!ShowMeterGroup "Graph"][!HideMeter "meterShowGraphs"][!ShowMeter "meterHideGraphs"][!SetOption "MeterHD1ReadSpeedLabel" "X" "35"][!SetOption "MeterHD1WritesSpeedLabel" "X" "35"][!SetOption "MeterHD1WritesSpeedLabel" "Y" "84"][!Update][!Redraw]
DynamicVariables=1
Depending on the value of the SkinState variable, this measure sets the needed options, respectively shows / hides the appropriate meters.
I think that's all, to do what you wanted. But I also have a remark about the initial code. Take care to never use the [!Redraw] bang, along with [!Update]. If you do so, you simply do a double redraw of the skin, which is a quite resource consuming operation and doesn't worth. [!Update] is enough. On each complete skin update, a redraw of the skin is also done, so you don't have to also add the [!Redraw] bang.
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Keep the skin state after restart/refresh

Post by StArL0rd84 »

balala wrote: also have a remark about the initial code. Take care to never use the [!Redraw] bang, along with [!Update]. If you do so, you simply do a double redraw of the skin, which is a quite resource consuming operation and doesn't worth. [!Update] is enough. On each complete skin update, a redraw of the skin is also done, so you don't have to also add the [!Redraw] bang.
Learned something, tnx balala
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Keep the skin state after restart/refresh

Post by balala »

dvo wrote:still missing the [!Refresh]

Code: Select all

IfEqualAction=[!SetVariable SkinState 0][!WriteKeyValue Variables SkinState "0" "#Variables#"][!Refresh]  
IfAboveAction=[!SetVariable SkinState 1][!WriteKeyValue Variables SkinState "1" "#Variables#"][!Refresh]
:oops:
If you refresh the skin, using the !SetVariable bang is useless. The refresh is a distructive operation, the dynamically set variable are lost.
But I (and others too) usually recommend to avoid continuous refresh of the skin. You can use the !SetVariable bang to dynamically set the new value of the variable and can add a WriteKeyValue bang, to permanently keep this newly set value in case of a manual refresh. But don't refresh the skin, if it's not absolutely needed. And in this case it is not at all.
Details: https://forum.rainmeter.net/viewtopic.php?p=119966#p119966
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Keep the skin state after restart/refresh

Post by balala »

StArL0rd84 wrote:Learned something, tnx balala
You're welcome.
Just keep in mind that [!Redraw] should be used just along with the [!UpdateMeter...] / [!UpdateMeterGroup...] bangs and eventually with [!ShowMeter...] / [!HideMeter...] / [!ShowMeterGroup...] / [!HideMeterGroup...]. Usually nor the [!UpdateMeasure...], nor the [!UpdateMeasureGroup...] doesn't require the [!Redraw] bang.
Post Reply