It is currently April 27th, 2024, 1:41 pm

Autohide Empty CD/DVD Drive

Get help with creating, editing & fixing problems with skins
PantherX
Posts: 13
Joined: December 3rd, 2012, 5:57 am

Autohide Empty CD/DVD Drive

Post by PantherX »

I did come across Kaelri's wonderful post and it works fine for USBs. However, for the CD/DVD Drive, I tweaked it after reading the documentation and it doesn't work. Any ideas as to how I can achieve it?

Code: Select all

[DriveType]
Measure = FreeDiskSpace
Drive = "#Letter#"
Type = 1
IfEqualValue = 6 
IfEqualAction = [ !ShowMeter Background ]
IfAboveValue = 7
IfAboveAction = [ !HideMeter Background ] 
IfBelowValue = 5
IfBelowAction = [ !HideMeter Background ]
Thanks in Advance :)
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Autohide Empty CD/DVD Drive

Post by eclectic-tech »

PantherX wrote:I did come across Kaelri's wonderful post and it works fine for USBs. However, for the CD/DVD Drive, I tweaked it after reading the documentation and it doesn't work. Any ideas as to how I can achieve it?

Code: Select all

[DriveType]
Measure = FreeDiskSpace
Drive = "#Letter#"
Type = 1
IfEqualValue = 6 
IfEqualAction = [ !ShowMeter Background ]
IfAboveValue = 7
IfAboveAction = [ !HideMeter Background ] 
IfBelowValue = 5
IfBelowAction = [ !HideMeter Background ]
Thanks in Advance :)
Worked for me if I enter my CD drive letter... (I removed all those extra "spaces" in your code)... shouldn't matter.

Did you see what the measure is returning in the !About 'Skin' tab for this skin?

I have not used this that often, but my other thought is if you are using a removable CD (USB interface) you may need to add IgnoreRemovable=0 to the measure.

EDIT: This will not show if the drive is "empty", it shows if the drive "exists" or not...
PantherX
Posts: 13
Joined: December 3rd, 2012, 5:57 am

Re: Autohide Empty CD/DVD Drive

Post by PantherX »

eclectic-tech wrote:...Did you see what the measure is returning in the !About 'Skin' tab for this skin?

I have not used this that often, but my other thought is if you are using a removable CD (USB interface) you may need to add IgnoreRemovable=0 to the measure.

EDIT: This will not show if the drive is "empty", it shows if the drive "exists" or not...
The DriveType is CDROM. Your edit explains what my code actually does.

However, I didn't explain myself clearly (sorry for that), what I want to do (if possible) is to hide the skin if the Drive is empty. Since we can work with Type and Label, I though that if the Label, is "not present" (About Skin shows blank), hide the skin. If the label is present (About Skin shows value), show the skin. The statements would be something like this but I can't get it to work:

Code: Select all

[DriveName]
Measure = FreeDiskSpace
IgnoreRemovable = 0
Drive = "#Letter#"
Label = 1
IfEqualValue = ""
IfEqualAction = [ !HideMeter Background ]
IfAboveValue = ""
IfAboveAction = [ !ShowMeter Background ]
Any suggestions as to how I can get it to work?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Autohide Empty CD/DVD Drive

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000

[Variables]
Drive1=F:

[MeasureLabelDrive1]
Measure=FreeDiskSpace
Drive=#Drive1#
Label=1
IgnoreRemovable=0
Substitute="":"-1"

[CheckDrive1]
Measure=Calc
Formula=[MeasureLabelDrive1]
IfEqualValue=-1
IfEqualAction=!SetOption MeterDrive1 Text "I have no LABEL!"
IfAboveValue=-1
IfAboveAction=!SetOption MeterDrive1 Text ""
DynamicVariables=1

[MeterDrive1]
Meter=String
MeasureName=MeasureLabelDrive1
FontSize=12
FontColor=255,255,255,255
You can't do "IF" actions on a string value like "" or "SomeLabel". IF actions only evaluate numbers. So what we are doing is turning an empty string ("") into a string that is "numeric", in this case -1.

However, if we put the IF actions right on the FreeDiskSpace measure, it will use the original value of the measure, and will not take into account the Substitute. So, we use a Calc measure to evaluate the value of the measure, by using the section variable [SectionName] and DynamicVariables=1. This causes the Calc measure to use the string value of the FreeDiskSpace measure, which has been changed from "" to -1 by the Substitute.

Calc measures will convert any string measure values that are "numeric" into actual numbers when used in a formula, and now the IF actions will work to evaluate the value and take any actions you need. You can !HideMeter / !ShowMeter or !SetOption the text as I did in my example or whatever you like.
PantherX
Posts: 13
Joined: December 3rd, 2012, 5:57 am

Re: Autohide Empty CD/DVD Drive

Post by PantherX »

Thanks for the explanation and code jsmorley :)

Unfortunately, it still can't do what I want so I am going to try my best to explain myself so please bare with me. What I want to be done is broken down into steps to make it easy for me to explain:

Drive action -> Skin action
1) Empty Drive - > Skin is loaded but is automatically hidden
2) Load Drive -> Since skin is loaded, it is now visible as there is a disk
3) Unload Drive -> Skin automatically hides since the drive is empty

If the loading and unloading of the drive is done, I would like the skin to cycle between visible and hidden automatically without refreshing the skin or anything. Basically, just like the USB Drive, when I insert it (assuming the same drive letter), the skin shows and when I eject it, the skin hides but with the DVD Drive.

Attempt 1
I have attached a skin sample (1.ini) which works with Step 2 and Step 3. However, it won't go from Step 1 to Step 2 without me refreshing the skin.

Code: Select all

;Background autohides when drive is empty but doesn't autoshow when drive is loaded.

[Rainmeter]
Update = 1000

[Variables]
Letter = B:
DriveNumber = 2
FontName = Calibri
FontHeight = 6
FontHeight2 = 8
FontHeight3 = 13
FontColor1 = 255, 255, 255, 255
BlueColor = 0, 148, 255, 128
BlueBorder = Border

[Background]
Meter = Image
ImageName = #SKINSPATH#\Test\Background.png
X = 0
Y = 0
W = 90
H = 45
UpdateDivider = -1

;----------
;Measures
;----------

[MeasureLabelDrive1]
Measure=FreeDiskSpace
Drive=#Letter#
Label=1
IgnoreRemovable=0
Substitute="":"-1"

[CheckDrive1]
Measure=Calc
Formula=[MeasureLabelDrive1]
IfEqualValue=-1
IfEqualAction=!HideMeter Background
IfAboveValue=-1
IfAboveAction=!ShowMeter Background
DynamicVariables=1

;----------
;Meters
;----------

[Header1]
Meter = String
X = 2
Y = 2
FontColor = #FontColor1#
FontSize = #FontHeight2#
FontFace = #FontName#
StringEffect = #BlueBorder#
FontEffectColor = #BlueColor#
AntiAlias = #No#
StringAlign = Left
Text = "DRIVE NO.#DriveNumber#"
UpdateDivider = -1

[Header2]
Meter = String
X = 80
Y = 2
FontColor = #FontColor1#
FontSize = #FontHeight2#
FontFace = #FontName#
StringEffect = #BlueBorder#
FontEffectColor = #BlueColor#
AntiAlias = #No#
StringAlign = Right
Text = "#Letter#\"
UpdateDivider = -1

[MeterDrive1]
MeasureName = MeasureLabelDrive1
Meter = String
X = 2
Y = 20
W = 147
H = 20
FontColor = #FontColor1#
FontSize = #FontHeight3#
FontFace = #FontName#
StringEffect = #BlueBorder#
FontEffectColor = #BlueColor#
ClipString = #Yes#
UpdateDivider = 3
Attempt 2
I have attached another skin sample (2.ini) which works with Step 1 and Step 2. However, it won't go from Step 2 to Step 3 without me refreshing the skin.

Code: Select all

;Background autoshows when drive is loaded but doesn't autohide when empty

[Rainmeter]
Update = 1000

[Variables]
Letter = B:
DriveNumber = 2
FontName = Calibri
FontHeight = 6
FontHeight2 = 8
FontHeight3 = 13
FontColor1 = 255, 255, 255, 255
BlueColor = 0, 148, 255, 128
BlueBorder = Border

[Background]
Meter = Image
ImageName = #SKINSPATH#\Test\Background.png
X = 0
Y = 0
W = 90
H = 45
UpdateDivider = -1

;----------
;Measures
;----------

[MeasureLabelDrive1]
Measure=FreeDiskSpace
Drive=#Letter#
Label=1
IgnoreRemovable=0
Substitute="":"-1"

[MeasureLabelDrive2]
Measure=FreeDiskSpace
Drive=#Letter#
Label=1
IgnoreRemovable=0
RegExpSubstitute=1
Substitute="[0-9a-zA-Z]":"2"

[CheckDrive1]
Measure=Calc
Formula=[MeasureLabelDrive1]
IfEqualValue=-1
IfEqualAction=[ !HideMeter Background ]
DynamicVariables=1

[CheckDrive2]
Measure=Calc
Formula=[MeasureLabelDrive2]
IfAboveValue=0
IfAboveAction=[ !ShowMeter Background ]
DynamicVariables=1

;----------
;Meters
;----------

[Header1]
Meter = String
X = 2
Y = 2
FontColor = #FontColor1#
FontSize = #FontHeight2#
FontFace = #FontName#
StringEffect = #BlueBorder#
FontEffectColor = #BlueColor#
AntiAlias = #No#
StringAlign = Left
Text = "DRIVE NO.#DriveNumber#"
UpdateDivider = -1

[Header2]
Meter = String
X = 80
Y = 2
FontColor = #FontColor1#
FontSize = #FontHeight2#
FontFace = #FontName#
StringEffect = #BlueBorder#
FontEffectColor = #BlueColor#
AntiAlias = #No#
StringAlign = Right
Text = "#Letter#\"
UpdateDivider = -1

[MeterDrive1]
MeasureName = MeasureLabelDrive1
Meter = String
X = 2
Y = 20
W = 147
H = 20
FontColor = #FontColor1#
FontSize = #FontHeight3#
FontFace = #FontName#
StringEffect = #BlueBorder#
FontEffectColor = #BlueColor#
ClipString = #Yes#
UpdateDivider = 3
Thus I have two skins which needs to be combined into a single skin and I that is where I am lost :confused: Would appreciate some help :)
You do not have the required permissions to view the files attached to this post.
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Autohide Empty CD/DVD Drive

Post by Mordasius »

You could just combine the two substitute statements in [MeasureLabelDrive1] but that will change the Disk Label to a series of '2s' (e.g. 2222222222) when a disk is loaded. To get around this you can use two measures: one to check if there is a disk loaded and show or hide the background, and; one to get the disk label.

Code: Select all

[MeasureLabelDrive1]
Measure=FreeDiskSpace
Drive=#Letter#
Label=1
IgnoreRemovable=0

[MeasureDriveLoaded]
Measure=FreeDiskSpace
Drive=#Letter#
Label=1
IgnoreRemovable=0
RegExpSubstitute=1
Substitute="[\d\w\s\-]":"2", "":"-1"

[CheckDrive1]
Measure=Calc
Formula=[MeasureDriveLoaded]
IfEqualValue=-1
IfEqualAction=!HideMeter Background
IfAboveValue=-1
IfAboveAction=!ShowMeter Background
DynamicVariables=1
Note that the code above will only show/hide the background image. If you want the image and the text to be shown/hidden when a disk is loaded/unloaded you'll need to add Group=DriveMeters to all the meters and change [CheckDrive1] to:

Code: Select all

[CheckDrive1]
Measure=Calc
Formula=[MeasureDriveLoaded]
IfEqualValue=-1
IfEqualAction=!HideMeterGroup DriveMeters
IfAboveValue=-1
IfAboveAction=!ShowMeterGroup DriveMeters
DynamicVariables=1
One potential problem is still that if the CD/DVD has no label then the skin won't show it as loaded.
PantherX
Posts: 13
Joined: December 3rd, 2012, 5:57 am

Re: Autohide Empty CD/DVD Drive

Post by PantherX »

Thanks very much for the explanation and code Mordasius 8-)

I have tested it on an internal (SATA) DVD Drive and external (USB) DVD drive and it works perfectly :) I am not very bothered about the no label disks since I don't own any like that plus I can't think of a solution for it.

I do have an observation, when ever I load or unload the drive (with the skin activated), the entire Rainmeter application (including other skins) hangs for few seconds, Task Manager reports "Not Responding" and then everything is back to normal. I tested this on Windows 7/8 64-bit so is this a Windows issue, Rainmeter issue or skin? Personally, it doesn't really bother me but I would like to know.
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Autohide Empty CD/DVD Drive

Post by Mordasius »

PantherX wrote:.. is this a Windows issue, Rainmeter issue or skin?
I get the same thing and guess it must be a bit of both Windows and Rainmeter as the FreeDiskSpace measure is niggling the OS to tell it what the disk label is while the OS is still trying to read the label from the CD/DVD.

Read only CDs/DVDs seem to respond much quicker than the read/write versions.
PantherX
Posts: 13
Joined: December 3rd, 2012, 5:57 am

Re: Autohide Empty CD/DVD Drive

Post by PantherX »

Got it. Thanks for that :)