It is currently April 19th, 2024, 9:27 am

Adding or Removing "s" from "item(s)" Based on Item Count

Get help with creating, editing & fixing problems with skins
dylankey
Posts: 10
Joined: February 27th, 2015, 8:07 am

Adding or Removing "s" from "item(s)" Based on Item Count

Post by dylankey »

I have very limited code knowledge, but I have done a lot of playing with Rainmeter skins, simple stuff. I recently decided to take on this little annoying problem with the Recycle Bin skins I have found. Reading the help site and looking at other skins, I decided to try my hand at some logic conditions and substitution

Code: Select all

[Rainmeter]
Author=Jeffrey Morley (modified by Dylan Key)
BackgroundMode=1
Update=500
AppVersion=14001

[Variables]
FontColor=250,250,250
FontColor2=247,247,247
FontSize=12
FontSize2=18
FontSize3=52
FontName=skiplegday


[MeasureBin]
Measure=Plugin
Plugin=RecycleManager.dll
Drives=ALL
RecycleType=COUNT

[ItemCount]
Measure=Calc
Formula= (MeasureBin = 1 ? 2 : 3)
Substitute= "3":"S","2":""

[MeasureSize]
Measure=Plugin
Plugin=RecycleManager.dll
Drives=ALL
RecycleType=SIZE

[MeterCount]
Meter=STRING
MeasureName=MeasureBin
[b]MeasureName2=ItemCount[/b]
FontColor=#FontColor#
FontSize=#FontSize2#
FontFace=#FontName#
X=50
Y=30
Text="%1 ITEM%2"
AntiAlias=1
Hidden=1


[MeterSize]
Meter=STRING
MeasureName=MeasureSize
FontColor=#FontColor2#
FontSize=#FontSize2#
FontFace=#FontName#
X=50
Y=55
Text=%1
Postfix="B"
AutoScale=1
AntiAlias=1
NumOfDecimals=0
Hidden=1


[MeterBinFull]
Meter=IMAGE
ImageName=RecycleFullw.png
X=0
Y=20
W=64
H=64
Hidden=1
LeftMouseDownAction=!execute [!RainmeterPluginBang "MeasureBin OpenBin"]
RightMouseUpAction=!execute [!RainmeterPluginBang "MeasureBin EmptyBin"]

[BinAction]
Measure=Calc
Formula=MeasureBin
IfAboveAction=!execute [!RainmeterShowMeter MeterBinFull][!RainmeterShowMeter MeterCount][!RainmeterShowMeter MeterSize]
IfAboveValue=0
IfEqualAction=!execute [!RainmeterHideMeter MeterBinFull][!RainmeterHideMeter MeterCount][!RainmeterHideMeter MeterSize]
IfEqualValue=0
There is the skin. From the original, I have taken away the empty bin image meter and hidden the text on empty bin. It all worked fine from there (I don't think this is necessarily relevant, but since I don't know what I'm doing, all the facts should be layed out).

Lines I added all seem to work exactly as intended up until the substitute line. If I run the skin without the substitute line, it updates correctly and inputs whatever values I set for the conditional statement at the end of "item". I thought maybe that using 0 and 1 for the conditional output might mess up the formula when I substituted for them, so I tried many different values, none of which seemed to change the outcome at all.

Where am I going wrong, and how do I fix it?
Last edited by dylankey on March 1st, 2015, 10:59 pm, edited 2 times in total.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Adding or Removing "s" from "item(s)" Based on Item Coun

Post by moshi »

Code: Select all

[MeasureWhatIsInTheBin]
Measure=Plugin
Plugin=RecycleManager.dll
Drives=ALL
RecycleType=COUNT
RegExpSubstitute=1
Substitute="^0$":"empty","^1$":"1 item","^(\d+)$":"\1 items"
http://docs.rainmeter.net/manual/measures/general-options/substitute#RegExpSubstitute
dylankey
Posts: 10
Joined: February 27th, 2015, 8:07 am

Re: Adding or Removing "s" from "item(s)" Based on Item Coun

Post by dylankey »

Thank you Moshi for the working bit of code. I understand why that works, but can you explain why my code doesn't work?

What my code does is read whatever the initial value is and never updates (i.e. if I have more than one item in the bin to begin with, from then on, it always reads "Items"; if I have one item to begin with, it always reads "Item")
Last edited by dylankey on March 1st, 2015, 11:01 pm, edited 1 time in total.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Adding or Removing "s" from "item(s)" Based on Item Coun

Post by moshi »

dylankey
Posts: 10
Joined: February 27th, 2015, 8:07 am

Re: Adding or Removing "s" from "item(s)" Based on Item Coun

Post by dylankey »

Thanks! Solved!