It is currently September 17th, 2021, 12:39 pm

Lua and !SetOption

Discuss the use of Lua in Script measures.
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Lua and !SetOption

Post by smurfier »

I can't quite get !SetOption to work. I'm trying to use it in lua:

Code: Select all

SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "#Txt.Clr#"')
When I use print(), the string looks correct.

A note about the skin, FontColor is originally being retrieved from a MeterStyle.
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
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

smurfier wrote:I can't quite get !SetOption to work. I'm trying to use it in lua:

Code: Select all

SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "#Txt.Clr#"')
When I use print(), the string looks correct.

A note about the skin, FontColor is originally being retrieved from a MeterStyle.
So you have something like:

[Variables]
Txt.Clr=255,255,25,255

[Style]
FontColor=#Txt.Clr#

[MeterOne]
Meter=String
MeterStyle=Style


Right?
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

Pretty much.

Code: Select all

[Variables]
Txt.Clr=255,255,25,255

[TextStyle]
FontColor=#Txt.Clr#

[mDay1]
Meter=String
MeterStyle=TextStyle
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
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

So what are you trying to do from Lua? I don't see in this case that sending that bang changes anything. You start with 255,255,25,255 and end up with 255,255,25,255.

I'm missing something.
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

I'm changing the days that are not in the current month to different colors on my Lua Calendar.

INI

Code: Select all

[Rainmeter]
Author=smurfier & hatbocs@gmail.com
AppVersion=1001000
Update=1000
BackgroundMode=2
SolidColor=0,0,0,1

[Variables]
@include=Settings\CalendarSettings.inc
Week=0
ThisWeek=0

;Meter Styles =========================================
[TextStyle]
H=#C.h#
W=#C.w#
X=#Space.X#R
Y=r
FontColor=#Txt.Clr#
FontFace=#Txt.Fnt#
FontSize=#Txt.Sz#
stringAlign=center
AntiAlias=1

[NewWk]
Y=#Space.y#R
X=(#Bumper.x#+#C.w#/2)

[LauTry]
Measure=Script
ScriptFile=Calendar.lua

[TodayHL]
Meter=image
X=(#Bumper.x#+(#C.w#+#Space.x#)*#Week#+3)
Y=(#Bumper.y#+(#C.h#+#Space.y#)*#ThisWeek#+#C.h#-2)
H=2
W=(#C.w#-6)
SolidColor=#Clr.Hrl#
DynamicVariables=1
;Day Label BG===============================================
[LblBgSty]
X=#Space.X#R
Y=r
H=#C.h#
W=#C.W#
SolidColor=#Clr.LblBg#

[lSunBG]
Meter=image
MeterStyle=LblBgSty
X=#Bumper.x#
Y=#Bumper.y#

[lMonBG]
Meter=image
MeterStyle=LblBgSty

[lTuesBG]
Meter=image
MeterStyle=LblBgSty

[lWedBG]
Meter=image
MeterStyle=LblBgSty

[lThurBG]
Meter=image
MeterStyle=LblBgSty

[lFriBG]
Meter=image
MeterStyle=LblBgSty

[lSatBG]
Meter=image
MeterStyle=LblBgSty

;Day Labels-------------------------------------------------
[LblTxtSty]
H=#C.h#
W=#C.w#
X=#Space.X#R
Y=r
FontFace=Trebuchet MS
FontColor=#Clr.Lbl#
FontSize=#Sz.Lbl#
stringAlign=center
AntiAlias=1

[lSun]
Meter=string
MeterStyle=LblTxtSty
Text=S
X=(#Bumper.x#+#C.w#/2)
Y=(#Bumper.y#+2)

[lMon]
Meter=string
MeterStyle=LblTxtSty
Text=M

[lTues]
Meter=string
MeterStyle=LblTxtSty
Text=T

[lWed]
Meter=string
MeterStyle=LblTxtSty
Text=W

[lThur]
Meter=string
MeterStyle=LblTxtSty
Text=T

[lFri]
Meter=string
MeterStyle=LblTxtSty
Text=F

[lSat]
Meter=string
MeterStyle=LblTxtSty
Text=S

;Week 1 Begin----------------------------------------------
[mDay1]
Meter=string
MeterStyle=TextStyle | NewWk
Y=(#Space.y#/2)R

[mDay2]
Meter=string
MeterStyle=TextStyle

[mDay3]
Meter=string
MeterStyle=TextStyle

[mDay4]
Meter=string
MeterStyle=TextStyle

[mDay5]
Meter=string
MeterStyle=TextStyle

[mDay6]
Meter=string
MeterStyle=TextStyle

[mDay7]
Meter=string
MeterStyle=TextStyle

;Week 2 Begin----------------------------------------------
[mDay8]
Meter=string
MeterStyle=TextStyle | NewWk

[mDay9]
Meter=string
MeterStyle=TextStyle

[mDay10]
Meter=string
MeterStyle=TextStyle

[mDay11]
Meter=string
MeterStyle=TextStyle

[mDay12]
Meter=string
MeterStyle=TextStyle

[mDay13]
Meter=string
MeterStyle=TextStyle

[mDay14]
Meter=string
MeterStyle=TextStyle

;Week 3 Begin----------------------------------------------
[mDay15]
Meter=string
MeterStyle=TextStyle | NewWk

[mDay16]
Meter=string
MeterStyle=TextStyle

[mDay17]
Meter=string
MeterStyle=TextStyle

[mDay18]
Meter=string
MeterStyle=TextStyle

[mDay19]
Meter=string
MeterStyle=TextStyle

[mDay20]
Meter=string
MeterStyle=TextStyle

[mDay21]
Meter=string
MeterStyle=TextStyle

;Week 4 Begin----------------------------------------------
[mDay22]
Meter=string
MeterStyle=TextStyle | NewWk

[mDay23]
Meter=string
MeterStyle=TextStyle

[mDay24]
Meter=string
MeterStyle=TextStyle

[mDay25]
Meter=string
MeterStyle=TextStyle

[mDay26]
Meter=string
MeterStyle=TextStyle

[mDay27]
Meter=string
MeterStyle=TextStyle

[mDay28]
Meter=string
MeterStyle=TextStyle

;Week 5 Begin----------------------------------------------
[mDay29]
Meter=string
MeterStyle=TextStyle | NewWk

[mDay30]
Meter=string
MeterStyle=TextStyle

[mDay31]
Meter=string
MeterStyle=TextStyle

[mDay32]
Meter=string
MeterStyle=TextStyle

[mDay33]
Meter=string
MeterStyle=TextStyle

[mDay34]
Meter=string
MeterStyle=TextStyle

[mDay35]
Meter=string
MeterStyle=TextStyle

;Week 6 Begin----------------------------------------------
[mDay36]
Meter=string
MeterStyle=TextStyle | NewWk

[mDay37]
Meter=string
MeterStyle=TextStyle

[mDay38]
Meter=string
MeterStyle=TextStyle

[mDay39]
Meter=string
MeterStyle=TextStyle

[mDay40]
Meter=string
MeterStyle=TextStyle

[mDay41]
Meter=string
MeterStyle=TextStyle

[mDay42]
Meter=string
MeterStyle=TextStyle
CalendarSettings.inc

Code: Select all

[Variables]
;Date indicator options
;Set to 0 for no day indicator, 1 for horizontal line, 2 for highlighted text, 3 for both
Ind=0
;Highligted text color
Clr.Hlg=255,255,255,255
;Horizontal line color
Clr.Hrl=128,192,255,160
;Horizontal line height
H.Hrl=2
;Horizontal date indicator, 0 for off, 1 for current week only, 2 for weekday only, 3 for both
Ind2=0
;Week indicator colors codes
W.Clr=255,255,255,20
WClr.Red=255
WClr.Grn=255
WClr.Blu=255
WClr.Alp=20
;Day of week indicator color codes
DClr.Red=255
DClr.Grn=255
DClr.Blu=255
DClr.Alp=20
;Day box display- 0 for off, 1 for forced transparency, 2 for solid color
;When set to off, while both date indicators are on, the color values are averaged to appear overlapped.
Ind3=2
Clr.Box=255,255,255,20
;Day Indicator Image - Delete everything after the = to remove.
Box.Img=Images\Indic.png
;Day Idicator Image offsets. Use when the image is larger than the cell height and width.
Box.OffsetY=4
Box.OffsetX=4

;General text formatting
;AutoScale text size to cell dimensions (including month & day labels)- 0 for off, 1 for on
Sz.Aut=1
;Size for regular text
Txt.Sz=10
;Color for regular text
Txt.Clr=255,255,255,160
;Font for regular text
Txt.Fnt=Trebuchet MS
;Color for days in previous month
Clr.Prv=128,192,255,160
;Color for days in following month
Clr.Aft=128,192,255,160
;Month label font
;Mnt.Fnt=Trebuchet MS
Mnt.Fnt=Lucida Handwriting
;Month label color
Mnt.Clr=255,255,255,160
;Event / Holiday effect color
Ent.Clr=170,170,170,100

;Month and Year Label Options
;Settings for the Month & Year label- 0 for off, 1 for left align, 2 for centered, 3 for right align
;Add 4 to the setting to make the Label vertical (ex. 4+1=5 verical and aligned to the bottom)
Month.Lbl=2
;Display the year in the label- 0 for off, 1 for four digit year, 2 for two digit year
S.Year=1
;Month label text
Mnt.Jan=January
Mnt.Feb=February
Mnt.Mar=March
Mnt.Apr=April
Mnt.May=May
Mnt.Jun=June
Mnt.Jul=July
Mnt.Aug=August
Mnt.Sep=September
Mnt.Oct=October
Mnt.Nov=November
Mnt.Dec=December
;Label height
Mnt.H=18
;Label Font Size
Lbl.Fnt=10
;Label background- 0 off, 1 for on
Month.bg=0
Month.color=255,255,255,10

;Day Label Settings
;Day Label background- 0 for off, 1 for squares, 2 for solid
S.Label=1
;Color for Day label backgrounds
Clr.LblBg=255, 255, 255, 25
;Size for Weekday labels
Sz.Lbl=8
;Color for Weekday labels
Clr.Lbl=255,255,255,150
;Day Label text
Lbl.Sun=S
Lbl.Mon=M
Lbl.Tue=T
Lbl.Wed=W
Lbl.Thu=T
Lbl.Fri=F
Lbl.Sat=S
;Highlight current day label- 0 for off, 1 for on
Lbl.Hlg=1
Clr.LHlg=255,255,255,255

;General options
;Show or hide days from the previous and following month.
;0 for off, 1 for previous month only, 2 for following month only, 3 for both.
E.Days=3
;With these options- 0 to disable, 1 to enable
;Enable or Disable the last week when it is not part of the current month.
Last.Wk=1
;Enable or Disable leading zeros for days less than 10.
Lead.Zero=0
;Enable or Disable week view.
;Sets inital view when using toggle button, or mouseover toggle
Wk.View=0
;Enable or Disable Week view toggle button.
Wk.Btt=0
;Enable or Disable Week View delayed toggle on mouseover
Wk.Tog=0
;Enable or Disable buttons to move the month. Only available in month view.
S.Adv=1
;Enable or disable top and bottom borders
Border.Top=0
Border.Bottom=0

;Background Options
;Background Image Name - Delete everything after the = to remove.
Bg.Img=Images\Back.png
;Background Box- 0 for none, 1 for solid color, 2 to stretch it under the labels
Bg.Opt=0
Bg.color=255,255,255,10
;Include the bumpers- 0 for off, 1 for on
;This option includes the vertical Day of week indicator
Bg.Str=1

;Positioning options
;Cell Dimensions
C.w=16
C.h=16
;Spacers and bumper
;Vertical space between cells
Space.x=11
;Space on left and right of calendar
Bumper.x=10
;Horizontal space between cells
Space.y=4
;Space on top of calendar
;Bumper.y=13
Bumper.y=3
;Space on bottom of calendar
Bumper.bottom=0
;Space between Month Label and Day Labels
MLbl.Space=5
;Space between Day Labels and Week1
Lbl.Space=5
Calendar.lua

Code: Select all

PROPERTIES =
{

}

function Initialize()
	Meters = {}
	for a=1,42 do
		Meters[a]=SKIN:GetMeter("mDay"..a)
	end
	OldDay=0
end -- function Initialize

function Update()
	Today= os.date("%d")
	Today= tonumber(Today)
	if Today~=OldDay then
		Year= os.date("%Y")
		Feb = 28+((Year%4)==0 and 1 or 0)
		CurrMonth = {31;Feb;31;30;31;30;31;31;30;31;30;31;}
		PrevMonth = {31;31;Feb;31;30;31;30;31;31;30;31;30;}
		Month= os.date("%m")
		Month = tonumber(Month)
		WeekDay = os.date("%w")
		WeekDay = tonumber(WeekDay)
		when = os.time({year=Year, month=Month, day=1})
		StartDay = os.date("%w", when)
		for a=1,42  do
			b = a - StartDay

--			print('!SetOption "mDay'..a..'" "FontColor" "#Txt.Clr#"')
			if b<1 then
			b = b+PrevMonth[Month]
--			SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "#Txt.Prv#"')
			elseif b>CurrMonth[Month] then
			b = b-CurrMonth[Month]
--			SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "#Txt.Aft#"')
			else
--			SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "#Txt.Clr#"')
			end
			Meters[a]:SetText(b)
		end
		ThisWeek = math.ceil((Today+StartDay)/7)
		SKIN:Bang("!SetVariable ThisWeek "..ThisWeek)
		SKIN:Bang("!SetVariable Week "..WeekDay)
	end
	OldDay=Today
return "Success"
end -- function Update
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
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

Does that mess that uses variable names as if they were $20 per character so it is unreadable answer my question though? :-)

Your original example only set the FontColor from 255,255,25,255 to 255,255,25,255. Are you sure there isn't just some logic flaw here, or am I missing something?

If you can create a simple example that doesn't work, it would be easier to debug.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Lua and !SetOption

Post by Kaelri »

Yeah, I don't get it. In the INI, you have

Code: Select all

[TextStyle]
...
FontColor=#Txt.Clr#
and

Code: Select all

[mDay1]
...
MeterStyle=TextStyle | NewWk
So as I understand it, mDay1's font color should be #Txt.Clr# to start with. What is the !SetOption supposed to do?
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

Alright..

When I put MouseOverAction=!SetOption "mDay1" "FontColor" "255,0,0,255" under Rainmeter, the Meter mDay1 disappears when I mouse-over the skin.

Ugh!
It's used to set the color to normal if that meter is part of the current month, and set it some other color when it's not part of the month.

Here is the snippet of the script that sets all of the meter values including testing if it's part of the month or not:

Code: Select all

		for a=1,42  do
			b = a - StartDay
			if b<1 then
			b = b+PrevMonth[Month]
			SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "128,192,255,160"')
			elseif b>CurrMonth[Month] then
			b = b-CurrMonth[Month]
			SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "128,192,255,160"')
			else
			SKIN:Bang('!SetOption "mDay'..a..'" "FontColor" "255,255,255,160"')
			end
			Meters[a]:SetText(b)
		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
jsmorley
Developer
Posts: 22270
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua and !SetOption

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=100
DynamicWindowSize=1
MouseOverAction=!SetOption MeterOne FontColor 255,255,255,255

[Variables]
Txt.Clr=255,255,25,255

[Style]
FontColor=#Txt.Clr#

[MeterOne]
Meter=String
MeterStyle=Style
FontSize=15
Text=Hello
Not sure. Works fine for me. Starts out yellow and changes to white on MouseOver.
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua and !SetOption

Post by smurfier »

I have no idea. Restarting my computer didn't change anything.
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 . . .