It is currently March 29th, 2024, 12:35 pm

GetW() in Initialize

Discuss the use of Lua in Script measures.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

GetW() in Initialize

Post by AlC »

Hey Guys

I done a simple lua script (I call it AutoWidth) that calculate the gap between my lanchers(strings), so that all launchers+gap have 990. Like this:
App1 (AppGap) App2 (AppGap) App3 (AppGap) App4 ....
And Because I don't change my launchers so often, I want that the script only load at the refreshing.

First one (which don't work)

Code: Select all

PROPERTIES =
{

}

function Initialize()

	mtApp1 = SKIN:GetMeter("App1")
	mtApp2 = SKIN:GetMeter("App2")
	mtApp3 = SKIN:GetMeter("App3")
	mtApp4 = SKIN:GetMeter("App4")
	mtApp5 = SKIN:GetMeter("App5")
	mtApp6 = SKIN:GetMeter("App6")
	mtApp7 = SKIN:GetMeter("App7")
	mtApp8 = SKIN:GetMeter("App8")
	
	
	App1Width = mtApp1:GetW()
	App2Width = mtApp2:GetW()
	App3Width = mtApp3:GetW()
	App4Width = mtApp4:GetW()
	App5Width = mtApp5:GetW()
	App6Width = mtApp6:GetW()
	App7Width = mtApp7:GetW()
	App8Width = mtApp8:GetW()
	print(App1Width)
	print(App2Width)
	print(App3Width)
	print(App4Width)
	print(App5Width)
	print(App6Width)
	print(App7Width)
	print(App8Width)
	
		
	AppGapLua = ( 990 - (App1Width + App2Width + App3Width + App4Width + App5Width + App6Width + App7Width + App8Width ) ) / 7
		
	print(AppGapLua)
	
		
	return AppGapLua
	
	end

function Update()
	
end

Second one (which works but I have to add updatedivider and must update the measure at the OnRefreshAction action)

Code: Select all

PROPERTIES =
{

}

function Initialize()

	mtApp1 = SKIN:GetMeter("App1")
	mtApp2 = SKIN:GetMeter("App2")
	mtApp3 = SKIN:GetMeter("App3")
	mtApp4 = SKIN:GetMeter("App4")
	mtApp5 = SKIN:GetMeter("App5")
	mtApp6 = SKIN:GetMeter("App6")
	mtApp7 = SKIN:GetMeter("App7")
	mtApp8 = SKIN:GetMeter("App8")
	
	
	end

function Update()
	
	App1Width = mtApp1:GetW()
	App2Width = mtApp2:GetW()
	App3Width = mtApp3:GetW()
	App4Width = mtApp4:GetW()
	App5Width = mtApp5:GetW()
	App6Width = mtApp6:GetW()
	App7Width = mtApp7:GetW()
	App8Width = mtApp8:GetW()
	print(App1Width)
	print(App2Width)
	print(App3Width)
	print(App4Width)
	print(App5Width)
	print(App6Width)
	print(App7Width)
	print(App8Width)
	
		
	AppGapLua = ( 990 - (App1Width + App2Width + App3Width + App4Width + App5Width + App6Width + App7Width + App8Width ) ) / 7
		
	print(AppGapLua)
	
		
	return AppGapLua
	
	
end

here my skin

Code: Select all

[Rainmeter]
Name=El.Alc
Config=Programme.ini
Update=1000
OnRefreshAction=!Execute [!RainmeterHide El.Alc\Programme][!UpdateMeasure AutoWidth][!UpdateMeasure AutoWidthCalc][!Redraw]
Author=AlC

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

;Metadata added by RainBrowser
;http://rainmeter.net/cms/Rainmeter101-EditingSkins

[Metadata]
Name=
Config=
Description=
Instructions=
Version=
Tags=
License=
Variant=
Preview=

;End of added Metadata

[Style]
@Include=#SKINSPATH#\El.Alc\Resources\Variables.inc

[Variables]
@Include=#SKINSPATH#\El.Alc\Resources\Variables.inc

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[BackgroundPrograms]
Meter=IMAGE
ImageName=#SKINSPATH#\El.Alc\Resources\Top2.png
AntiAlias=1

[App1]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp1#
X=20
Y=#YPrograms#
Text="#TextApp1#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp1 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp1 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App1" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App1#"]
DynamicVariables=1

[App2]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp2#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp2#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp2 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp2 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App2" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App2#"]
DynamicVariables=1

[App3]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp3#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp3#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp3 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp3 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App3" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App3#"]
DynamicVariables=1

[App4]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp4#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp4#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp4 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp4 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App4" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App4#"]
DynamicVariables=1

[App5]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp5#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp5#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp5 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp5 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App5" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App5#"]
DynamicVariables=1

[App6]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp6#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp6#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp6 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp6 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App6" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App6#"]
DynamicVariables=1

[App7]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp7#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp7#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp7 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp7 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App7" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App7#"]
DynamicVariables=1

[App8]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp8#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp8#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp8 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp8 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App8" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App8#"]
DynamicVariables=1

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[AutoWidth]
Measure=Script
ScriptFile=#CurrentPath#AutoWidth.lua

[AutoWidthCalc]
Measure=Calc
Formula=AutoWidth
So in my case i get for the first script 140 (which is false) and for the print (App...Width) only 1
In the second script I get 78 which is correct.

And I notice this in my About box, when i refersh the second script. So I think is the script too "fast" and get 1 and get 35,36,54... for the second update ??
NOTICE: (01:14:11.093) Refreshing skin "El.Alc\Programme\Programme.ini"
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 1
NOTICE: (01:14:11.093) 140.28571428571
NOTICE: (01:14:11.093) 36
NOTICE: (01:14:11.093) 35
NOTICE: (01:14:11.093) 54
NOTICE: (01:14:11.093) 72
NOTICE: (01:14:11.093) 69
NOTICE: (01:14:11.093) 54
NOTICE: (01:14:11.093) 29
NOTICE: (01:14:11.109) 91
NOTICE: (01:14:11.109) 78.571428571429
NOTICE: (01:14:11.109) 36
NOTICE: (01:14:11.109) 35
NOTICE: (01:14:11.109) 54
NOTICE: (01:14:11.109) 72
NOTICE: (01:14:11.109) 69
NOTICE: (01:14:11.109) 54
NOTICE: (01:14:11.109) 29
NOTICE: (01:14:11.109) 91
NOTICE: (01:14:11.109) 78.571428571429
NOTICE: (01:14:11.109) Refreshing skin "El.Alc\CPU\CPU2\CPU2.ini"
NOTICE: (01:14:11.125) Refreshing skin "El.Alc\CPU\CPU3\CPU3.ini"
Question 1: So Why ??

Question 2 and 3 following :)

Hope you can help me
Rainmeter - You are only limited by your imagination and creativity.
User avatar
donutmtoazt
Posts: 50
Joined: July 10th, 2011, 9:15 am
Location: Fresno, CA

Re: GetW() in Initialize

Post by donutmtoazt »

I'm not entirely sure what's causing your problem, but I think I know a way to work around it.

At the end of initialize, delete your return function and post this in there:

Code: Select all

SKIN:Bang("!SetVariable "somevar" "'..AppGapLua..'"')
Then, in your .ini, delete your calc measure and change all of the X values that called on the measure to #somevar#.

That should hopefully do the trick.
Last edited by donutmtoazt on August 7th, 2011, 11:16 am, edited 1 time in total.
This is my keyboard. There are many like it, but this one is mine.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: GetW() in Initialize

Post by smurfier »

Does this work any differently?

Code: Select all

PROPERTIES = {}

function Initialize()
OldWidth=0
Meters = {}
for a=1,8 do
Meters[a]=SKIN:GetMeter("App"..a)
end
   
end

function Update()
Width = 0
for a=1,8 do
Width = Width + tonumber(Meters[a]:GetW())
end
   
if Width ~= OldWidth then AppGapLua = ( 990 - Width) / 7 end

OldWidth = Width
      
   return AppGapLua
   
end
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: GetW() in Initialize

Post by AlC »

also

@donutmtoazt

I tried that before with setvariable and with setoption and writekeyvalue, too. But again with no succes.

@smurfier

The result is the same as my second script in the first post.
I add to your script print(AppGapLua) again.
And I notice in your script this again, that the first update(Initialize) I get 140,... and in the second update 78
NOTICE: (03:58:20.906) Refreshing skin "El.Alc\Programme\Programme.ini"
NOTICE: (03:58:20.922) 140.28571428571
NOTICE: (03:58:20.922) 78.571428571429
NOTICE: (03:58:20.922) Refreshing skin "El.Alc\CPU\CPU2\CPU2.ini"
so the general problem is I think that the GetW() in Initialize are 1


I think I solve the problem so:

Code: Select all

[Rainmeter]
Name=El.Alc
Config=Programme.ini
Update=1000
OnRefreshAction=!Execute [!RainmeterHide El.Alc\Programme][!UpdateMeasure AutoWidth][!UpdateMeasure AutoWidthCalc][!Redraw]
Author=AlC


[App1]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp1#
X=20
Y=#YPrograms#
Text="#TextApp1#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp1 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp1 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App1" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App1#"]
DynamicVariables=1

[App2]
Meter=STRING
MeterStyle=Style
FontColor=#ColorApp2#
X=[AutoWidthCalc]R
Y=r
Text="#TextApp2#"
MouseOverAction=!Execute [!RainmeterSetVariable ColorApp2 #ColorAppActive#][!RainmeterUpdate]
MouseLeaveAction=!Execute [!RainmeterSetVariable ColorApp2 #ColorAppNormal#][!RainmeterUpdate]
RightMouseDoubleClickAction=!Execute ["#ADDONSPATH#RainFile\RainFile.exe" "File" "Variables" "App2" "#SKINSPATH#\El.Alc\Resources\Variables.inc" "#Programfolder#"]
LeftMouseDownAction=!Execute ["#App2#"]
DynamicVariables=1

[AutoWidth]
Measure=Script
ScriptFile=#CurrentPath#AutoWidth.lua
UpdateDivider=600000

[AutoWidthCalc]
Measure=Calc
Formula=AutoWidth
UpdateDivider=600000
With
OnRefreshAction=!Execute [!RainmeterHide El.Alc\Programme][!UpdateMeasure AutoWidth][!UpdateMeasure AutoWidthCalc][!Redraw]

[AutoWidth]
Measure=Script
ScriptFile=#CurrentPath#AutoWidth.lua
UpdateDivider=600000

[AutoWidthCalc]
Measure=Calc
Formula=AutoWidth
UpdateDivider=600000

PS: I get the PM and try it now
Rainmeter - You are only limited by your imagination and creativity.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: GetW() in Initialize

Post by jsmorley »

Just as an aside, there is another clever way of having a Lua script run on demand, rather than using disabled/enabled or setting UpdateDivider=-1. Poiru and I were talking about this the other day, and he came up with this, which I think is worth having in your toolbelt if needed.

In the script:

Code: Select all

function Initialize()

	RunMe = false

end -- function Initialize

function Update()

	if RunMe then
	
		-- put your actual code here
		
		RunMe = false
		
	end

	return "I just ran!"
	
end -- function Update
In the skin:

Code: Select all

FinishAction=!CommandMeasure "LuaMeasure" "RunMe = true"
or

Code: Select all

OnRefreshAction=!CommandMeasure "LuaMeasure" "RunMe = true"
or

Code: Select all

LeftMouseUpAction=!CommandMeasure "LuaMeasure" "RunMe = true"
Or any other way you want to execute the script "on demand".

This has advantages over enabled/disabled on the script measure as disabled measures return zero as a numeric value, which you may not want "between runs". It has advantages over UpdateDivider=-1, as that setting will still run the measure one time when the skin is refreshed, and this also may not be what you want. All the methods have their place however, this is just one more.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: GetW() in Initialize

Post by AlC »

Okey thanks for this jsmorley I will take a look on this and on poiru's way.

Question 2 and 3 following :)
So one Question I have yet

It's because of the converting of the LuaMeasure to CalcMeasure

[AutoWidth]
Measure=Script
ScriptFile=#CurrentPath#AutoWidth.lua

[AutoWidthCalc]
Measure=Calc
Formula=AutoWidth

Because when I have X=[AutoWidthCalc]R it works fine
but when I have X=[AutoWidth]R the COMPLETE skin with all strings and the backgroundimage move to left, ca. the value of [AutoWidth]

I don't know, because [AutoWidth] is normally a number
And I have no idea why the whole skin move to the left

I just wanted know that
Rainmeter - You are only limited by your imagination and creativity.