It is currently November 21st, 2018, 3:00 pm

ConfigActive 2.1

Share your custom plugins and applications to enhance Rainmeter.
User avatar
raiguard
Posts: 478
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: ConfigActive 2.0

raiguard » June 22nd, 2018, 10:36 pm

jsmorley wrote:LeftMouseUpAction=[&MeasureScript:Test('LoadSkin\ToggledSkin')]

;-)

LoadSkin\ToggledSkin LoadSkin\\ToggledSkin LoadSkin\ToggledSkin

Inline Lua is intended to "return" some value to the section variable, but that doesn't mean you have to use the value it returns... It actually doesn't have to return anything at all.
:17what

That's an acceptable workaround. Hopefully the !CommandMeasure thing is a bug that is fixable. I have been dealing with that for over a year, and just assumed it was a consequence of LUA needing double backslashes. I never knew it was a bug!

Anyway, thanks. :D
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
jsmorley
Developer
Posts: 18350
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ConfigActive 2.0

jsmorley » June 22nd, 2018, 10:37 pm

raiguard wrote::17what

That's an acceptable workaround. Hopefully the !CommandMeasure thing is a bug that is fixable. I have been dealing with that for over a year, and just assumed it was a consequence of LUA needing double backslashes. I never knew it was a bug!

Anyway, thanks. :D
Unless I'm missing something, this means that Inline Lua can just "deprecate" using !CommandMeasure to fire Lua functions...

We will look at !CommandMeasure, but I fear that behavior might be baked into the DNA of Lua, and might be hard to fix without backwards compatibility issues, or having to hack core Lua code that puts at risk future Lua version updates. We will see.
User avatar
raiguard
Posts: 478
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: ConfigActive 2.0

raiguard » June 22nd, 2018, 10:40 pm

jsmorley wrote:Unless I'm missing something, this means that Inline Lua can just "deprecate" using !CommandMeasure to fire Lua functions...
Well, there are disadvantages. First off, you would need to use DynamicVariables on anything that needs to invoke LUA commands (which probably isn't too much of a deal, but it could have a slight performance impact). Secondly, it doesn't appear that Inline LUA can use table function arguments.

LeftMouseUpAction=[&MeasureScript:ToggleSkin{configName = '[#toggledSkinConfig]', configState = [&MeasureConfigActive:IsActive([#toggledSkinConfig])]}] throws an error. While when used in a !CommandMeasure it works fine.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
jsmorley
Developer
Posts: 18350
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ConfigActive 2.0

jsmorley » June 22nd, 2018, 10:43 pm

raiguard wrote:Well, there are disadvantages. First off, you would need to use DynamicVariables on anything that needs to invoke LUA commands (which probably isn't too much of a deal, but it could have a slight performance impact). Secondly, it doesn't appear that Inline LUA can use table function arguments.

LeftMouseUpAction=[&MeasureScript:ToggleSkin{configName = '[#toggledSkinConfig]', configState = [&MeasureConfigActive:IsActive([#toggledSkinConfig])]}] throws an error. While when used in a !CommandMeasure it works fine.
I'm not entirely sure you do need DynamicVariables if you are not in fact returning anything.

Yeah, you can't pass a direct call to a table with an index to it, you would have to pass some reference to the table name (if needed) and the index separately in the arguments, then use that to access the table.

The major difference is that you can just execute raw Lua code using !CommandMeasure, where Inline Lua can only execute a named function(), with any parameters you want. However, I could argue that that isn't fatal, you just need to define your functions carefully.

Edit: Yeah, you don't need DynamicVaraiables.
User avatar
raiguard
Posts: 478
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: ConfigActive 2.0

raiguard » June 22nd, 2018, 10:52 pm

jsmorley wrote:I'm not entirely sure you do need DynamicVariables if you are not in fact returning anything.
Ah, you're right.
jsmorley wrote:Yeah, you can't pass a direct call to a table with an index to it, you would have to pass some reference to the table name and the index separately in the arguments, then use that to access the table.
The point of this was to make arguments optional. I couldn't find an argument order that would allow me to make them optional without needing to manually input 'nil' for one or more of the other arguments if you don't want to use them. For example, if you want to toggle a specific variant, you would need to use ToggleSkin('[#toggledSkinConfig]', [&MeasureConfigActive:IsActive([#toggledSkinConfig])], nil, 'Variant1.ini', '[&MeasureConfigActive:ConfigVariantName([#toggledSkinConfig])]') if the function is function ToggleSkin(configName, configState, toState, skinIni, activeIni).

Anyway, that's unfortunate. It sounds really complicated if I still want to use a table when using Inline LUA, so I'll just scrap that and use nil.

Edit: Typing 'nil' as a function argument in Inline LUA appears to translate into a zero when the function gets the value. That's odd.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
raiguard
Posts: 478
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: ConfigActive 2.0

raiguard » June 22nd, 2018, 11:30 pm

Finished updating my sample skin and figured I would share it here. It works like a charm! I even managed to add a new feature while I was at it! Thanks for all your help.
LoadSkin.gif

Code: Select all

[Rainmeter]
MiddleMouseUpAction=[!Refresh]
AccurateText=1

[Variables]
toggledSkinConfig=LoadSkin\ToggledSkin
toggledSkinConfigActive=[&MeasureConfigActive:IsActive([#toggledSkinConfig])]
toggledSkinConfigActiveIni=[&MeasureConfigActive:ConfigVariantName([#toggledSkinConfig])]
variant1Ini=Variant1.ini
variant2Ini=Variant2.ini

[MeasureConfigActive]
Measure=Plugin
Plugin=ConfigActive
DynamicVariables=1

[MeasureScript]
Measure=Script
ScriptFile=#@#Scripts\LoadSkin.lua
ToggleOn=[\x5a]
ToggleOff=[\x56]
RadioOn=[\x5c]
RadioOff=[\x5b]
ToggleGroup=SkinToggles

[StyleLabelString]
FontFace=Roboto
FontColor=240,240,240
FontSize=10
AntiAlias=1
X=3R
Y=-1r

[StyleToggleButton]
FontFace=ElegantIcons
FontColor=138,210,250
FontSize=12
AntiAlias=1
X=5
Y=4R
Group=SkinToggles
DynamicVariables=1

[MeterBackground]
Meter=Shape
Shape=Rectangle 0,0,128,102 | Fill Color 15,15,15 | StrokeWidth 0

[MeterToggleConfigButton]
Meter=String
MeterStyle=StyleToggleButton
Y=5
Text=[&MeasureScript:GetIcon([#toggledSkinConfigActive])]
LeftMouseUpAction=[&MeasureScript:ToggleSkin('[#toggledSkinConfig]', [#toggledSkinConfigActive])]

[MeterToggleConfigLabel]
Meter=String
MeterStyle=StyleLabelString
Text=Toggle Config

[MeterLoadVariant1Button]
Meter=String
MeterStyle=StyleToggleButton
Text=[&MeasureScript:GetIcon([#toggledSkinConfigActive], '[#variant1Ini]', '[#toggledSkinConfigActiveIni]')]
LeftMouseUpAction=[&MeasureScript:ToggleSkin('[#toggledSkinConfig]', [#toggledSkinConfigActive], '[#variant1Ini]', '[#toggledSkinConfigActiveIni]', 1)]

[MeterLoadVariant1Label]
Meter=String
MeterStyle=StyleLabelString
Text=Load Variant 1

[MeterLoadVariant2Button]
Meter=String
MeterStyle=StyleToggleButton
Text=[&MeasureScript:GetIcon([#toggledSkinConfigActive], '[#variant2Ini]', '[#toggledSkinConfigActiveIni]')]
LeftMouseUpAction=[&MeasureScript:ToggleSkin('[#toggledSkinConfig]', [#toggledSkinConfigActive], '[#variant2Ini]', '[#toggledSkinConfigActiveIni]', 1)]

[MeterLoadVariant2Label]
Meter=String
MeterStyle=StyleLabelString
Text=Load Variant 2

[MeterToggleVariant1Button]
Meter=String
MeterStyle=StyleToggleButton
Text=[&MeasureScript:GetIcon([#toggledSkinConfigActive], '[#variant1Ini]', '[#toggledSkinConfigActiveIni]', true)]
LeftMouseUpAction=[&MeasureScript:ToggleSkin('[#toggledSkinConfig]', [#toggledSkinConfigActive], '[#variant1Ini]', '[#toggledSkinConfigActiveIni]')]

[MeterToggleVariant1Label]
Meter=String
MeterStyle=StyleLabelString
Text=Toggle Variant 1

[MeterToggleVariant2Button]
Meter=String
MeterStyle=StyleToggleButton
Text=[&MeasureScript:GetIcon([#toggledSkinConfigActive], '[#variant2Ini]', '[#toggledSkinConfigActiveIni]', true)]
LeftMouseUpAction=[&MeasureScript:ToggleSkin('[#toggledSkinConfig]', [#toggledSkinConfigActive], '[#variant2Ini]', '[#toggledSkinConfigActiveIni]')]

[MeterToggleVariant2Label]
Meter=String
MeterStyle=StyleLabelString
Text=Toggle Variant 2

Code: Select all

debug = false

function Initialize()

	toggleOn = SELF:GetOption('ToggleOn', '[#toggleOn]')
	toggleOff = SELF:GetOption('ToggleOff', '[#toggleOff]')
	radioOn = SELF:GetOption('RadioOn', toggleOn)
	radioOff = SELF:GetOption('RadioOff', toggleOff)
	toggleGroup = SELF:GetOption('ToggleGroup', 'SkinToggles')

end

function Update() end

-- Toggles the specified skin.
function ToggleSkin(configName, configState, skinIni, activeIni, toState)

	configName = configName:gsub('\\', '\\\\'):gsub('\\\\', '\\')
	toState = toState or skinIni and (skinIni == activeIni and -1 or 1) or configState * -1

	if toState == 1 then
		if skinIni == nil then
			SKIN:Bang('!ActivateConfig', configName)
		else
			SKIN:Bang('!ActivateConfig', configName, skinIni)
		end
	else
		SKIN:Bang('!DeactivateConfig', configName)
	end

	SKIN:Bang('!UpdateMeterGroup', toggleGroup)
	SKIN:Bang('!Redraw')
	return ''

end

function Test(input)

	local newInput = string.gsub(input, '\\', '\\\\')
	local oldInput = string.gsub(newInput, '\\\\', '\\')
	print(input, newInput, oldInput)
	return input .. '	' .. newInput .. '	' .. oldInput

end

-- Returns the corresponding button state depending on the state of the skin
function GetIcon(configState, skinIni, activeIni, radioOverride)

	if activeIni == nil then
		if configState == 1 then return toggleOn
		else return toggleOff end
	else
		if activeIni == skinIni then return radioOverride and toggleOn or radioOn
		else return radioOverride and toggleOff or radioOff end
	end

end

-- function to make logging messages less cluttered
function LogHelper(message, type)

  if type == nil then type = 'Debug' end

  if debug == true then
    SKIN:Bang("!Log", message, type)
  elseif type ~= 'Debug' then
  	SKIN:Bang("!Log", message, type)
	end

end
Edit: Oops, accidentally left the test function in there.
You do not have the required permissions to view the files attached to this post.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
jsmorley
Developer
Posts: 18350
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ConfigActive 2.0

jsmorley » June 23rd, 2018, 11:27 pm

Raiguard,

I have posted a 2.1 version of the plugin, that allows escaped "\", as in Illustro\\System to be sent to it and it will ignore the extra slash.
User avatar
raiguard
Posts: 478
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: ConfigActive 2.0

raiguard » June 24th, 2018, 3:15 pm

Ah sorry, I somehow didn't see this yesterday. I wouldn't have put it past you to fix that because using Inline LUA works well enough, but since you put forth the effort, I appreciate it! :thumbup:
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017