It is currently September 16th, 2024, 7:46 pm

HotKey plugin 1.0

Plugins and Addons popular with the Community
User avatar
Hazrd
Posts: 23
Joined: August 26th, 2024, 7:59 am
Location: Malaysia

Re: HotKey plugin 1.0

Post by Hazrd »

Yincognito wrote: September 1st, 2024, 6:03 pm A minor clarification to an otherwise excellent answer: measures do support group bangs (actually, more group bangs than meters do), just not a hypothetical !CommandMeasureGroup bang.
I've read through the entire bang documentation multiple times and cant figure out an efficiet way to start/stop multiple measures. Could you perhaps elaborate/provide examples on this?
User avatar
balala
Rainmeter Sage
Posts: 16549
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: HotKey plugin 1.0

Post by balala »

Hazrd wrote: September 3rd, 2024, 1:23 pm I've read through the entire bang documentation multiple times and cant figure out an efficiet way to start/stop multiple measures. Could you perhaps elaborate/provide examples on this?
No, as previously has been said, there is no such way. !CommandMeasure has no variant to be used for groups, because it can't have. There are lot of ways in which you can use this bang, with lot of parameters, so there can't be implemented a grouping !ComandMeasure. So no, unfortunately you have to add each measure one by one. Sorry...
User avatar
Hazrd
Posts: 23
Joined: August 26th, 2024, 7:59 am
Location: Malaysia

Re: HotKey plugin 1.0

Post by Hazrd »

balala wrote: September 3rd, 2024, 4:51 pm So no, unfortunately you have to add each measure one by one. Sorry...
Well, I was just making sure there wasn't a Rainmeter solution I could use. There's nothing a little Lua script cant fix! Thanks anyway ;-)

Edit: I'm just gonna add in my script for anyone who needs it! :D

Code: Select all

-- [[

(feel free to remove this!)

FUNCTION PARAMS
measures: A comma delimited list of all measures
cmd: the command to execute on said measures

]]

function CommandMeasureGroup(measures, cmd)

   for measure in string.gmatch(measures, '([^,]+)') do
      
      local curMeasure = SKIN:GetMeasure(measure)

      if curMeasure then
         SKIN:Bang('!CommandMeasure', measure, cmd)
      else
         SKIN:Bang('!Log', "The measure '" ..  measure .. "' could not be found!")
      end

   end

end
User avatar
Yincognito
Rainmeter Sage
Posts: 8153
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: HotKey plugin 1.0

Post by Yincognito »

Hazrd wrote: September 4th, 2024, 5:32 am Well, I was just making sure there wasn't a Rainmeter solution I could use. There's nothing a little Lua script cant fix! Thanks anyway ;-)

Edit: I'm just gonna add in my script for anyone who needs it! :D

Code: Select all

-- [[

(feel free to remove this!)

FUNCTION PARAMS
measures: A comma delimited list of all measures
cmd: the command to execute on said measures

]]

function CommandMeasureGroup(measures, cmd)

   for measure in string.gmatch(measures, '([^,]+)') do
      
      local curMeasure = SKIN:GetMeasure(measure)

      if curMeasure then
         SKIN:Bang('!CommandMeasure', measure, cmd)
      else
         SKIN:Bang('!Log', "The measure '" ..  measure .. "' could not be found!")
      end

   end

end
Nice work! :thumbup:

That being said, I was thinking of adding a similar script as a workaround, but you end up doing pretty much the same thing here: enumerate all relevant measures (in this case, as the 1st parameter of the function). Not sure how is that different from basically doing the same in the plain Rainmeter's individual !CommandMeasure bangs (the only difference is that in this script, you only have to pass the 2nd !CommandMeasure parameter once).

Would be nice if Lua had a SKIN.GetMeasureNames() function to retrieve the names of all measures in a skin as a table, instead of having to parse the (properly encoded or not) .ini of the skin. Then, you could use SKIN:GetMeasure(measure):GetOption('Group') to do your thing on an entire group.

P.S. For the record, what the script does could also be done by a String measure substituting the measure enumeration with the proper bangs, followed by "executing" that measure value anywhere in the code.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Hazrd
Posts: 23
Joined: August 26th, 2024, 7:59 am
Location: Malaysia

Re: HotKey plugin 1.0

Post by Hazrd »

Yincognito wrote: September 4th, 2024, 7:49 am That being said, I was thinking of adding a similar script as a workaround, but you end up doing pretty much the same thing here: enumerate all relevant measures (in this case, as the 1st parameter of the function). Not sure how is that different from basically doing the same in the plain Rainmeter's individual !CommandMeasure bangs (the only difference is that in this script, you only have to pass the 2nd !CommandMeasure parameter once).
I figured simply listing the names of the measures in a single string would be far less cumbersome than repeating the same command measure over and over. I thought of a solution where all the measure sections had an index as a suffix, and the script would loop over them based on that index and a name (kinda like function(measureBaseName, cmd)), but that would make your skin a little unreadable, especially if you're using it for something like this Hotkey plugin. It'd become pretty confusing if each measure followed the same naming syntax like "Hotkey1, Hotkey2, Hotkey3, etc..." just for it to work with the script.
User avatar
Yincognito
Rainmeter Sage
Posts: 8153
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: HotKey plugin 1.0

Post by Yincognito »

Hazrd wrote: September 4th, 2024, 8:55 am I figured simply listing the names of the measures in a single string would be far less cumbersome than repeating the same command measure over and over. I thought of a solution where all the measure sections had an index as a suffix, and the script would loop over them based on that index and a name (kinda like function(measureBaseName, cmd)), but that would make your skin a little unreadable, especially if you're using it for something like this Hotkey plugin. It'd become pretty confusing if each measure followed the same naming syntax like "Hotkey1, Hotkey2, Hotkey3, etc..." just for it to work with the script.
Indeed. Here's a plain Rainmeter version of what your script does, just to illustrate what I meant (I used different KeyDownActions for testing purposes):

Code: Select all

[Variables]
Text=""
Command=""

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

---Measures---

[mCommandAll]
Measure=String
String=mA,mB,mC,
UpdateDivider=-1
RegExpSubstitute=1
Substitute="(.*?),":'[!CommandMeasure \1 "#Command#"]'
DynamicVariables=1

[mA]
Group=HotKeyGroup
Measure=Plugin
Plugin=HotKey
HotKey=a
KeyDownAction=[!SetVariable Text "#Text#a"][!UpdateMeasureGroup HotKeyGroup][!UpdateMeter *][!Redraw]
DynamicVariables=1

[mB]
Group=HotKeyGroup
Measure=Plugin
Plugin=HotKey
HotKey=b
KeyDownAction=[!SetVariable Text "#Text#b"][!UpdateMeasureGroup HotKeyGroup][!UpdateMeter *][!Redraw]
DynamicVariables=1

[mC]
Group=HotKeyGroup
Measure=Plugin
Plugin=HotKey
HotKey=c
KeyDownAction=[!SetVariable Text "#Text#c"][!UpdateMeasureGroup HotKeyGroup][!UpdateMeter *][!Redraw]
DynamicVariables=1

---Meters---

[Result]
Meter=String
SolidColor=0,255,0,255
Text="Result = #Text#"
LeftMouseUpAction=[!SetVariable Command "Toggle"][!UpdateMeasure mCommandAll][mCommandAll]
DynamicVariables=1
Basically, setting the Command variable as the "parameter", then updating and "executing" the [mCommandAll] string like in the LeftMouseUpAction is all it takes. The mCommandAll measure does what your script does (bar executing the bangs): it replaces the comma separated measure names with the desired bangs to be executed later on. Press a, b, or c to add them to the Text variable, left click to toggle the HotKey measures between started or stopped. Setting the Command variable and updating the mCommandAll measure are not needed if you hardcode the desired command in the Substitute, instead of using a variable for it.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16549
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: HotKey plugin 1.0

Post by balala »

Hazrd wrote: September 4th, 2024, 5:32 am Well, I was just making sure there wasn't a Rainmeter solution I could use. There's nothing a little Lua script cant fix!
Well, a lua solution seems viable, when I said there is no way to group the bangs I were speaking about a strictly Rainmeter solution, not about a lua-involved solution.
However in my opinion, doesn't worth to complicate things. Obviously we all are different, but me personally wouldn't add a lua script, just to avoid adding the bangs one by one. Obviously who wants, is free to use this technique, but in my opinion doesn't worth. Rainmeter strictly speaking is not a programming language, if it would be, such things could be done by Rainmeter code itself. So, if it is not, don't complicate things, when it is not mandatory.
My guess, at least...
Hazrd wrote: September 4th, 2024, 5:32 am

Code: Select all

-- [[

(feel free to remove this!)

FUNCTION PARAMS
measures: A comma delimited list of all measures
cmd: the command to execute on said measures

]]

function CommandMeasureGroup(measures, cmd)

   for measure in string.gmatch(measures, '([^,]+)') do
      
      local curMeasure = SKIN:GetMeasure(measure)

      if curMeasure then
         SKIN:Bang('!CommandMeasure', measure, cmd)
      else
         SKIN:Bang('!Log', "The measure '" ..  measure .. "' could not be found!")
      end

   end

end
The above code does work, however strictly speaking closing a comment is done in lua by --]], not by ]]. So add the missing characters in the 9th line of the above code (however as said, the code works well even with the double brackets, so finally this seems to be something optional).
User avatar
Yincognito
Rainmeter Sage
Posts: 8153
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: HotKey plugin 1.0

Post by Yincognito »

balala wrote: September 4th, 2024, 2:29 pmThe above code does work, however strictly speaking closing a comment is done in lua by --]], not by ]]. So add the missing characters in the 9th line of the above code (however as said, the code works well even with the double brackets, so finally this seems to be something optional).
Double square brackets are used for multiline literal strings in Lua, that's why they're present in the script, see the "Multiline quotes" section here:
http://lua-users.org/wiki/StringsTutorial
In the Lua manual, they're called "long brackets", since one can nest them:
https://www.lua.org/manual/5.1/manual.html#2.1
In other words, he just commented out a multiline string in the script, in order to avoid commenting out each and every line of that "help" string:
https://www.codecademy.com/resources/docs/lua/comments

EDIT: Realized that you were aware of the above - posted too soon, though both --]] and ]]-- are correct to above (the former comments just the ]] line, the latter closes the multiline comment). Sorry about that. :oops:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth