It is currently September 18th, 2019, 12:07 am

Changing a BarMeter color when threshold is reached?

Help with creating, editing & fixing problems with skins
dfghrngsdkg
Posts: 19
Joined: February 16th, 2019, 8:40 pm

Changing a BarMeter color when threshold is reached?

dfghrngsdkg » August 26th, 2019, 3:30 pm

Hello Community,

First of all I am a Non-Coder and new to Rainmeter-Scripting. I was working on a "simple" Meter that can read a Disk's capacity to get an understanding of how things work. The 'DiskMeter' itself is reading the Drive in two ways: "[MeasureDrive]" (White-Bar) and "[MeasureDriveInvert]" (Gray-Bar) by design/as intended to get me two status bars + a "%" to show of what is left of Disk-Space. So far the "DIskMeter" works just fine.

Problem Now:
I want to have my gray "[DriveMeterBarInvert]" -that is linked to "[MeasureDriveInvert]"- to change its color only to RED whenever the Disk's is reaching 10% left of free Disk-Space (Threshold). In theory all I have to do is to place the "IfTrue" information in the "[DriveMeterBarInvert]" - "BarColor=" section, but in reality with no success.

While searching for solutions I found two threads in here and tried both of those (Option A) and (Option B) which can be found inside the attached Script. Unfortunately I can't wrap my brain around it, even if both ways seems logical to me, so I will post my .ini file here in hope someone can help me out.


"Thank you" to anyone who can point me to the correct solution.

Code: Select all


[Rainmeter]
Update=1000
MiddleMouseUpAction=!Refresh
BackgroundMode=1
SolidColor=0,0,0,1

[Meta]
Changes Color whenever the Threshold of 10% left is reached.

[Variables]
FONT=Calibri 65
COLOR=255,255,255
COLORDIAG=255,255,255,190
COLORS=255,255,255,170
COLORBACK=255,255,255,95
COLORGRAPH=255,255,255,70
COLORRED=255,110,110,95


[StyleLeft]
FontFace=#FONT#
StringStyle=NORMAL
FontColor=#COLOR#
StringAlign=Left
AntiAlias=1
FontSize=8
SolidColor=0,0,0,1

[StyleCenter]
FontFace=#FONT#
StringStyle=Normal
FontColor=#COLOR#
StringAlign=Center
AntiAlias=1
FontSize=8
SolidColor=0,0,0,1


;----------MEASURES----------

[MeasureDrive]
Measure=FreeDiskSpace
Drive=C:

[MeasureDriveInvert]
Measure=FreeDiskSpace
Drive=C:
InvertMeasure=1

========== Meter Flex-Bar =====

[DriveMeterBar]
MeasureName=MeasureDriveInvert
Meter=BAR
X=37
Y=14
W=100
H=15
BarOrientation=HORIZONTAL
BarColor=#COLORS#

[DriveMeterBarInvert]
MeasureName=MeasureDrive
Meter=BAR
X=37
Y=19
W=100
H=5
BarOrientation=HORIZONTAL
Flip=1
BarColor=#COLORBACK#


;==== MeasureColorBar

; OPTION A:

;[MeasureColorBar]
;Measure=Calc
;Formula=( MeasureDrive / MeasureDriveInvert )
;IfCondition=(MesureDrive>0.1) ;<< If 10% is left Change color to 255,110,110,95 aka. COLORRED
;IfTrueAction=[!SetOption DriveMeterBarInvert BarColor "255,110,110,95"][!UpdateMeter "DriveMeterBarInvert"][!Redraw]
;IfFalseAction=[!SetOption DriveMeterBarInvert BarColor "255,255,255,95"][!UpdateMeter "DriveMeterBarInvert"][!Redraw]


;OPTION B:

;[MeasureColorBar]
;Measure=Calc
;Formula=( MeasureDrive )
;IfCondition=(DriveMeterBar>0.1)
;IfTrueAction=[!SetOption MeterBarInvert BarColor 255,110,110,95][!Redraw]
;IfCondition=(DriveMeterBar<0.1)
;IfTrueAction=[!SetOption MeterBarInvert BarColor 255,255,255,95][!Redraw]


;=====[MeterBarInvert] >> Exchange "MeasureName=DriveMeterBarInvert in [DriveMeterBarInvert]+ Delete Rest 

;[MeterBarInvert]
;MeasureName=MeasureDrive
;Meter=BAR
;X=37
;Y=19
;W=100
;H=5
;BarOrientation=HORIZONTAL
;Flip=1
;BarColor=#MeasureColorBar#

;--------[HDD Elements]---------

[MeterDriveBlock]
Meter=Image
x=138
y=19
w=3
h=5
SolidColor=#COLORS#

[MeterHDDPercent]
Meter=STRING
MeasureName=MeasureDrive
MeterStyle=StyleLeft
X=145
Y=12
Postfix=%
Text="%1"
Percentual=1
AutoScale=1

[MeterHDDLabel]
Meter=STRING
MeterStyle=StyleCenter
X=100
Y=3
Text="[  C  ]"
LeftMouseUpAction=["C:"]

Last edited by dfghrngsdkg on August 26th, 2019, 5:46 pm, edited 1 time in total.
Charlatan
Posts: 7
Joined: January 18th, 2013, 7:14 am

Re: Changing a BarMeter color when threshold is reached?

Charlatan » August 26th, 2019, 4:19 pm

You can accomplish this using a single measure using section variables to refer to the full capacity of the drive. [MeasureDrive:MaxValue] will give you the full size of the drive. You also don't need the second bar meter since you can just give the first one a solid background, but perhaps that's not what you're going for.

Code: Select all

;Formula=( MeasureDrive / MeasureDriveInvert )
;IfCondition=(MesureDrive>0.1)
The issue here (besides the minor typo in the second line) is that the operations performed in the first line do not carry onto the second line. Here is how I would do it, with the IfConditions in the FreeDiskSpace measure:

Code: Select all

; = = = = = MEASURES = = = = =

[MeasureDrive]
Measure=FreeDiskSpace
Drive=C:
; Inverted so that used space is shown.
InvertMeasure=1
; If used space is greater than 90% of total space
IfCondition=(MeasureDrive > 0.9*[MeasureDrive:MaxValue])
IfTrueAction=[!SetOption DriveMeterBar SolidColor "#COLORBACK#"]
IfFalseAction=[!SetOption DriveMeterBar SolidColor "#COLORRED#"]
DynamicVariables=1

; = = = = = METERS = = = = =

[DriveMeterBar]
MeasureName=MeasureDrive
Meter=BAR
X=37
Y=14
W=100
H=15
BarOrientation=HORIZONTAL
BarColor=#COLORS#
SolidColor=#COLORBACK#
dfghrngsdkg
Posts: 19
Joined: February 16th, 2019, 8:40 pm

Re: Changing a BarMeter color when threshold is reached?

dfghrngsdkg » August 26th, 2019, 5:10 pm

Hey Charlatan,

Thank you for the hint concerning the "/variables/section-variables/" manual and the Code. While I'll take a look into the manual later on, I already transferred your code into a blank page + added the needed variables. It shows that it works, however not the way as I envisioned (like you had mentioned correctly) but it is a start. What troubles me is that this code is mixing up colors so that the former White-Bar now turned Pink. I think its because of the "Red" bar that works as an overlay, stretching from start to end. Hmm, If only the InverseBar is changing its color on demand then all is fine.
User avatar
ikarus1969
Posts: 349
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Changing a BarMeter color when threshold is reached?

ikarus1969 » August 27th, 2019, 5:50 am

Hi!

You probably would like to try the following code.

I just:
  • adapted the color-definition from "COLORRED" so that it really is red ;-). Colors have at least 3 parts: a red, a green and a blue part (and an optional value that defines how transparent a color is; the so-called "alpha"-value); each of the 3 can have values from 0 to 255; the higher the "more intense" the red/green/blue part is
  • renamed the disk-measures, so that it's clear what they measure
  • adapted the measure to calculate the percentage of the free space on the disk
  • modified the "IfTrueAction" and "IfFalseAction" to use the defined color-variables for coloring the invert-bar

Code: Select all

[Rainmeter]
Update=1000
MiddleMouseUpAction=!Refresh
BackgroundMode=1
SolidColor=0,0,0,1

[Meta]
Description=Changes Color whenever the Threshold of 10% left is reached.

[Variables]
FONT=Calibri 65
COLOR=255,255,255
COLORDIAG=255,255,255,190
COLORS=255,255,255,170
COLORBACK=255,255,255,95
COLORGRAPH=255,255,255,70
; COLORRED=255,110,110,95  << previous color definition of "RED". In fact it >is< pink
COLORRED=255,000,000,255


[StyleLeft]
FontFace=#FONT#
StringStyle=NORMAL
FontColor=#COLOR#
StringAlign=Left
AntiAlias=1
FontSize=8
SolidColor=0,0,0,1

[StyleCenter]
FontFace=#FONT#
StringStyle=Normal
FontColor=#COLOR#
StringAlign=Center
AntiAlias=1
FontSize=8
SolidColor=0,0,0,1


;----------MEASURES----------

[MeasureDrive_FREE]
Measure=FreeDiskSpace
Drive=C:

[MeasureDrive_USED]
Measure=FreeDiskSpace
Drive=C:
InvertMeasure=1

[MeasureDrive_TOTAL]
Measure=FreeDiskSpace
Drive=C:
Total=1

[MeasureColorBar]
Measure=Calc
Formula=MeasureDrive_FREE / MeasureDrive_TOTAL
IfCondition=MeasureColorBar <= 0.1
IfTrueAction= [!SetOption DriveMeterBarInvert BarColor "#COLORRED#"] [!UpdateMeter "DriveMeterBarInvert"][!Redraw]
IfFalseAction=[!SetOption DriveMeterBarInvert BarColor "#COLORBACK#"][!UpdateMeter "DriveMeterBarInvert"][!Redraw]

========== Meter Flex-Bar =====

[DriveMeterBar]
MeasureName=MeasureDrive_USED
Meter=BAR
X=37
Y=14
W=100
H=15
BarOrientation=HORIZONTAL
BarColor=#COLORS#

[DriveMeterBarInvert]
MeasureName=MeasureDrive_FREE
Meter=BAR
X=37
Y=19
W=100
H=5
BarOrientation=HORIZONTAL
Flip=1
BarColor=#COLORBACK#

;--------[HDD Elements]---------

[MeterDriveBlock]
Meter=Image
x=138
y=19
w=3
h=5
SolidColor=#COLORS#

[MeterHDDPercent]
Meter=STRING
MeasureName=MeasureDrive_FREE
MeterStyle=StyleLeft
X=145
Y=12
Postfix=%
Text="%1"
Percentual=1
AutoScale=1

[MeterHDDLabel]
Meter=STRING
MeterStyle=StyleCenter
X=100
Y=3
Text="[  C  ]"
LeftMouseUpAction=["C:"]
dfghrngsdkg
Posts: 19
Joined: February 16th, 2019, 8:40 pm

Re: Changing a BarMeter color when threshold is reached?

dfghrngsdkg » August 27th, 2019, 9:00 am

Hello ikarus1969,

Thank you! This is what I was looking for and it works like a charm. Looking at the Script as a whole, I now also realize my mistake by not adding: "[MeasureDrive_TOTAL]" to my equation. I thought that, if I measure "Used" minus "Left" I could get the same result with lesser Lines, but like Charlatan has mentioned in his post, a such doesn't work - even if in theory it sounds plausible/logical. Ya, the learning curve is steep. I'd like to say Thank you to both of you for investing your time to help me out on this part.



May I ask you an additional question?

I'd like to create a Meter for USB-Drives too. The Idea is that the Meter sits empty (not visible) on my screen. If I hook up an USB-Drive, the Meter then appears and shows: space used/left+% >> based on what was created here in this Code. When I unplug the USB-Drive, the Meter disappears and sits again not visible on my screen. Basically the same what the OS is showing in the Explorer whenever a Drive is connected or removed. On my research I came across a Meter (Link below) that shows a USB-Drive BUT, after its removal the line (lets call it: Drive E) then stays on the screen permanently with displaying Bars and Text saying 0.00GB is used/left. It mostly disappears after a PC-Restart, but sometimes not. The Link of the novasev-tutorial on USB-Drives is no longer available so I have nothing I can look at except the code that comes with this "broken?" Meter.

Alternatively -if the "Explorer-Option" can't be brought to work because of a Rainmeter limitation- I'll try to write the USB Meter-Code into the existing code so that C:,D: is shown and below that the USB-Drive appears. but like to know what I have to do in both ways to make a Drive to disappear once it is unplugged.

NovaSev: https://www.deviantart.com/novasev/art/SimplyNova-Addon-USB-ONLINE-TUTORIAL-367397255 .*


Kind regards..


* I'll post this question here for now, but probably open a new thread on it in order to not compromise the original post.
Last edited by dfghrngsdkg on August 27th, 2019, 9:29 am, edited 2 times in total.
User avatar
ikarus1969
Posts: 349
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Changing a BarMeter color when threshold is reached?

ikarus1969 » August 27th, 2019, 9:23 am

I took the code from deviantart and changed just the following:
  • wherever there has been G: explicitly i changed it to #D2# to tell the skin to use the variable for the second drive, the USB-drive (on the measures ending with Disk2)
After i had done this, the line disappears when i disconnect the USB-drive.

Disappearing is done by using the HideMeter-Bangs, Showing is done with the SowMeter-bangs

btw: the skin uses some old way to code the bangs: whereever you find a !Rainmeter... it can, and should be, replaced by ! and whatever follows Rainmeter.

Code: Select all

[Rainmeter]
Author=NovaSev
Update=1000
DynamicWindowSize=1

;==========================================    SOME INFORMATION FOR YOUR PLEASURE =================================================

;This is part of a tutorial on adding removable drives to the SimplyNova skin (can be used for any skin though) that will detect
;and display when a drive is plugged in or removed.

;If you want to contact NovaSev for any reason, find me on Facebook @ http://www.facebook.com/NovaSev or contact me through 
;http://novasev.com/contact.html - I hope you like the skin.

;Also, I would love to see you all on my Facebook, Twitter or Google+ pages to help make me feel happy about life in general :) Just search for NovaSev

[Metadata]
Name=SimplyNova HD and Removable Drive
Description=Bar progress meter to show disk usage, including a removable drive (part of a tutorial series by NovaSev)
Instructions=see http://www.novasev.com/tut-rms-USB.html
Version=1.0.0
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

;================================================================
;-----------------------  VARIABLES  ----------------------------
;================================================================
;Fonts for all aspects of skin - included in @Resources folder. The other variables are related to Font Size and Colors.
[Variables]
Font=Agency FB
FS1=10
FS2=14
BarUsed=71BCD2
BarTotal=225,225,225,35
FCN=255,255,255,255
FCT=71BCD2

;Hard Drives: Letter display and measure usage. To erase a drive, you'll have to delete the meters at the bottom as well.
D1=C:
;This is the removable drive - you may have to change this according to your own configuration.
D2=E:

;================================================================
;------------------------  MEASURES  ----------------------------
;================================================================
;Measures are parts of Rainmeter that your meters call in order to display information.

[measureTotalDisk1]
Measure=FreeDiskSpace
Drive=#D1#
Total=1
UpdateDivider=120

[measureUsedDisk1]
Measure=FreeDiskSpace
Drive=#D1#
InvertMeasure=1
UpdateDivider=120

[measureTotalDisk2]
Measure=FreeDiskSpace
Drive=#D2#
IgnoreRemovable=0
Total=1
UpdateDivider=2
IfAboveValue=1
IfAboveAction=[!RainmeterShowMeter meterLabelDisk2][!RainmeterShowMeter meterValueDisk2][!RainmeterShowMeter meterBarDisk2]
IfBelowValue=2
IfBelowAction=[!RainmeterHideMeter meterLabelDisk2][!RainmeterHideMeter meterValueDisk2][!RainmeterHideMeter meterBarDisk2]

[measureLabelDisk2]
Measure=FreeDiskSpace
Drive=#D2#
Label=1
IgnoreRemovable=0
UpdateDivider=2
IfAboveValue=1
IfAboveAction=[!RainmeterShowMeter meterLabelDisk2][!RainmeterShowMeter meterValueDisk2][!RainmeterShowMeter meterBarDisk2]
IfBelowValue=2
IfBelowAction=[!RainmeterHideMeter meterLabelDisk2][!RainmeterHideMeter meterValueDisk2][!RainmeterHideMeter meterBarDisk2]

[measureUsedDisk2]
Measure=FreeDiskSpace
Drive=#D2#
IgnoreRemovable=0
InvertMeasure=1
UpdateDivider=2
Substitute="1.0":"Removed"
IfAboveValue=1
IfAboveAction=[!RainmeterShowMeter meterLabelDisk2][!RainmeterShowMeter meterValueDisk2][!RainmeterShowMeter meterBarDisk2]
IfBelowValue=2
IfBelowAction=[!RainmeterHideMeter meterLabelDisk2][!RainmeterHideMeter meterValueDisk2][!RainmeterHideMeter meterBarDisk2]

;================================================================
;------------------------  STYLES  ------------------------------
;================================================================
;Styles are called by every meter that you see. They are used to control the looks (font, size, color, etc) of all the meters.

[styleTitle]
StringAlign=CENTER
StringCase=UPPER
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontColor=#FCT#
FontFace=#Font# 
FontSize=#FS2#
AntiAlias=1
ClipString=1
Angle=1.57

[styleLeftText]
StringAlign=LEFT
StringCase=NONE
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#FCN#
FontFace=#Font#
FontSize=#FS1#
AntiAlias=1
ClipString=1

[styleRightText]
StringAlign=RIGHT
StringCase=NONE
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#FCN#
FontFace=#Font#
FontSize=#FS1#
AntiAlias=1
ClipString=1

[styleBar]
BarColor=#BarUsed#
BarOrientation=HORIZONTAL
SolidColor=#BarTotal#

;================================================================
;--------------------------  METERS -----------------------------
;================================================================
;This is everything that you'll see on your desktop here (Excluding hidden meters, which you can see after you
;click on a certain part of the skin to UN hide meters.

[meterTitle]
Meter=STRING
MeterStyle=styleTitle
X=20
Y=90
W=320
H=90
Text=Hard Drives

[meterLabelDisk1]
Meter=STRING
MeterStyle=styleLeftText
X=30
Y=42
W=290
H=14
Text="#D1#\"

[meterValueDisk1]
Meter=STRING
MeterStyle=styleRightText
MeasureName=measureUsedDisk1
MeasureName2=measureTotalDisk1
X=290
Y=0r
W=190
H=14
Text="%1B/%2B used"
NumOfDecimals=1
AutoScale=1
LeftMouseUpAction=!Execute ["#D1#\"]

[meterBarDisk1]
Meter=BAR
MeterStyle=styleBar
MeasureName=measureUsedDisk1
X=30
Y=60
W=260
H=3

[meterLabelDisk2]
Meter=STRING
MeterStyle=styleLeftText
X=30
Y=72
W=290
H=14
FontColor=#Font Color#
Text="#D2#\"
LeftMouseUpAction=!Execute ["#D2#\"]

[meterValueDisk2]
Meter=STRING
MeterStyle=styleRightText
MeasureName=measureUsedDisk2
MeasureName2=measureTotalDisk2
X=290
Y=0r
W=290
H=14
Text="%1B/%2B used"
NumOfDecimals=1
AutoScale=1

[meterBarDisk2]
Meter=BAR
MeterStyle=styleBar
MeasureName=measureUsedDisk2
X=30
Y=90
W=260
H=3

;================================================================
;-----------------------  CALCULATION ---------------------------
;================================================================
;This is a calculation that will update your meter a lot more often. This is due to the fact that
;Rainmeter has no way of detecting if a USB drive is plugged in or removed without physically 
;refreshing the meter. So here, we automatically refresh the meter every 5 seconds.

[CalcAutoRefresh]
Measure=CALC
Formula=Counter % 7
IfAboveAction=!RainmeterRefresh
IfAboveValue=5
dfghrngsdkg
Posts: 19
Joined: February 16th, 2019, 8:40 pm

Re: Changing a BarMeter color when threshold is reached?

dfghrngsdkg » August 27th, 2019, 9:38 am

Oha.. and Hello again,

I honestly didn't expect such a fast and detailed reply. I feel now stalked a little *hides IP behind a VPN, behind a VPN* I'll give it a try to make me understand of how it work.
"btw: the skin uses some old way to code the bangs: whereever you find a !Rainmeter... it can, and should be, replaced by ! and whatever follows Rainmeter." Does it mean I have instead to write: !Rainmeter >> to write !SetOption, !etc.?

Interesting to me is that this Script is based on an old Code.. I didn't know that. Now, with your input I have much of trials ahead -probably a week's work now- but I'll let you know the outcome when it is done. :)


Btw, the implementation of the Color-Change now causes to cut off the Meter's % (like it was in my trials before I went on to post my question here) and I didn't found a solution yet to get it back into the readable section. Any advise?
Last edited by dfghrngsdkg on August 27th, 2019, 9:57 am, edited 2 times in total.
User avatar
ikarus1969
Posts: 349
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Changing a BarMeter color when threshold is reached?

ikarus1969 » August 27th, 2019, 9:55 am

dfghrngsdkg wrote:
August 27th, 2019, 9:38 am
I honestly didn't expect such a fast and detailed reply. I feel now stalked a little *hides IP behind a VPN, behind a VPN* I'll give it a try to make me understand of how it work.
I'm writing this in my lunch-break from the computer at my office, so maybe you get the VPN messages because of that. But i'm not sure.
dfghrngsdkg wrote:
August 27th, 2019, 9:38 am
"btw: the skin uses some old way to code the bangs: whereever you find a !Rainmeter... it can, and should be, replaced by ! and whatever follows Rainmeter." Does it mean I have instead to write: !Rainmeter >> to write !SetOption, !etc.?
Exactly!
example: instead of

Code: Select all

[!RainmeterSetOption "Meter" "Text" "hello, world!"]
write

Code: Select all

[!SetOption "Meter" "Text" "hello, world!"]
dfghrngsdkg wrote:
August 27th, 2019, 9:38 am
Btw, the implementation of the Color-Change now causes to cut off the Meter's % (like it was in my trials before I went on to post my question here) and I didn't found a solution yet to get it back into the readable section. Any advise?
add the line DynamicWindowSize=1 to the Rainmeter-section of the skin ;-) (Docu of the DynamicWindowSize-Parameter)
dfghrngsdkg
Posts: 19
Joined: February 16th, 2019, 8:40 pm

Re: Changing a BarMeter color when threshold is reached?

dfghrngsdkg » August 27th, 2019, 10:00 am

Just didn't expect such a fast reply. Thought it needs time to sink in first, but that's probably only for ordinary folks like me who not -in their lunch breaks- write codes for relaxation or amusement. :D

I;ll try your DynamicWindow.

My "professional" solution I came up with was to add the following line:

Code: Select all

[StyleRight]
FontFace=#FONT#
StringStyle=NORMAL
FontColor=#COLOR#
StringAlign=Right
AntiAlias=1
FontSize=8
SolidColor=0,0,0,1[code]

This works too.
User avatar
ikarus1969
Posts: 349
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Changing a BarMeter color when threshold is reached?

ikarus1969 » August 27th, 2019, 10:01 am

As always there are several ways to implement something, it always depends on what you want to achieve.
Congratulations to your solution!