It is currently July 19th, 2019, 2:37 am

Lua for me.

Discuss the use of Lua in Script measures.
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 5:29 pm

balala wrote:Not certainly, because the [MeasureRun] measure (which has the above FinishAction option) isn't automatically executed on refresh of the skin. Or at least it shouldn't have to be. That's why I asked kyriakos876
If you see my Rainmeter section you will find that

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
OnUpdateAction=[!CommandMeasure MeasureRun "Run"]
So it does run when a refresh is applied. That's the point to.... It needs to do the first scan on itself, and then if something changes it needs to rewrite the everything. That's why it creates a loop, maybe you don't have the update action on your rainmeter section.... I'm sorry if the code I uploaded doesn't have that, my bad.
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 5:34 pm

raiguard wrote:So I have simplified my script immensely, here is the new code:

Code: Select all

identifierString = '%^1%^'
cTable = {}

function Initialize() end

function Update() end

function Split(allDisks)

  allDisks:gsub(".", function(c)
    table.insert(cTable, c)
    SKIN:Bang(string.format('!WriteKeyValue Variables "Underliner_Width_%s" "0" "#@#Variables.inc"',c))
  end)
  -- print(allDisks)
  Concat()
  SKIN:Bang('!Refresh')

end

function Concat()
  
  local rTable = {}
  local lines = {}
  for line in io.lines(SELF:GetOption('templateFilePath')) do
    table.insert(rTable, line)
  end
  for k,v in ipairs(cTable) do
    for l,line in pairs(rTable) do
      line = line:gsub(identifierString, v)
      table.insert(lines, line)
    end
  end

  outputFile = io.open(SELF:GetOption('outputFilePath'), 'w')
  outputFile:write(table.concat(lines, '\n'))
  outputFile:close()

end
Here is the template that the script is using:

Code: Select all

[MeasureTotalDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
Total=1
IgnoreRemovable=0
UpdateDivider=100

[MeasureUsedDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
InvertMeasure=1
IgnoreRemovable=0
UpdateDivider=100

[DiskAnimation^1^]
Measure=Plugin
Plugin=ActionTimer
ActionList1=UpdateOnce | Wait 16 | Repeat IconAnimationIn, 16, 16
UpdateOnce=[!Update]
IconAnimationIn=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#+25,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure ][!Redraw]
ActionList2=UpdateOnce | Wait 25 | Repeat IconAnimationOut, 16, 13
IconAnimationOut=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure ][!Redraw]
ActionList3=UpdateOnce | Wait 25 | Repeat MouseUp, 16, 6
MouseUp=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,130,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure ][!Redraw]

[MeterDisk^1^_Name]
Meter=String
MeterStyle=NormalLeft
X=#XFromTheWall#
Y=20r
DynamicVariables=1
UpdateDivider=-1

[MeterDisk^1^_Value]
Meter=String
MeasureName=MeasureUsedDisk^1^
MeasureName2=MeasureTotalDisk^1^
MeterStyle=NormalRight
X=(#MaxWidth#-#XFromTheWall#)
Y=r
Text=%1B/%2B
NumOfDecimals=1
AutoScale=1
UpdateDivider=100

[Background_Disk_^1^]
Meter=Shape
X=0
Y=([MeterDisk^1^_Name:Y]-[MeterDisk^1^_Name:W]/2)
Shape=Rectangle 0,0,#MaxWidth#,([MeterDisk^1^_Name:H]*1.75) | Fill Color 0,0,0,0 | StrokeWidth 0
LeftMouseUpAction=[^1^:]
DynamicVariables=1
UpdateDivider=-1

[Underliner_^1^]
Meter=Shape
X=(#MaxWidth#/2-0/2)
Y=-5R
Shape=Rectangle 0,0,#Underliner_Width_^1^#,1 | Fill Color 66,133,244 | StrokeWidth 0
DynamicVariables=1
UpdateDivider=-1

And here is the skin INI code I'm using:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
OnUpdateAction=[!CommandMeasure MeasureRun "Run"]
MouseScrollDownAction=[!Refresh]
BackgroundMode=2
Solidcolor=0,0,0
[Metadata]
Name=
Author=
Information=
Version=
License=Creative Commons Attribution - Non - Commercial - Share Alike 3.0

[Variables]
@Include=#@#Variables.inc
@Include2=#@#ScriptOutput.ini
AllDisks=CDE
StringLenght=0

[MeasureLua]
Measure=Script
ScriptFile=#@#Concat.lua
TemplateFilePath=#@#Template.ini
OutputFilePath=#@#ScriptOutput.ini
DynamicVariables=1

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic logicaldisk get caption
OutputType=ANSI
RegExpSubstitute=1
Substitute="Caption":""," ":"",":":"","Name.*#CRLF#":"","#CRLF#":"
DynamicVariables=1
FinishAction=[!EnableMeasure MeasureComparison][!UpdateMeasure MeasureComparison]

[MeasureComparison]
Measure=String
String=[MeasureRun]
IfMatch=^#AllDisks#$
IfNotMatchAction=[!WriteKeyValue Variables AllDisks "[MeasureRun]"][!DisableMeasure MeasureComparison][!CommandMeasure MeasureLua "Split('[MeasureRun]')"]
DynamicVariables=1
Disabled=1

[MeterDummy]
Meter=Image
SolidColor=10,10,10
W=20
H=20
You will see that I added a new measure, [MeasureComparison]. When [MeasureRun] finishes, it enables [MeasureComparison] which will compare the value of [MeasureRun] to the value of the #allDisks# variable. This way, the skin will automatically update when disks are added or removed, and automatically refresh, but avoids the aforementioned refresh loop:
RMAdaptiveDisks2.gif
You can see here that despite needing to write a file and refresh the skin, it is quite fast. Disks Meter is only there to demonstrate which disks are being added and removed.

I have also package an RMSKIN for you so you can check it out in its full glory. With this method, rather than having to worry about escaping variables and getting quotes to work in a !WriteKeyValue bang, all you need to do is edit the template as you would edit a skin, and it'll work. Final note: If you want the script to leave a blank line between iterations of the template, then you need to leave two empty lines at the end of the template.
I will eat and check on that. On thing I noticed is that I forgot to ad on the section [MeterDisk^1^_Name] a text option that should be like: Text=^1^:
and that would be like this:

Code: Select all

SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "Text" "\'%s:\'" "#@#FileToEdit.txt"',i,i))
in my lua script.

By the way, if you got the template by copy-pasting the first drive that was created with my lua, note that not everything was written, due to the fact that I did not escape many things, if you get the lastest rmskin I uploaded above you should see what I mean. I'll change the template to fit my needs and check how that goes. Huge thanks by the way to all of you! :17good
User avatar
raiguard
Posts: 633
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Lua for me.

raiguard » September 28th, 2018, 5:44 pm

kyriakos876 wrote:By the way, if you got the template by copy-pasting the first drive that was created with my lua, note that not everything was written, due to the fact that I did not escape many things, if you get the lastest rmskin I uploaded above you should see what I mean. I'll change the template to fit my needs and check how that goes. Huge thanks by the way to all of you! :17good
I actually figured this out myself before I even posted the first script, so I went through and escaped the variables to get the correct values (without escaping them, everything was completely broken). So I went through, fixed your LUA, generated the file, then copied disk C and used that as the template.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 5:54 pm

raiguard wrote:I actually figured this out myself before I even posted the first script, so I went through and escaped the variables to get the correct values (without escaping them, everything was completely broken). So I went through, fixed your LUA, generated the file, then copied disk C and used that as the template.
But in your remplate you have this:

Code: Select all


[MeterDisk^1^_Name]
Meter=String
MeterStyle=NormalLeft
X=#XFromTheWall#
Y=20r
DynamicVariables=1
UpdateDivider=-1
Which is missing stuff... unless you're talking about your newest upload... I haven't checked that yet. I will in sometime though! Looks really promising and the fact that it's waaaay easier to edit, makes me like it even more. That template thing is great! I'd never have thought of this myself with my experience on lua!
User avatar
raiguard
Posts: 633
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Lua for me.

raiguard » September 28th, 2018, 5:54 pm

kyriakos876 wrote:But in your remplate you have this:

Code: Select all


[MeterDisk^1^_Name]
Meter=String
MeterStyle=NormalLeft
X=#XFromTheWall#
Y=20r
DynamicVariables=1
UpdateDivider=-1
Which is missing stuff... unless you're talking about your newest upload... I haven't checked that yet. I will in sometime though! Looks really promising and the fact that it's waaaay easier to edit, makes me like it even more. That template thing is great! I'd never have thought of this myself with my experience on lua!
Yeah, I just noticed that you uploaded a new RMSKIN youself, I'll go through and update mine based on that. Gimme a few minutes.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
raiguard
Posts: 633
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Lua for me.

raiguard » September 28th, 2018, 6:01 pm

Can you tell me if this template is missing anything?

Edit: I didn't replace the DiskAnimationC commandmeasures with ^1^, so that is now fixed.

Code: Select all

[MeasureTotalDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
Total=1
UpdateDivider=100

[MeasureUsedDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
InvertMeasure=1
UpdateDivider=100

[DiskAnimation^1^]
Measure=Plugin
Plugin=ActionTimer
ActionList1=UpdateOnce | Wait 16 | Repeat IconAnimationIn, 16, 16
UpdateOnce=[!Update]
IconAnimationIn=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#+25,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure #CurrentSection#][!Redraw]
ActionList2=UpdateOnce | Wait 25 | Repeat IconAnimationOut, 16, 13
IconAnimationOut=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure #CurrentSection#][!Redraw]
ActionList3=UpdateOnce | Wait 25 | Repeat MouseUp, 16, 6
MouseUp=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,130,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure #CurrentSection#][!Redraw]
DynamicVariables=1

[MeterDisk^1^_Name]
Meter=String
MeterStyle=NormalLeft
X=#XFromTheWall#
Y=20r
Text='^1^:'
DynamicVariables=1
UpdateDivider=-1

[MeterDisk^1^_Value]
Meter=String
MeasureName=MeasureUsedDisk^1^
MeasureName2=MeasureTotalDisk^1^
MeterStyle=NormalRight
X=(#MaxWidth#-#XFromTheWall#)
Y=r
Text=%1B/%2B
NumOfDecimals=1
AutoScale=1
UpdateDivider=100

[Background_Disk_^1^]
Meter=Shape
X=0
Y=([MeterDisk^1^_Name:Y]-[MeterDisk^1^_Name:H]/2)
Shape=Rectangle 0,0,#MaxWidth#,([MeterDisk^1^_Name:H]*1.75) | Fill Color 0,0,0,0 | StrokeWidth 0
MouseOverAction=[!CommandMeasure DiskAnimation^1^ #quotes#Stop 2#quotes# ][!CommandMeasure DiskAnimation^1^ #quotes#Execute 1#quotes# ]
MouseLeaveAction=[!CommandMeasure DiskAnimation^1^ #quotes#Stop 1#quotes# ][!CommandMeasure DiskAnimation^1^ #quotes#Execute 2#quotes# ]
LeftMouseUpAction=[^1^:\]
DynamicVariables=1
UpdateDivider=-1

[Underliner_^1^]
Meter=Shape
X=(#MaxWidth#/2-#Underliner_Width_^1^#/2)
Y=-5R
Shape=Rectangle 0,0,#Underliner_Width_^1^#,1 | Fill Color #AccentColor# | StrokeWidth 0
DynamicVariables=1
UpdateDivider=-1
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 6:13 pm

raiguard wrote:Can you tell me if this template is missing anything?

Edit: I didn't replace the DiskAnimationC commandmeasures with ^1^, so that is now fixed.

Code: Select all

[MeasureTotalDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
Total=1
UpdateDivider=100

[MeasureUsedDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
InvertMeasure=1
UpdateDivider=100

[DiskAnimation^1^]
Measure=Plugin
Plugin=ActionTimer
ActionList1=UpdateOnce | Wait 16 | Repeat IconAnimationIn, 16, 16
UpdateOnce=[!Update]
IconAnimationIn=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#+25,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure #CurrentSection#][!Redraw]
ActionList2=UpdateOnce | Wait 25 | Repeat IconAnimationOut, 16, 13
IconAnimationOut=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure #CurrentSection#][!Redraw]
ActionList3=UpdateOnce | Wait 25 | Repeat MouseUp, 16, 6
MouseUp=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,130,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure #CurrentSection#][!Redraw]
DynamicVariables=1

[MeterDisk^1^_Name]
Meter=String
MeterStyle=NormalLeft
X=#XFromTheWall#
Y=20r
Text='^1^:'
DynamicVariables=1
UpdateDivider=-1

[MeterDisk^1^_Value]
Meter=String
MeasureName=MeasureUsedDisk^1^
MeasureName2=MeasureTotalDisk^1^
MeterStyle=NormalRight
X=(#MaxWidth#-#XFromTheWall#)
Y=r
Text=%1B/%2B
NumOfDecimals=1
AutoScale=1
UpdateDivider=100

[Background_Disk_^1^]
Meter=Shape
X=0
Y=([MeterDisk^1^_Name:Y]-[MeterDisk^1^_Name:H]/2)
Shape=Rectangle 0,0,#MaxWidth#,([MeterDisk^1^_Name:H]*1.75) | Fill Color 0,0,0,0 | StrokeWidth 0
MouseOverAction=[!CommandMeasure DiskAnimation^1^ #quotes#Stop 2#quotes# ][!CommandMeasure DiskAnimation^1^ #quotes#Execute 1#quotes# ]
MouseLeaveAction=[!CommandMeasure DiskAnimation^1^ #quotes#Stop 1#quotes# ][!CommandMeasure DiskAnimation^1^ #quotes#Execute 2#quotes# ]
LeftMouseUpAction=[^1^:\]
DynamicVariables=1
UpdateDivider=-1

[Underliner_^1^]
Meter=Shape
X=(#MaxWidth#/2-#Underliner_Width_^1^#/2)
Y=-5R
Shape=Rectangle 0,0,#Underliner_Width_^1^#,1 | Fill Color #AccentColor# | StrokeWidth 0
DynamicVariables=1
UpdateDivider=-1
First of all let me tell you that this is an unnecessary amount of help you're providing me with, and secondly, yes, that looks correct. So I guess in your template I cant just use double quotes in stead of all this craziness #quotes#Stop 1#quotes#
User avatar
raiguard
Posts: 633
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Lua for me.

raiguard » September 28th, 2018, 6:14 pm

Here is my new RMSKIN based on your most recent update:

EDIT: Eh, I'm not really doing much. I already had the script laying around and it wasn't very much work to adapt it for use with your skin. ;)

Anyway, yeah, with the template, you can just write it completely as a normal skin. You don't have to do anything special besides leaving two empty lines at the end if you want the iterations to have an empty line between them. That, and replacing all instances of the disk letter with ^1^.
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
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 6:30 pm

raiguard wrote:Here is my new RMSKIN based on your most recent update:

EDIT: Eh, I'm not really doing much. I already had the script laying around and it wasn't very much work to adapt it for use with your skin. ;)

Anyway, yeah, with the template, you can just write it completely as a normal skin. You don't have to do anything special besides leaving two empty lines at the end if you want the iterations to have an empty line between them. That, and replacing all instances of the disk letter with ^1^.
Yoooo that's some good stuff dude!
Also, I couldn't figure out how this:

Code: Select all

[MeasureComparison]
Measure=String
String=[MeasureRun]
IfMatch=^#AllDisks#$
IfNotMatchAction=[!WriteKeyValue Variables AllDisks "[MeasureRun]"][!DisableMeasure MeasureComparison][!CommandMeasure MeasureLua "Split('[MeasureRun]')"]
DynamicVariables=1
Disabled=1
should be written... The regular expression I tried was wrong in so many levels ... :17denial

Now I only need to figure how I want to mount my disks as well as figure out how to measure the storage of a usb drive... Because those show 0GB/0GB in the current code but I think I got it from here.
User avatar
raiguard
Posts: 633
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: Lua for me.

raiguard » September 28th, 2018, 6:33 pm

kyriakos876 wrote:Yoooo that's some good stuff dude!
Also, I couldn't figure out how this:

Code: Select all

[MeasureComparison]
Measure=String
String=[MeasureRun]
IfMatch=^#AllDisks#$
IfNotMatchAction=[!WriteKeyValue Variables AllDisks "[MeasureRun]"][!DisableMeasure MeasureComparison][!CommandMeasure MeasureLua "Split('[MeasureRun]')"]
DynamicVariables=1
Disabled=1
should be written... The regular expression I tried was wrong in so many levels ... :17denial

Now I only need to figure how I want to mount my disks as well as figure out how to measure the storage of a usb drive... Because those show 0GB/0GB but I think I got it from here.
Glad to help! To be honest, though, I wasn't completely doing this just to help you - I plan on implementing this method in my own Disks Meter. Right now I'm using the "brute-force" method I mentioned before, where I have measures and meters for every disk baked-in. That causes the INI to be almost 6000 lines long, which absolutely drains Rainmeter's performance every time it updates. This will allow me to make Disks Meter way more performance-friendly, especially for older computers/laptops.

Also, the only thing you need to do to measure removable drives is to add IgnoreRemovable=0 to the total and used disk space measures.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017