It is currently April 27th, 2024, 3:19 pm

[BUG] Substitute dosen't show in the Log's Skin tab on some occasions

Report bugs with the Rainmeter application and suggest features.
User avatar
Jeff
Posts: 332
Joined: September 3rd, 2018, 11:18 am

[BUG] Substitute dosen't show in the Log's Skin tab on some occasions

Post by Jeff »

Image

An inconsequential bug really, but I observed that when you apply Substitute, in the Log > Skins tab, it only shows on some measures but on others it dosen't.
The code below is what's in the image, a String measure and a CPU measure.
I imagine that for the CPU measure, the reason why the Substitute dosen't show in the Log, but works fine on the meter is because the Substitute might be applied after NumOfDecimals=0 executes. This is based on the assumption that the problem only dissolves down to the order of checks Rainmeter does in the code and that it's not an actual bug or something that was overlooked in the code, I can't read the code so I can't know.

Code: Select all

[StringA]
Measure=String
String=33
RegExpSubstitute=1
Substitute="(^\d\d\d$)":"0\0","(^\d\d$)":"00\0","(^\d$)":"000\0"
[StringB]
Measure=CPU
RegExpSubstitute=1
Substitute="(^\d\d\d$)":"0\0","(^\d\d$)":"00\0","(^\d$)":"000\0"
[Stylization]
FontSize=100
FontColor=FEDCAB
AntiAlias=1
InLineSetting=Shadow | 1 | 1 | 2 | ABCDEF
[Meter1]
Meter=String
MeasureName=StringA
MeterStyle=Stylization
[Meter2]
Meter=String
MeasureName=StringB
MeterStyle=Stylization
Y=R
User avatar
Yincognito
Rainmeter Sage
Posts: 7176
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Substitute dosen't show in the Log's Skin tab on some occasions

Post by Yincognito »

Jeff wrote: July 11th, 2023, 8:42 pmI imagine that for the CPU measure, the reason why the Substitute dosen't show in the Log, but works fine on the meter is because the Substitute might be applied after NumOfDecimals=0 executes.
Your assumption is almost correct - and no, this isn't a bug, it has to do with how Rainmeter works internally. Take a look here (at when, where and on what the substitution is performed from the first post, and also at the subsequent replies on a somewhat related topic, if you're interested) for some insight on how it works. The main thing here is that generally and a bit counterintuitively (but in a way, similar to how dynamic variables or bangs operate too), the substitution mostly happens when the measure is used (in your meter, in this case), and on that used value - it doesn't happen like you'd expect, strictly when the measure it is attached to is updated.

This is why, in your case, you can get away with a substitute that only takes into account integer values (like your substitute does), even though the measure, bar the initial "0" value, yields mostly fractional values for the CPU usage (e.g. 15.36765 and not 15). So, the substitution happens when your measure is referenced in the related meter, and by that time, because of the default 0 number of decimals in the meter, the numeric value of the measure there is reduced to an integer value, before being handled as a string. That is also why you don't get the expected 0 padded string value in the log, because to get that, you'd have to operate on the string representation of the "true" fractional numerical value of the measure (and not on its decimal stripped value it's constrained to in the meter). Even after taking these into account, you still won't get the desired string both in the log and the meter, unless you specifically use the measure's string value as a section variable, obviously enabling dynamic variables in the meter as well, like this:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,1

---Meters---

[StringA]
Measure=String
String=33
RegExpSubstitute=1
Substitute="(^\d\d\d$)":"0\0","(^\d\d$)":"00\0","(^\d$)":"000\0"
[StringB]
Measure=CPU
RegExpSubstitute=1
Substitute="^(\d*\.\d*)$":"000\1","^\d*(\d{4})\.\d*$":"\1"
[Stylization]
FontSize=100
FontColor=FEDCAB
AntiAlias=1
InLineSetting=Shadow | 1 | 1 | 2 | ABCDEF
[Meter1]
Meter=String
MeasureName=StringA
MeterStyle=Stylization
[Meter2]
Meter=String
Text=[StringB]
DynamicVariables=1
MeterStyle=Stylization
Y=R
Take a look at [StringB] and [Meter2] for comparison with the previous code. Naturally, since we don't strip decimals from the measure's numerical value anymore but we do it on its string value, the displayed value is in fact truncated and not rounded. I assumed here that the measure will always have fractional values, disregarding the few exception cases, so if you need that, you'd have to make the decimal dot and the following stuff optional by adding a question mark (?) after the desired expression (e.g. \.?\d*? in the above case), or fake fractional values like below.

--------------

Bonus Note: On zero or space padding substititions - they can be done in a more general fashion, e.g.:

Code: Select all

Substitute="^(.*)$":"0000\1","^.*(.{5})$":"\1"
for an integer value padded to a 5 digit string (the easiest example). Two substitutions is all it takes: one to add the maximum number of padding characters (4 since at least 1 character is assumed for the original string), the other to remove the surplus characters (what's more than 5 chars). You can use a similar approach for digits after the decimal point or even when combining the padding characters, e.g.:

Code: Select all

Substitute="^([^\.]*)$":"\1.","^(.*)$":"  \100","^.*(.{3}\..{2}).*$":"\1"
for a fractional value that has its integer part space padded to a 3 char string and its fractional part zero padded to a 2 char string, like   3.20. The first substitution simply fakes a decimal point after an integer value, to make things more consistent in the following substitutions. Needless to say, having a - or a + before the value (like for weather temps) adds some bits to the subs, but that's to be expected anyway.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth