It is currently May 26th, 2020, 8:43 pm

Help: Switching wallpapers with a button

Help with creating, editing & fixing problems with skins
Mino_el_Nukenin
Posts: 181
Joined: April 24th, 2020, 7:39 pm
Location: France

Help: Switching wallpapers with a button

Post by Mino_el_Nukenin »

Hi,
New to Rainmeter for some days now.
I've been updating by myself a Skin already made.

It's a button that toggle all the others skins on the desktop. This part works fine.
I want this button to also set a wallpaper (wallpaper - active) when I click it and to set back the first wallpaper (wallpaper - inactive) when I click again.

So far I've managed the setting of new wallpaper (active) but can't find a way to toggle the setting of first one (inactive) back.

Here is the code so far :

Code: Select all

[Rainmeter]
Author=Media Maggot | Daelnz | Mino

[Metadata]
Name=Shield Button
Information=Clicking on the Shield logo opens the desktop features + set wallpaper
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Version=1.1.1

[Variables]
@include=#SKINSPATH#\SHIELD Agent Module\Config.inc

[MeterButton]
Meter=BUTTON
ButtonImage=Shield Button.png
ButtonCommand=[!ToggleFadeGroup "SHIELD Agent Module"]
LeftMouseUpAction=[!SetWallpaper "#SKINSPATH#\SHIELD Agent Module\Wallpaper - active.png" Fill]
Antialias=1
For what I read and understood in the tutorials I think it has something to do with an "IfAction" or something like that..
Thanks in advance for your help
User avatar
balala
Rainmeter Sage
Posts: 10605
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help: Switching wallpapers with a button

Post by balala »

Mino_el_Nukenin wrote:
April 24th, 2020, 7:52 pm
So far I've managed the setting of new wallpaper (active) but can't find a way to toggle the setting of first one (inactive) back.
I recommend to add a variable into the [Variables] section, let's name it MyVar:

Code: Select all

[Variables]
...
MyVar=0
Now remove the ButtonCommand option of the [MeterButton] and replace the LeftMouseUpAction with the following one: LeftMouseupAction=[!SetVariable MyVar "(1-#MyVar#)"][!UpdateMeasure "MeasureMyVar"][!UpdateMeter "#CURRENTSECTION#"]. Also add a DynamicVariables=1 option to the [MeterButton] meter.
And finally add the following measure:

Code: Select all

[MeasureMyVar]
Measure=Calc
Formula=#MyVar#
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!HideFadeGroup "SHIELD Agent Module"][!SetWallpaper "#SKINSPATH#\SHIELD Agent Module\Wallpaper - active.png" Fill]
IfFalseAction=[!ShowFadeGroup "SHIELD Agent Module"][!SetWallpaper "ADD-THE-OTHER-WALLPAPER.png" Fill]
DynamicVariables=1
Additional tip: it's not a good idea to use both ButtonCommand and LeftMouseUpAction, on the same button meter. To avoid headache, recommend to use only one of them. There is not too important which one do you choose, but don't use both. On the Note here you can find out what1s the difference between the two options.
Mino_el_Nukenin
Posts: 181
Joined: April 24th, 2020, 7:39 pm
Location: France

Re: Help: Switching wallpapers with a button

Post by Mino_el_Nukenin »

Thanks so much for the help and the quick response.

It works perfectly : Now I have a button that toggles all my skins and activate my wallpaper and if I click it again everything fade as I want.

Code: Select all

...
[Variables]
@include=#SKINSPATH#\SHIELD Agent Module\Config.inc
MyVar=0

[MeterButton]
Meter=BUTTON
ButtonImage=Shield Button.png
LeftMouseupAction=[!SetVariable MyVar "(1-#MyVar#)"][!UpdateMeasure "MeasureMyVar"][!UpdateMeter "#CURRENTSECTION#"]
DynamicVariables=1
Antialias=1

[MeasureMyVar]
Measure=Calc
Formula=#MyVar#
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!ShowFadeGroup "SHIELD Agent Module"][!SetWallpaper "#SKINSPATH#\SHIELD Agent Module\Wallpaper - active.png" Fill]
IfFalseAction=[!HideFadeGroup "SHIELD Agent Module"][!SetWallpaper "#SKINSPATH#\SHIELD Agent Module\Wallpaper - inactive.png" Fill]
DynamicVariables=1
BUT, I'm trying to understand how it works.
So basically with the [measure] and the differents [meter] it's like the button goes from the situation 0 to situation 1 ?
I'm kinda lost with it.
User avatar
balala
Rainmeter Sage
Posts: 10605
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help: Switching wallpapers with a button

Post by balala »

Mino_el_Nukenin wrote:
April 24th, 2020, 10:11 pm
BUT, I'm trying to understand how it works.
So basically with the [measure] and the differents [meter] it's like the button goes from the situation 0 to situation 1 ?
I'm kinda lost with it.
It's not too hard. There is the MyVar variable, which can be either 0 or 1. Its value is switched by the [!SetVariable MyVar "(1-#MyVar#)"] bang of the [MeterButton] meter, between these two values. Now when the MyVar variables changes, the IfCondition of the [MeasureMyVar] measure is reevaluated and the appropriate bangs of either the IfTrueAction or IfFalseAction are executed, which led to change the wallpaper and toggle the state of the skins belonging to the SHIELD Agent Module group.
However here I have an additional comment: although not forbidden, neither a good idea is to use spaces into the name of the groups (or sections, variables or whatever). It definitely works, but the problem is that always when you want to execute any action with such a group, you have to include its (spaces containing) name into quotes, otherwise it won't work. Getting rid of those spaces can avoid a lot of possible future troubles.
Just a few details about the spaces in section names (same applies for variable or group names): https://forum.rainmeter.net/viewtopic.php?f=5&t=31683&p=160586#p160586
And a few others about the necessity of quotes: https://forum.rainmeter.net/viewtopic.php?p=174602#p174603
Mino_el_Nukenin
Posts: 181
Joined: April 24th, 2020, 7:39 pm
Location: France

Re: Help: Switching wallpapers with a button

Post by Mino_el_Nukenin »

Thanks for the explanation. Since I'm really starting rainmeter and coding I'm a bit confused with meter, measure, bang, etc, even after reading the tutorials for beginners. Now it's clearer.
Thanks for the tip about "quote" group.

The button works fine, but I also would like the system to set back the inital wallpaper (inactive) when shutting down, because for exemple today when I turned on the PC, the active wallpaper was already set, even before clicking the button.
User avatar
balala
Rainmeter Sage
Posts: 10605
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help: Switching wallpapers with a button

Post by balala »

Mino_el_Nukenin wrote:
April 25th, 2020, 12:56 pm
The button works fine, but I also would like the system to set back the inital wallpaper (inactive) when shutting down, because for exemple today when I turned on the PC, the active wallpaper was already set, even before clicking the button.
Yes, it is when you turn on the computer, because when Rianmeter starts it loads the skins, among others this skin as well. But this skin having the MyVar variable set to 0 (into the [Variables] section), this is the value the skin starts with. The IfTrueAction option of the [MeasureMyVar] measure (which is executed when the skin is loaded, due to the value of the MyVar variable), sets the Wallpaper - active.png image as wallpaper and this is changing only if you click the button.
It's extremely simple to set the other wallpaper "by default" (so when Rainmeter starts up). The only thing you have to do is change the initial value of the MyVar variable into the [Variables] section to MyVar=1.
The above solution works only if you shutdown the computer all the time. If you for instance hibernate it, when you resume it, it starts with the wallpaper set when you hibernated it, it doesn't switch. It can be done to switch in this case as well, please let me know if it's your case, to post a solution (if needed).
Mino_el_Nukenin
Posts: 181
Joined: April 24th, 2020, 7:39 pm
Location: France

Re: Help: Switching wallpapers with a button

Post by Mino_el_Nukenin »

Thanks again for your help.

After going around different ideas, I think I'll go back to a [!ToggleFadeGroup] command since the 2 wallpapers are the same, with the "active" one just showing up a logo.
So I'll just create a skin with a [MeterImage] of the logo with a transparent background and put in a specific Group in the [Rainmeter[ section and have the button toggle this group.
I'll keep your codes, in case I change my mind again.
User avatar
balala
Rainmeter Sage
Posts: 10605
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help: Switching wallpapers with a button

Post by balala »

Mino_el_Nukenin wrote:
April 25th, 2020, 7:27 pm
So I'll just create a skin with a [MeterImage] of the logo with a transparent background and put in a specific Group in the [Rainmeter[ section and have the button toggle this group.
I think it's not needed to create a new skin. You can add an Image meter to the current code and just show / hide that Image meter when needed. Much simpler, I suppose.
Please let me know if you wanna follow this and need help.
Mino_el_Nukenin
Posts: 181
Joined: April 24th, 2020, 7:39 pm
Location: France

Re: Help: Switching wallpapers with a button

Post by Mino_el_Nukenin »

Oh I see, so it would be adding a [!ToggleMeter] in my ButtonCommand, the meter being the image I want to display or hide with button ?
I think I'm beginning to understand the basics with meters and bangs.

Anyway I've already created the skin for the [MeterImage] with another skin having the same Group, and the button toggle them. It's working fine.
Thanks very much for your help !
User avatar
balala
Rainmeter Sage
Posts: 10605
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help: Switching wallpapers with a button

Post by balala »

Mino_el_Nukenin wrote:
April 25th, 2020, 8:45 pm
Oh I see, so it would be adding a [!ToggleMeter] in my ButtonCommand, the meter being the image I want to display or hide with button ?
Exactly, this was the idea.
Mino_el_Nukenin wrote:
April 25th, 2020, 8:45 pm
I think I'm beginning to understand the basics with meters and bangs.
The essence of this forum. I'm glad!
Mino_el_Nukenin wrote:
April 25th, 2020, 8:45 pm
Anyway I've already created the skin for the [MeterImage] with another skin having the same Group, and the button toggle them. It's working fine.
Thanks very much for your help !
Oh, alright, then use it so. Good work.