It is currently December 15th, 2019, 6:31 am

Using formulas with meter names? Is it possible?

Get help with installing and using Rainmeter.
User avatar
Krainz
Posts: 154
Joined: May 27th, 2012, 5:16 am

Using formulas with meter names? Is it possible?

Krainz » October 14th, 2019, 5:40 pm

Example:

Let's say I have squares S01, S02, S03 and S04

When clicking square S02, square S01 (metername-1) is hidden

The idea is more or less as follows:

Code: Select all

[Style]
Meter=Image
Solidcolor=0,0,0,255
H=100
W=100
X=150R
LeftMouseUpAction=[!ToggleMeter "S0[-1]"]

[S01]
Meter=Image
MeterStyle=Style

[S02]
Meter=Image
MeterStyle=Style

[S03]
Meter=Image
MeterStyle=Style

[S04]
Meter=Image
MeterStyle=Style
The question is: is it possible to make one unique formula that will always subtract the current meter's ID number by one?

Or do I have to put in a formula for every square that's going to hide the previous one? I.e:

Code: Select all

[Style]
Meter=Image
Solidcolor=0,0,0,255
H=100
W=100
X=150R


[S01]
Meter=Image
MeterStyle=Style

[S02]
Meter=Image
MeterStyle=Style
LeftMouseUpAction=[!ToggleMeter "S01"]

[S03]
Meter=Image
MeterStyle=Style
LeftMouseUpAction=[!ToggleMeter "S02"]

[S04]
Meter=Image
MeterStyle=Style
LeftMouseUpAction=[!ToggleMeter "S03"]
User avatar
balala
Rainmeter Sage
Posts: 9267
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

balala » October 14th, 2019, 8:00 pm

Krainz wrote:
October 14th, 2019, 5:40 pm
The question is: is it possible to make one unique formula that will always subtract the current meter's ID number by one?
No, it's not, however a kind of approach still exists.
First you have to add a String measure, which converts the name of the clicked meter to a simple number:

Code: Select all

[MeasureOrd]
Measure=String
String=#Ord#
RegExpSubstitute=1
Substitute="S0(\d{1})":"\1"
DynamicVariables=1
Now modify the LeftMouseUpAction of the [Style] section (which I believe it's not a meter, as stated by its Meter=Image option, but I style applied to all Image meters, so it shouldn't have to have the mentioned Meter=Image option), using the following option instead of the existing one: LeftMouseUpAction=[!SetVariable Ord "#CURRENTSECTION#"][!UpdateMeasure "MeasureOrd"][!ToggleMeter "S0[MeasureOrd]"][!Redraw]. See that when clicked, the Ord variable gets the name of the clicked meter, this is converted by the [MeasureOrd] measure to a number, then finally the !ToggleMeter bang of the LeftMouseUpAction hides this meter. Note that in this case using the !ToggleMeter bangs is useless, because a meter once hidden (on the first click), it never can be shown again, because you can't click a hidden meter, to get it back.
User avatar
Krainz
Posts: 154
Joined: May 27th, 2012, 5:16 am

Re: Using formulas with meter names? Is it possible?

Krainz » October 14th, 2019, 8:47 pm

Thank you!
User avatar
balala
Rainmeter Sage
Posts: 9267
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

balala » October 14th, 2019, 8:52 pm

:thumbup:
User avatar
Krainz
Posts: 154
Joined: May 27th, 2012, 5:16 am

Re: Using formulas with meter names? Is it possible?

Krainz » December 13th, 2019, 5:51 am

Hey I must be doing something wrong

Here's the measure I'm using:

Code: Select all

[CurrentIcon]
Measure=String
String=#IACT#
RegExpSubstitute=1
Substitute="mIndex(\d{1})":"\1"
DynamicVariables=1
And here's the hotkey measure:

Code: Select all

[Enter]
Measure=Plugin
Plugin=HotKey
HotKey=ENTER
KeyDownAction=[!SetVariable IACT "#CURRENTSECTION#"][!CommandMeasure "mIndex[CurrentIcon]" "Open"]
DynamicVariables=1
It works if I put [!CommandMeasure mIndex1 "Open"]. But if I tried it with all of the following and it didn't work:

KeyDownAction=[!CommandMeasure "[CurrentIcon]" "Open"]
KeyDownAction=[!CommandMeasure "mIndex[CurrentIcon]" "Open"]
KeyDownAction=[!CommandMeasure """mIndex[CurrentIcon]""" "Open"]

What am I supposed to do?


What I'm trying to do: enter opens the currently highlighted fileview icon through CommandMeasure. left and right keyboard arrows change the currently highlighted item. mouseover will also internally set the highlighted item to the one being hovered, but that's mostly for hotkey interactions.

The reason I'm trying to use formulas with these hotkey measures is so that I don't end up needing three hotkey measures for every single fileview item.

EDIT: nevermind, I found a way to resolve it. Your post made me realize I could reference a meter alongside a measure within quotes and Rainmeter will understand it as a meter.

The solution:

Code: Select all

[CurrentN]
Measure=Calc
Formula=1
UpdateDivider=-1
IfCondition=CurrentN < 1
IfTrueAction=[!SetOption CurrentN Formula "1"][!UpdateMeasure CurrentN]

[PressLeftCounter]
Measure=Calc
Formula=PressLeftCounter + 1
Disabled=1
UpdateDivider=-1
OnUpdateAction=[!SetOption CurrentN Formula "([CurrentN] - 1)"][!UpdateMeasure CurrentN][!Redraw]

[PressRightCounter]
Measure=Calc
Formula=PressRightCounter + 1
Disabled=1
UpdateDivider=-1
OnUpdateAction=[!SetOption CurrentN Formula "([CurrentN] + 1)"][!UpdateMeasure CurrentN][!Redraw]

[LeftKeyboard]
Measure=Plugin
Plugin=HotKey
HotKey=LEFT
KeyDownAction=[!HideMeter "btn[CurrentN]"][!EnableMeasure PressLeftCounter][!UpdateMeasure PressLeftCounter][!ShowMeter "btn[CurrentN]"][!Redraw]

[RightKeyboard]
Measure=Plugin
Plugin=HotKey
HotKey=RIGHT
KeyDownAction=[!HideMeter "btn[CurrentN]"][!EnableMeasure PressRightCounter][!UpdateMeasure PressRightCounter][!ShowMeter "btn[CurrentN]"][!Redraw]

[Enter]
Measure=Plugin
Plugin=HotKey
HotKey=ENTER
KeyDownAction=[!CommandMeasure "mIndex[CurrentN]" "Open"]
If anyone is interested or curious, btn1 btn2 btn3 etc are the highlight meters.


Now what I'm having trouble with is the following (and I believe it needs regExp):

I want MouseOverAction to make [CurrentN] the number of the current btn being hovered by the mouse.

Example: mouse hovers over btn5. It does a [!HideMeter "btn[CurrentN]"] and then makes [CurrentN] 5.

Mouse hovers over btn7. It does a [!HideMeter "btn[CurrentN]"] and then makes [CurrentN] 7.

What I tried doing was:

Code: Select all

[btnstyle]
MouseOverAction=[!HideMeter "btn[CurrentN]"][!SetVariable BTNORD #CURRENTSECTION#][!UpdateMeasure "CurrentNstring"][!SetOption CurrentN Formula "[CurrentNstring]"][!UpdateMeasure CurrentN]

[CurrentNstring]
Measure=String
String=#BTNORD#
RegExpSubstitute=1
Substitute="btn(\d{1})":"\1"
DynamicVariables=1
But it doesn't seem to work. What should I do?
User avatar
balala
Rainmeter Sage
Posts: 9267
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

balala » December 13th, 2019, 5:03 pm

Krainz wrote:
December 13th, 2019, 5:51 am
But it doesn't seem to work. What should I do?
:confused:
Have no idea and probably no one will have, because if you're posting just some small pieces of your code, not the entire one, we can't replicate what you have there / the issue. For instance in the above case the substitution of the [CurrentNstring] measure will properly work only if the [btnstyle] section is used onto meters named [btnX] (where X must be a digit). Don't know if it is properly used. Additionally it is extremely hard for us to re-create the whole code, based on the posted sections, especially that probably more sections are not posted at all. To be honest doesn't worth for anyone to work too much just to can replicate the issue. It would be your duty to help us to help you: https://forum.rainmeter.net/viewtopic.php?f=5&t=28421#p148358
Post complete code please, or if resources are needed, pack the config and upload the package. You probably will get help if we can easily replicate the skin and it causes the same problem here as on your side. Otherwise...
User avatar
Krainz
Posts: 154
Joined: May 27th, 2012, 5:16 am

Re: Using formulas with meter names? Is it possible?

Krainz » December 13th, 2019, 8:32 pm

Yeah, I think I should just give up. The btn is this blue frame behind the image panel, and I'd end up having to code around not only hovering the btn but also the image panel.

I gave it a try by setting one of those string meters to tell me the current value of CurrentN and it was always being set to 2 whenever any meter was hovered and when my mouse left the boundaries of any meter it reset back to 1. Crazy.

Maybe lua could do it but I don't have a clue how to code lua
User avatar
balala
Rainmeter Sage
Posts: 9267
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using formulas with meter names? Is it possible?

balala » December 13th, 2019, 9:21 pm

Krainz wrote:
December 13th, 2019, 8:32 pm
Yeah, I think I should just give up. The btn is this blue frame behind the image panel, and I'd end up having to code around not only hovering the btn but also the image panel.

I gave it a try by setting one of those string meters to tell me the current value of CurrentN and it was always being set to 2 whenever any meter was hovered and when my mouse left the boundaries of any meter it reset back to 1. Crazy.

Maybe lua could do it but I don't have a clue how to code lua
Don't directly run into lua. As said it is extremely hard for anyone to help you if we can't simply replicate the issue. That's why I asked you to post a complete code or pack and upload the config (if some resources are involved). Would be much easier to help.
User avatar
Yamajac
Posts: 134
Joined: June 30th, 2014, 8:44 am

Re: Using formulas with meter names? Is it possible?

Yamajac » Yesterday, 11:47 am

Use 1 instead of s01.