It is currently March 28th, 2024, 11:43 am

IfCondition Show/Hide MeterImage or MeterGroup

Get help with creating, editing & fixing problems with skins
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

IfCondition Show/Hide MeterImage or MeterGroup

Post by neo.nemek »

Hello guys, back to the Conditional code, I don't quite understand the IfMatch or IfCondition conditions, even though I try different forms of code, I don't get the desired result.
I have a Measure to check "ADAPTER_TYPE" that returns this data as follows:
0 --> There is no network connection with any adapter.
Wireless --> Connected to the network via WIFI
Ethernet --> Connected to the network via Ethernet

The Measure is this:

Code: Select all

;Check which network connection is being used
[mAdapterType]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_TYPE
DynamicVariables=1
So I have a METER that I want to do these actions:
Action 1, show PNG image relative to "NO CONNECTION" this is GROUP=0 hide any other METER as GROUP 1, 2
Action 2, Hide GROUP=0,GROUP=2 and show PNG "Wireless" and GROUP=1
Action 3, Hide GROUP 0 and 1 also show PNG "Ethernet" and GROUP=3

METERCode:

Code: Select all

;This code does not work it does not show any PNG image
[ImageNetworkPod]
Meter=Image
MeasureName=mAdapterType
ImageTint=#Image Color#
X=200
Y=0
IfCondition=mAdapterType="0"
IfTrueAction=[!SetOption ImageNetworkPod ImageName #Graphic#No Conection.png][!Redraw]
IfCondition2=mAdapterType="Wireless"
IfTrueAction2=[!SetOption ImageNetworkPod ImageName #Graphic#Wireless.png][!Redraw]
IfCondition3=mAdapterType="Ethernet"
IfTrueAction3=[!SetOption ImageNetworkPod ImageName #Graphic#Wireless.png][!Redraw]
DynamicVariables=1
On the other hand, if I try the original METER that only shows the PNG of the wireless, it does show the PNG of the Wireless:

Code: Select all

;Show the Wifi PNG image on the POD
;[Image]
;Meter=Image
;ImageName=#Graphic#Wireless.png
;ImageTint=#Image Color#
;X=200
;Y=0
;Hidden=0
;Group=1 | WifiPOD
As much as I try to understand the Conditionals, I have not quite written the code correctly, can you help me on this again? Thank you very much for all your help
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by balala »

neo.nemek wrote: February 14th, 2023, 8:53 pm As much as I try to understand the Conditionals, I have not quite written the code correctly, can you help me on this again?
There are some things you should take into account:
  • IfConditions are options which can be used only on measures. They don't work on meters. So the IfConditions added to the above [ImageNetworkPod] meter (which is an Image meter), don't work, they don't do anything (in fact are ignored). You should move them to a measure, for instance to [mAdapterType].
  • IfConditions is working with the numerical values of measures. They can't deal with the string values and have to be entirely numeric. This means that even if the above IfConditions could work, they could check only the numeric value of a measure. So you can't do something like IfCondition2=mAdapterType="Wireless" or IfCondition3=mAdapterType="Ethernet". Theoretically at least the first IfCondition (IfCondition=mAdapterType=0 - see that I removed the quotes) could be correct, but in fact it's not either.
  • To check string values, you should have to use IfMatches. For instance (not checked):

    Code: Select all

    [mAdapterType]
    Measure=Plugin
    Plugin=SysInfo
    SysInfoType=ADAPTER_TYPE
    DynamicVariables=1
    IfMatch=0
    IfMatchction=[!SetOption ImageNetworkPod ImageName "#Graphic#No Conection.png"][!UpdateMeter "ImageNetworkPod"][!Redraw]
    IfMatch2=Wireless
    IfMatchAction2=[!SetOption ImageNetworkPod ImageName "#Graphic#Wireless.png"][!UpdateMeter "ImageNetworkPod"][!Redraw]
    IfMatch3=Ethernet
    IfMatchAction3=[!SetOption ImageNetworkPod ImageName "#Graphic#Wireless.png"][!UpdateMeter "ImageNetworkPod"][!Redraw]
Additional note: I added some [!UpdateMeter "ImageNetworkPod"] bangs to the IfMatchAction options. Setting an ImageName to an Image meter and redrawing the skin does nothing unless you're updating the meter. This is why I added those bangs.
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by neo.nemek »

[*]To check string values, you should have to use IfMatches. For instance (not checked):

Code: Select all

[mAdapterType]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_TYPE
DynamicVariables=1
IfMatch=0
IfMatchction=[!SetOption ImageNetworkPod ImageName "#Graphic#No Conection.png"][!UpdateMeter "ImageNetworkPod"][!Redraw]
IfMatch2=Wireless
IfMatchAction2=[!SetOption ImageNetworkPod ImageName "#Graphic#Wireless.png"][!UpdateMeter "ImageNetworkPod"][!Redraw]
IfMatch3=Ethernet
IfMatchAction3=[!SetOption ImageNetworkPod ImageName "#Graphic#Wireless.png"][!UpdateMeter "ImageNetworkPod"][!Redraw]
[/list]

Additional note: I added some [!UpdateMeter "ImageNetworkPod"] bangs to the IfMatchAction options. Setting an ImageName to an Image meter and redrawing the skin does nothing unless you're updating the meter. This is why I added those bangs.
[/quote]

This time the code did not work the first time, it must be that "ADAPTER_TYPE" does not return that data 0,Wireless,Ethernet.
But it's weird, I have a text METER to check that it returns "[mAdapterType]" and that's what the METER writes to me on the screen:

Code: Select all

[MeterAdapterType-TEMP]
Meter=String
MeasureName=mAdapterType
x=130
y=125
FontSize=12
FontColor=White
Text=%1
AntiAlias=1
DynamicVariables=1
;Show me: 0, Wireless, Ethernet in screen
I don't understand why this time in the Network POD it doesn't work and instead in the weather POD it did work, I'm going to post a zip with the skin of that POD and we'll see what happens, Sorry for so much inconvenience but I need to finish this POD to smile happily hahahaha
Attachments
Network -Left Tab.rar
POD Skin Network
(2.02 KiB) Downloaded 3 times
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by SilverAzide »

neo.nemek wrote: February 14th, 2023, 8:53 pm Hello guys, back to the Conditional code, I don't quite understand the IfMatch or IfCondition conditions, even though I try different forms of code, I don't get the desired result.
I have a Measure to check "ADAPTER_TYPE" that returns this data as follows:
0 --> There is no network connection with any adapter.
Wireless --> Connected to the network via WIFI
Ethernet --> Connected to the network via Ethernet

The Measure is this:

Code: Select all

;Check which network connection is being used
[mAdapterType]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_TYPE
DynamicVariables=1
So I have a METER that I want to do these actions:
Action 1, show PNG image relative to "NO CONNECTION" this is GROUP=0 hide any other METER as GROUP 1, 2
Action 2, Hide GROUP=0,GROUP=2 and show PNG "Wireless" and GROUP=1
Action 3, Hide GROUP 0 and 1 also show PNG "Ethernet" and GROUP=3
In addition to the problems mentioned by balala, you have a few more issues to consider.

Your idea of using the SysInfo ADAPTER_TYPE to return 0 to indicate no network is flawed. The only time this logic works 100% is if you have no network adapters at all. You can easily run into cases where you have no active network connections but this measure will still return a non-zero value. Also don't forget that the ADAPTER_TYPE returns numeric values in addition to string values, so using IfConditions will work if you test for numeric values:

Code: Select all

[mAdapterType]
...
IfCondition=(mAdapterType = 6)
IfTrueAction=[!Log "Active adapter type is Ethernet" Notice][!do other stuff...]
IfCondition2=(mAdapterType = 71)
IfTrueAction2=[!Log "Active adapter type is Wireless" Notice][!do other stuff...]
To determine if you have or don't have an active network connection, you should use SysInfo LAN_CONNECTIVITY. To determine if you have or don't have a connection to the internet, you should use SysInfo WAN_CONNECTIVITY.

So, to implement the logic you stated in your post in blue, you need two measures, like so:

Code: Select all

[mNetworkIsActive]
Measure=SysInfo
SysInfoType=LAN_CONNECTIVITY

[mAdapterType]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_TYPE
DynamicVariables=1
IfCondition=(mNetworkIsActive = 1) && (mAdapterType = 6)
IfTrueAction=[!Log "Connected to the network via Ethernet" Notice][!do other stuff like show/hide meter groups...]
IfCondition2=(mNetworkIsActive = 1) && (mAdapterType = 71)
IfTrueAction2=[!Log "Connected to the network via WIFI" Notice][!do other stuff...]
IfCondition3=(mNetworkIsActive = 1) && (mAdapterType <> 6) && (mAdapterType <> 71)
IfTrueAction3=[!Log "Connected to the network via some other adapter type" Notice][!do other stuff...]
IfCondition4=(mNetworkIsActive = -1)
IfTrueAction4=[!Log "There is no network connection with any adapter" Notice][!do other stuff...]
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by neo.nemek »

Your idea of using the SysInfo ADAPTER_TYPE to return 0 to indicate no network is flawed. The only time this logic works 100% is if you have no network adapters at all. You can easily run into cases where you have no active network connections but this measure will still return a non-zero value. Also don't forget that the ADAPTER_TYPE returns numeric values in addition to string values, so using IfConditions will work if you test for numeric values:

Code: Select all

[mAdapterType]
...
IfCondition=(mAdapterType = 6)
IfTrueAction=[!Log "Active adapter type is Ethernet" Notice][!do other stuff...]
IfCondition2=(mAdapterType = 71)
IfTrueAction2=[!Log "Active adapter type is Wireless" Notice][!do other stuff...]
To determine if you have or don't have an active network connection, you should use SysInfo LAN_CONNECTIVITY. To determine if you have or don't have a connection to the internet, you should use SysInfo WAN_CONNECTIVITY.

So, to implement the logic you stated in your post in blue, you need two measures, like so:

Code: Select all

[mNetworkIsActive]
Measure=SysInfo
SysInfoType=LAN_CONNECTIVITY

[mAdapterType]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_TYPE
DynamicVariables=1
IfCondition=(mNetworkIsActive = 1) && (mAdapterType = 6)
IfTrueAction=[!Log "Connected to the network via Ethernet" Notice][!do other stuff like show/hide meter groups...]
IfCondition2=(mNetworkIsActive = 1) && (mAdapterType = 71)
IfTrueAction2=[!Log "Connected to the network via WIFI" Notice][!do other stuff...]
IfCondition3=(mNetworkIsActive = 1) && (mAdapterType <> 6) && (mAdapterType <> 71)
IfTrueAction3=[!Log "Connected to the network via some other adapter type" Notice][!do other stuff...]
IfCondition4=(mNetworkIsActive = -1)
IfTrueAction4=[!Log "There is no network connection with any adapter" Notice][!do other stuff...]
Well I think I have it after some code tests (2h of tests) hahaha, I am still very new to Rainmeter and its instructions since I have only been studying how code instructions behave for 2 weeks. Thank you without your help I would not have made it.

Code: Select all

IfCondition4=(mNetworkIsActive = -1)
IfTrueAction4=[!Log "There is no network connection with any adapter" Notice][!SetVariable Group4 "0"][!SetVariable OpenTabGroup "4"][!Redraw]
When it is finished I will delete the piece of code that injects the !Log.

A question @SilverAzide!!

Code: Select all

(mAdapterType = 6)
(mAdapterType = 71)
Because the Number 6 and 71 are used, can you explain those numbers why they can't be others like 9 and 84 for example?
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by eclectic-tech »

A question @SilverAzide!!

Code: Select all

(mAdapterType = 6)
(mAdapterType = 71)
Because the Number 6 and 71 are used, can you explain those numbers why they can't be others like 9 and 84 for example?
ADAPTER_TYPE : [String and Number] The type of network adapter specified by SysInfoData.

The string value will be one of Ethernet, Wireless or Other. The number value will be one of 6 (Ethernet), 71 (Wireless), or some other number in the range 0-280 (Other). The meaning of numeric codes other than 6 and 71 can be found at: docs.microsoft.com Adapter Info.
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by neo.nemek »

eclectic-tech wrote: February 15th, 2023, 1:40 pm ADAPTER_TYPE : [String and Number] The type of network adapter specified by SysInfoData.

The string value will be one of Ethernet, Wireless or Other. The number value will be one of 6 (Ethernet), 71 (Wireless), or some other number in the range 0-280 (Other). The meaning of numeric codes other than 6 and 71 can be found at: docs.microsoft.com Adapter Info.
Thank you now I understand the reasoning of the numbers 6 and 71.
After several hours of thinking and thinking, trying and trying, the sentence is almost ready and now it changes the POD image according to the network connection it has established:

Code: Select all

[mNetworkIsActive]
Measure=SysInfo
SysInfoType=LAN_CONNECTIVITY

[mAdapterType]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_TYPE
DynamicVariables=1
IfCondition=(mNetworkIsActive = 1) && (mAdapterType = 6)
IfTrueAction=[!Log "Connected to the network via Ethernet" Notice][!SetOption ImageNetworkPod ImageName "#Graphic#Ethernet.png"][!SetVariable OpenTabGroup "1"][!Redraw]
IfCondition2=(mNetworkIsActive = 1) && (mAdapterType = 71)
IfTrueAction2=[!Log "Connected to the network via WIFI" Notice][!SetOption ImageNetworkPod ImageName "#Graphic#Wireless.png"][!SetVariable OpenTabGroup "2"][!Redraw]
IfCondition3=(mNetworkIsActive = 1) && (mAdapterType <> 6) && (mAdapterType <> 71)
IfTrueAction3=[!Log "Connected to the network via some other adapter type" Notice][!SetOption ImageNetworkPod ImageName "#Graphic#UnknowConection.png"][!SetVariable OpenTabGroup "3"][!Redraw]
IfCondition4=(mNetworkIsActive = -1)
IfTrueAction4=[!Log "No Network conections avalaible" Notice][!SetOption ImageNetworkPod ImageName "#Graphic#NoConection.png"][!SetVariable OpenTabGroup "4"][!Redraw]
neo.nemek
Posts: 36
Joined: February 11th, 2023, 7:52 am

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by neo.nemek »

New correct code syntax problem.
I have declared a Variable "OpenTabGroup=0" and depending on the network connection I have established, the Variable "OpenTabGroup" takes the value 1 or 2 or 3 or 4.
I need that within a METER that Variable be checked and execute a series of actions by doing "LeftMouseDownAction" on an image so that there will be a TAB slide and show some hidden METERS, the code is this:

Code: Select all

[TabClosed-Open Network TAB]
Meter=Image
ImageName=#Graphic#Tab.png
ImageFlip=Horizontal
ImageTint=#Tab Color#
X=188
Y=0
IfCondition=(#OpenTabGroup# = 1)
IfTrueAction=LeftMouseDownAction=!Execute [!HideMeterGroup 6][!ShowMeterGroup 7][!ShowMeterGroup "NetworkIP"][!Redraw]
.
.
.
But this code syntax doesn't work because the code after "IfTrueAction=" is wrongly assembled, its syntax is incorrect.

This is the correct line that if it works alone without the aforementioned Variable check

Code: Select all

LeftMouseDownAction=!Execute [!RainmeterHideMeterGroup 6][!RainmeterShowMeterGroup 7]
How do I pass this correctly written line after "IfTrueAction" if it is possible and Rainmeter allows it, otherwise I would have to think of another way to open the TAB and show the hidden METERS

Can I put this action inside a Variable?

IfTrueAction=[!SetVariable OpenTabGroup "!Execute [!RainmeterHideMeterGroup 6][!RainmeterShowMeterGroup 7]"]

It seems that if I can put that instruction inside a variable, how good I did not expect to be able to put that instruction inside the Variable
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by balala »

neo.nemek wrote: February 15th, 2023, 7:41 pm I need that within a METER that Variable be checked and execute a series of actions by doing "LeftMouseDownAction" on an image so that there will be a TAB slide and show some hidden METERS,
See the first point of my reply above. IfCondition can't work on meters, just on measures. It's completely useless to add them to a meter, because it's ignored on meters. So, move it to a measure (in fact doesn't even really matter which measure are you moving it to, but what is important is to use it on a measure, for nstance on [mAdapterType]).
neo.nemek wrote: February 15th, 2023, 7:41 pm But this code syntax doesn't work because the code after "IfTrueAction=" is wrongly assembled, its syntax is incorrect.
It definitely is, but there is a question and I can't follow what you want to do: do you want to set the proper LeftMouseUpAction option to a meter, depending on the value of the OpenTabGroup variable, or you want to execute certain operation depending on the value of the variable?
In first case, you have to use !SetOption bangs. For instance this way:

Code: Select all

[mAdapterType]
Measure=
...
IfCondition=(#OpenTabGroup# = 1)
IfTrueAction=[!SetOption "TabClosed-Open Network TAB" LeftMouseDownAction """[!HideMeterGroup 6][!ShowMeterGroup 7][!ShowMeterGroup "NetworkIP"][!Redraw]"""][!UpdateMeter "TabClosed-Open Network TAB"]
IfCondition2=(#OpenTabGroup# = 2)
IfTrueAction2=[!SetOption "TabClosed-Open Network TAB" LeftMouseDownAction """[ ADD HERE THE APPROPRIATE BANGS, YOU WANT TO SET TO THE LEFTMOUSEUPACTION OPTION FOR THIS CASE]"""][!UpdateMeter "TabClosed-Open Network TAB"]
...
Note here that I included the bangs you want to set with the !SetOption bang into triple quotes (Magic Quotes), which are needed because the bangs themselves contain quotes. Also I removed the deprecated and not needed !Execute bang. Don1t use it anymore, because it has been deprecated long time ago.
For second case, add simply the bangs to the IfTrueAction options:

Code: Select all

[mAdapterType]
Measure=
...
IfCondition=(#OpenTabGroup# = 1)
IfTrueAction=[!HideMeterGroup 6][!ShowMeterGroup 7][!ShowMeterGroup "NetworkIP"][!Redraw]
IfCondition2=(#OpenTabGroup# = 2)
IfTrueAction2=[ ADD HERE THE APPROPRIATE BANGS, YOU WANT TO SET TO THE LEFTMOUSEUPACTION OPTION FOR THIS CASE]
...
If I misunderstood you please give us (me) a few details on what you want to achieve.

Additional note (again): even if not forbidden, it's not a good idea either to use spaces into names of sections. Instead of [TabClosed-Open Network TAB] (with spaces), I recommend to use for example [TabClosed-OpenNetworkTAB] (no spaces). If the name contain spaces, whenever are you using it into a bang, you have to quote it, otherwise the bang fails.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: IfCondition Show/Hide MeterImage or MeterGroup

Post by SilverAzide »

neo.nemek wrote: February 15th, 2023, 7:41 pm New correct code syntax problem.
I have declared a Variable "OpenTabGroup=0" and depending on the network connection I have established, the Variable "OpenTabGroup" takes the value 1 or 2 or 3 or 4.
I need that within a METER that Variable be checked and execute a series of actions by doing "LeftMouseDownAction" on an image so that there will be a TAB slide and show some hidden METERS, the code is this:

...

How do I pass this correctly written line after "IfTrueAction" if it is possible and Rainmeter allows it, otherwise I would have to think of another way to open the TAB and show the hidden METERS

Can I put this action inside a Variable?

It seems that if I can put that instruction inside a variable, how good I did not expect to be able to put that instruction inside the Variable
As mentioned by balala in reference to your original post, you cannot have IfConditions on meters. You can only have IfConditions on measures.

Also, please get rid of all that !Execute and !Rainmeter stuff, that junk was dropped from Rainmeter years and years ago.

And finally, you should try to avoid using spaces in your "section names". Section names are the things inside square brackets, like [mAdapterType]. Using section names like [TabClosed-Open Network TAB] is going to lead to problems down the road even though it will usually work, but try to break this bad habit now while you are learning. Don't use symbols like +/-/etc either, as Rainmeter can get confused and think you are trying to do some math expression.

To answer your question, you have all the logic you need already built in the [mAdapterType] measure, no need for any extra variables. You just need to add additional bangs to control the appearance, like [!ShowMeterGroup "NetworkIP"] or whatever. I don't see where you have added any Group options to any meters, but I assume they are elsewhere in your code.
Post Reply