It is currently April 19th, 2024, 7:45 pm

Validate if a file exist otherwise set a default file

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

Yincognito wrote: November 2nd, 2020, 10:44 pm Aaaah... now it makes sense, of course. But if one wants to find the dimensions of an image, he could / should be able to do that by not constraining the W and H of the meter, right? Which is precisely what I did in the above code. This is the main reason why I didn't understand the need to use a plugin for that, to be honest.
Sure, it's just that loading and displaying the image may not be what you want. You can make it transparent I guess, but don't forget that you can't "hide" it. That will set the size to zero.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeterImage]
Meter=Image
ImageName=#@#Images\laughing.jpg
ImageAlpha=0

[MeterSize]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[MeterImage:W] by [MeterImage:H]
DynamicVariables=1
User avatar
Yincognito
Rainmeter Sage
Posts: 7128
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

jsmorley wrote: November 2nd, 2020, 10:45 pm Sure, it's just that loading and displaying the image may not be what you want. You can make it transparent I guess, but don't forget that you can't "hide" it. That will set the size to zero.
I didn't "hide" it. I just set its coordinates to negative values to keep is out of view / skin. As far as I could see, this is something you have done as well, when iterating through the possibilities to do certain things, in your plugin page, so you can't say it's just my crazy unorthodox approach this time. :lol:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

Yincognito wrote: November 2nd, 2020, 10:49 pm I didn't "hide" it. I just set its coordinates to negative values to keep is out of view / skin. As far as I could see, this is something you have done as well, when iterating through the possibilities to do certain things, in your plugin page, so you can't say it's just my crazy unorthodox approach this time. :lol:
I don't see any reason why a meter that is "outside" the skin would not return a width and height value, but perhaps they are truncated when outside the skin. That is certainly possible. That is true when a meter is constrained in a Container for instance.
User avatar
Yincognito
Rainmeter Sage
Posts: 7128
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

Just in case you didn't see or read it, this is the problem with the approach we talk about, which in theory should work (unless it's a consequence of image caching, that is).

P.S. I didn't use negative coordinates or truncate the meter in any way in the sample I linked to, by the way.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

No, this still works...

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeterImage]
Meter=Image
X=-700
ImageName=#@#Images\laughing.jpg
;ImageAlpha=0

[MeterSize]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[MeterImage:W] by [MeterImage:H]
DynamicVariables=1
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

Yincognito wrote: November 2nd, 2020, 10:52 pm Just in case you didn't see or read it, this is the problem with the approach we talk about, which in theory should work (unless it's a consequence of image caching, that is).

P.S. I didn't use negative coordinates or truncate the meter in any way in the sample I linked to, by the way.
Ah, that is a horse of a different color. That feels like a a bit of a bug to me. Seems to me that the code isn't "forgetting" the old values when there are no possible "new" values. In general though, I'm not sure I would count on "doesn't exist" to be the same as "zero" ever in programming. NULL is not zero... I will grant you that the size of an image that doesn't exist is zero, but I'm not sure how the code is handling things after it has already reached the point where there is the error in loading the image.
User avatar
Yincognito
Rainmeter Sage
Posts: 7128
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

jsmorley wrote: November 2nd, 2020, 10:57 pm Ah, that is a horse of a different color. That feels like a a bit of a bug to me. Seems to me that the code isn't "forgetting" the old values when there are no possible "new" values. In general though, I'm not sure I would count on "doesn't exist" to be the same as "zero" ever in programming. NULL is not zero...
Yeah, but it usually defaults to 0, at least in Rainmeter's book.
So, jsmorley, now you understand my consternation that I had to use a plugin (it just happened to be yours, incidentally) just to get this piece of functionality that I should been able to get using the "normal" / "built-in" Rainmeter capabilities? 8-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

Yincognito wrote: November 2nd, 2020, 11:03 pm Yeah, but it usually defaults to 0, at least in Rainmeter's book.
So, jsmorley, now you understand my consternation that I had to use a plugin (it just happened to be yours, incidentally) just to get this piece of functionality that I should been able to get using the "normal" / "built-in" Rainmeter capabilities? 8-)
I sorta resist that this is a "normal" way to approach this. I don't know what kind of dark hole Rainmeter goes into when it can't find the image you request, but it is in any case purposely generating an "error" condition, and I wouldn't go that route myself. I'd be tempted to use !SetOption to change from ImageName=Image0.jpg to removing the ImageName option entirely. Then the Image meter is going to be depending on W / H / SolidColor to define the image, and since there is no W or H, that is properly "zero".
User avatar
Yincognito
Rainmeter Sage
Posts: 7128
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

jsmorley wrote: November 2nd, 2020, 11:06 pm I sorta resist that this is a "normal" way to approach this. I don't know what kind of dark hole Rainmeter goes into when it can't find the image you request, but it is in any case purposely generating an "error" condition, and I wouldn't go that route myself. I'd be tempted to use !SetOption to change from ImageName=Image0.jpg to removing the ImageName option entirely. Then the Image meter is going to be depending on W / H / SolidColor to define the image, and since there is no W or H, that is properly "zero".
Yeah, well, let's just call it a "trick" then. :p You know, something you do to simplify things, while achieving the same result.
Also, while we are here, since it's part of this topic, any idea how to handle this? Is this possible (yeah, I know, parsing is complicated in Rainmeter, I agree)?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

Yincognito wrote: November 2nd, 2020, 11:14 pm Yeah, well, let's just call it a "trick" then. :p You know, something you do to simplify things, while achieving the same result.
Also, while we are here, since it's part of this topic, any idea how to handle this? Is this possible (yeah, I know, parsing is complicated in Rainmeter, I agree)?
Parsing is complicated indeed. I think Brian will have to weigh in on that one.