It is currently May 5th, 2024, 4:19 pm

Switching Icons on click, HELP!

Get help with creating, editing & fixing problems with skins
tadbitnerdy
Posts: 4
Joined: November 26th, 2012, 11:16 am

Switching Icons on click, HELP!

Post by tadbitnerdy »

Hello all,

I've used rainmeter for a few years, but I never really got into modifying or creating my own skins. I'm currently using the Omnimo 5 Skin. I'm working on creating a panel that, when I click it, change my sound playback device from Speakers, to USB, and so on. I already have this part working. What I'm trying to do now is get it to change the icon that is displayed, depending on which output device I'm using (USB, show headphones image; Speakers, show speaker image).

Here is some code:

Code: Select all

[MeasureGetIconText]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=file://C:/Users/tadzilla/Downloads/playbackdevice___audio_output_switch___by_heilnizar-d4q182i/PlaybackDevice/Res/Settings.ini
RegExp="(?siU)Device=(.)"
Group=IconGroup
ForceReload=1

[MeasureGetIcon]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureGetIconText]
StringIndex=1
Group=IconGroup
ForceReload=1

[icon]
Meter=Image
ImageName=[MeasureGetIcon]
X=(#height#/(150/21)+5)
Y=(#height#/(150/18)+5)
W=(#height#/(150/106))
H=(#height#/(150/106))
AntiAlias=1
Group=IconGroup

[Action]
Meter=Button
X=(#height#/(150/21)+5)
Y=(#height#/(150/18)+5)
W=(#height#/(150/106))
H=(#height#/(150/106))
LeftMouseUpAction=!Execute ["#Action#"][!UpdateMeasure "MeasureGetIconText"][!UpdateMeasure "MeasureGetIcon"][!UpdateMeter "icon"][!Redraw]
What I'm trying to do is pull in a file called 'Settings.ini'. This file is what updates everytime I run my EXE file to change the audio output. Every time the output device changes, the file updates. I use webparser to find the 'Device=' string. The number after this string is what tells me what device I'm using (1 or 2). This number also corresponds with the file name of the icon needed (1.png, 2.png). I was hoping that this would allow me change icons on LeftMouseUpAction, but it wasn't as easy as I thought it would be.

I know for a fact that the first part ([MeasureGetIconText]) is working (1 is stored in index 1).

Sorry for the long explanation. Any help would be appreciated.

Thanks!
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Switching Icons on click, HELP!

Post by MerlinTheRed »

When using measure names in square brackets, you must set DynamicVariables=1 on the measure or meter you are using it in. Otherwise the meter/measure will not be updated if the measure's value changes.

Also MeasureGetIcon is not necessary here. you can just set StringIndex=1 on MeasureGetIconText directly.

!Execute is not needed any more in the newest Rainmeter version, so I removed it.

This is how the code would look with all those modifications:

Code: Select all

[MeasureGetIconText]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=file://C:/Users/tadzilla/Downloads/playbackdevice___audio_output_switch___by_heilnizar-d4q182i/PlaybackDevice/Res/Settings.ini
RegExp="(?siU)Device=(.)"
StringIndex=1
Group=IconGroup
ForceReload=1

[icon]
Meter=Image
ImageName=[MeasureGetIconText]
X=(#height#/(150/21)+5)
Y=(#height#/(150/18)+5)
W=(#height#/(150/106))
H=(#height#/(150/106))
AntiAlias=1
Group=IconGroup
DynamicVariables=1

[Action]
Meter=Button
X=(#height#/(150/21)+5)
Y=(#height#/(150/18)+5)
W=(#height#/(150/106))
H=(#height#/(150/106))
LeftMouseUpAction=["#Action#"][!UpdateMeasure "MeasureGetIconText"][!UpdateMeasure "MeasureGetIcon"][!UpdateMeter "icon"][!Redraw]
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
tadbitnerdy
Posts: 4
Joined: November 26th, 2012, 11:16 am

Re: Switching Icons on click, HELP!

Post by tadbitnerdy »

Thanks for the quick answer! I'll try this out when I get home from work, and I'll let you know once it is working.

Thanks,
tadbitnerdy
Posts: 4
Joined: November 26th, 2012, 11:16 am

Re: Switching Icons on click, HELP!

Post by tadbitnerdy »

It works for the most part. However, the only way i can get the icon to change is if I manually refresh the skin. If I do a manual refresh, the icon goes blank. Then when I click on it, the icon is updated, but it get updated to the previous devices icon (so, if the device is USB, the icon will change to speaker, and so on). Again, this will only work after a manual refresh.

The button executes an EXE file, which updates the Settings.ini file after the device is changed. Do I need to add some kind of delay to the !updatemeasure bangs to allow the EXE time to run before the measures are updated? It doesn't seem like the !update bangs are actually doing anything.

Thanks again for the help.

-Tad
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Switching Icons on click, HELP!

Post by MerlinTheRed »

It may well be that your exe is not finished before the Update bang is executed. Rainmeter doesn't wait for external programs to finish before going on to the next bang. What you could do is set UpdateRate=1 on the WebParser measure. This will make it re-parse the ini file every update cycle. The default behavior of WebParser is updating every 600 update cycles, because you normally use it to get info from the web.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
tadbitnerdy
Posts: 4
Joined: November 26th, 2012, 11:16 am

Re: Switching Icons on click, HELP!

Post by tadbitnerdy »

Works perfectly now! I pretty much can't update the icon on execute, so I set up the skin to have Update=1000, and set everything else up to update. It works just fine now. Thanks!